public function testPublish() { $process = $this->createProcessMock(); $this->processSerializer->expects($this->once())->method('serialize')->with($this->identicalTo($process))->will($this->returnValue($serialized = 'serialized')); $this->processProducer->expects($this->once())->method('publish')->with($this->identicalTo($serialized)); $this->producer->publish($process); }
/** * @param mixed[] $headers * @param string $body */ public function handle(array $headers, $body) { if (!$this->firewall->authorize($headers, $body)) { throw new BadRequestHttpException('The request signature is not valid.'); } if (!is_array($payload = json_decode($body, true))) { throw new BadRequestHttpException('The request json body cannot be decoded.'); } $this->eventDispatcher->dispatch(WebhookEvents::HOOK, $event = new WebhookEvent($payload)); foreach ($event->getProcesses() as $process) { $this->processProducer->publish($process); } }
public function testHandle() { $this->firewall->expects($this->once())->method('authorize')->with($this->identicalTo($headers = ['X-Hub-Signature' => 'sha1=52b582138706ac0c597c315cfc1a1bf177408a4d']), $this->identicalTo($body = '{"foo":"bar"}'))->will($this->returnValue(true)); $process = $this->createProcessMock(); $this->eventDispatcher->expects($this->once())->method('dispatch')->with($this->identicalTo(WebhookEvents::HOOK), $this->callback(function ($event) use($body, $process) { if (!$event instanceof WebhookEvent || $event->getPayload() !== json_decode($body, true)) { return false; } $event->addProcess($process); return true; })); $this->processProducer->expects($this->once())->method('publish')->with($this->identicalTo($process)); $this->handler->handle($headers, $body); }