-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #584 from k20human/bugfix/583
Fix new static method getContainer in KernelTestCase collision
- Loading branch information
Showing
4 changed files
with
32 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ class_alias(KernelBrowser::class, Client::class); | |
* @author Lea Haensenberger | ||
* @author Lukas Kahwe Smith <[email protected]> | ||
* @author Benjamin Eberlei <[email protected]> | ||
* | ||
* @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); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters