diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 95d53790..7d3158df 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: matrix: php-version: ['7.2', '7.3', '7.4', '8.0'] composer-flags: [''] - symfony-version: ['5.1'] + symfony-version: ['^5.3'] include: - php-version: 7.2 symfony-version: "^4.4" diff --git a/src/Test/WebTestCase.php b/src/Test/WebTestCase.php index c7912e06..3b637299 100644 --- a/src/Test/WebTestCase.php +++ b/src/Test/WebTestCase.php @@ -38,6 +38,8 @@ class_alias(KernelBrowser::class, Client::class); * @author Lea Haensenberger * @author Lukas Kahwe Smith * @author Benjamin Eberlei + * + * @method ContainerInterface getContainer() */ abstract class WebTestCase extends BaseWebTestCase { @@ -68,7 +70,7 @@ abstract class WebTestCase extends BaseWebTestCase */ protected function getServiceMockBuilder(string $id): MockBuilder { - $service = $this->getContainer()->get($id); + $service = $this->getDependencyInjectionContainer()->get($id); $class = get_class($service); return $this->getMockBuilder($class)->disableOriginalConstructor(); @@ -87,7 +89,7 @@ protected function runCommand(string $name, array $params = [], bool $reuseKerne $kernel = static::$kernel = static::createKernel(['environment' => $this->environment]); $kernel->boot(); } else { - $kernel = $this->getContainer()->get('kernel'); + $kernel = $this->getDependencyInjectionContainer()->get('kernel'); } $application = new Application($kernel); @@ -127,7 +129,7 @@ protected function getVerbosityLevel(): int // If `null`, is not yet set if (null === $this->verbosityLevel) { // Set the global verbosity level that is set as NORMAL by the TreeBuilder in Configuration - $level = strtoupper($this->getContainer()->getParameter('liip_functional_test.command_verbosity')); + $level = strtoupper($this->getDependencyInjectionContainer()->getParameter('liip_functional_test.command_verbosity')); $verbosity = '\Symfony\Component\Console\Output\StreamOutput::VERBOSITY_'.$level; $this->verbosityLevel = constant($verbosity); @@ -182,7 +184,7 @@ protected function getDecorated(): bool { if (null === $this->decorated) { // Set the global decoration flag that is set to `true` by the TreeBuilder in Configuration - $this->decorated = $this->getContainer()->getParameter('liip_functional_test.command_decoration'); + $this->decorated = $this->getDependencyInjectionContainer()->getParameter('liip_functional_test.command_decoration'); } // Check the local decorated flag @@ -202,14 +204,13 @@ public function isDecorated(bool $decorated): void * Get an instance of the dependency injection container. * (this creates a kernel *without* parameters). */ - protected function getContainer(): ContainerInterface + protected function getDependencyInjectionContainer(): ContainerInterface { $cacheKey = $this->environment; if (empty($this->containers[$cacheKey])) { - $options = [ + $kernel = static::createKernel([ 'environment' => $this->environment, - ]; - $kernel = $this->createKernel($options); + ]); $kernel->boot(); $container = $kernel->getContainer(); @@ -223,6 +224,22 @@ protected function getContainer(): ContainerInterface return $this->containers[$cacheKey]; } + /** + * Keep support of Symfony < 5.3. + */ + public function __call(string $name, $arguments) + { + if ('getContainer' === $name) { + if (method_exists($this, $name)) { + return self::getContainer(); + } + + return $this->getDependencyInjectionContainer(); + } + + throw new \Exception("Method {$name} is not supported."); + } + /** * Creates an instance of a lightweight Http client. * @@ -244,9 +261,9 @@ protected function makeClient(array $params = []): Client */ protected function makeAuthenticatedClient(array $params = []): Client { - $username = $this->getContainer() + $username = $this->getDependencyInjectionContainer() ->getParameter('liip_functional_test.authentication.username'); - $password = $this->getContainer() + $password = $this->getDependencyInjectionContainer() ->getParameter('liip_functional_test.authentication.password'); return $this->createClientWithParams($params, $username, $password); @@ -296,7 +313,7 @@ protected function createUserToken(UserInterface $user, string $firewallName): T */ protected function getUrl(string $route, array $params = [], int $absolute = UrlGeneratorInterface::ABSOLUTE_PATH): string { - return $this->getContainer()->get('router')->generate($route, $params, $absolute); + return $this->getDependencyInjectionContainer()->get('router')->generate($route, $params, $absolute); } /** diff --git a/tests/Test/WebTestCaseTest.php b/tests/Test/WebTestCaseTest.php index 8edb0113..84157c76 100644 --- a/tests/Test/WebTestCaseTest.php +++ b/tests/Test/WebTestCaseTest.php @@ -154,7 +154,7 @@ public function testAssertStatusCodeException(): void try { $this->assertStatusCode(-1, $client); } catch (AssertionFailedError $e) { - $this->assertStringContainsString('No route found for "GET /9999"', $e->getMessage()); + $this->assertStringContainsString('No route found', $e->getMessage()); $this->assertStringContainsString('Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(', $e->getMessage()); $this->assertStringContainsString('Failed asserting that 404 matches expected -1.', $e->getMessage()); diff --git a/tests/Traits/LiipAcmeFixturesTrait.php b/tests/Traits/LiipAcmeFixturesTrait.php index 01a0ecea..32722fab 100644 --- a/tests/Traits/LiipAcmeFixturesTrait.php +++ b/tests/Traits/LiipAcmeFixturesTrait.php @@ -22,7 +22,7 @@ trait LiipAcmeFixturesTrait public function schemaUpdate(): void { // Create database - $kernel = $this->getContainer()->get('kernel'); + $kernel = $this->getDependencyInjectionContainer()->get('kernel'); $application = new Application($kernel); @@ -46,7 +46,7 @@ public function loadTestFixtures(): User $user1->setEnabled(true); $user1->setConfirmationToken(null); - $manager = $this->getContainer()->get('doctrine')->getManager(); + $manager = $this->getDependencyInjectionContainer()->get('doctrine')->getManager(); $manager->persist($user1); $user2 = clone $user1;