enableProfiler(); $hookBody = $this->getTestBookRequestBody(); $headers = $this->getHeaders(); $endpoint = '/admin/listen'; $testLibrary = new Library(__DIR__ . '/../Files/books'); $client->getContainer()->set('library', $testLibrary); $client->request('POST', $endpoint, [], [], $headers, $hookBody); $statusCode = $client->getResponse()->getStatusCode(); $this->assertEquals(Response::HTTP_OK, $statusCode); /** @var MessageDataCollector $mailCollector */ $mailCollector = $client->getProfile()->getCollector('swiftmailer'); /** @var \Swift_Message[] $mails */ $mails = $mailCollector->getMessages(); $this->assertCount(1, $mails); $hookData = json_decode($hookBody, true); $sampleCommitHash = current($hookData['commits'])['id']; $sentMessage = array_shift($mails); $this->assertContains('Publishing Successful', $sentMessage->getBody()); $this->assertContains($sampleCommitHash, $sentMessage->getBody()); } /** * @return string */ private function getTestBookRequestBody(): string { return file_get_contents(__DIR__ . '/../Files/webhook-gitlab-push-test-book.json'); } /** * @return array */ private function getHeaders(): array { $headers = [ 'HTTP_X-GitLab-Event' => 'Push Hook', // prefix required for non-standard 'Content-Type' => 'application/json' ]; return $headers; } }