Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| HomepageContext | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
| iBrowseTheHomepage | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| theResponseCodeShouldBe | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| iShouldSeeTheDefaultWelcomeMessage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getDiContainer | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Tests\AppStarter\Acceptance; |
| 11 | |
| 12 | // @codeCoverageIgnoreStart |
| 13 | require __DIR__.'/../../BootstrapBehat.php'; |
| 14 | // @codeCoverageIgnoreEnd |
| 15 | |
| 16 | use AppStarter\Homepage\Application\Http\HomeController; |
| 17 | use Assert\Assert; |
| 18 | use Behat\Behat\Context\Context; |
| 19 | use Behat\Step\Then; |
| 20 | use Behat\Step\When; |
| 21 | use DI\Container; |
| 22 | use DI\ContainerBuilder; |
| 23 | use Nyholm\Psr7\Response; |
| 24 | use Nyholm\Psr7\ServerRequest as Request; |
| 25 | |
| 26 | final class HomepageContext implements Context |
| 27 | { |
| 28 | private Response $response; |
| 29 | |
| 30 | #[When('I browse the Home page')] |
| 31 | public function iBrowseTheHomepage(): void |
| 32 | { |
| 33 | $controller = $this->getDiContainer()->get(HomeController::class); |
| 34 | $request = new Request('GET', '/'); |
| 35 | $response = new Response(); |
| 36 | $this->response = $controller->index($request, $response); |
| 37 | } |
| 38 | |
| 39 | #[Then('the response code should be :statusCode')] |
| 40 | public function theResponseCodeShouldBe(int $statusCode): void |
| 41 | { |
| 42 | Assert::that($this->response->getStatusCode())->same($statusCode); |
| 43 | } |
| 44 | |
| 45 | #[Then('I should see the default welcome message')] |
| 46 | public function iShouldSeeTheDefaultWelcomeMessage(): void |
| 47 | { |
| 48 | Assert::that((string) $this->response->getBody())->contains('Welcome to the starter site'); |
| 49 | } |
| 50 | |
| 51 | private function getDiContainer(): Container |
| 52 | { |
| 53 | // DI Container Builder |
| 54 | $containerBuilder = new ContainerBuilder(); |
| 55 | $containerBuilder->useAutowiring(true); |
| 56 | // Add DI container definitions |
| 57 | $containerBuilder->addDefinitions(ROOT_DIR.'/config/starter/container.php'); |
| 58 | $containerBuilder->addDefinitions(ROOT_DIR.'/config/starter/container_test.php'); |
| 59 | |
| 60 | // Build the container |
| 61 | return $containerBuilder->build(); |
| 62 | } |
| 63 | } |