1616use Liip \FunctionalTestBundle \Utils \HttpAssertions ;
1717use PHPUnit \Framework \MockObject \MockBuilder ;
1818use Symfony \Bundle \FrameworkBundle \Client ;
19- use Symfony \Bundle \FrameworkBundle \Console \Application ;
2019use Symfony \Bundle \FrameworkBundle \KernelBrowser ;
21- use Symfony \Bundle \FrameworkBundle \Test \WebTestCase as BaseWebTestCase ;
2220use Symfony \Component \BrowserKit \Cookie ;
23- use Symfony \Component \Console \Tester \CommandTester ;
2421use Symfony \Component \DependencyInjection \ContainerInterface ;
2522use Symfony \Component \DependencyInjection \ResettableContainerInterface ;
2623use Symfony \Component \DomCrawler \Crawler ;
4037 class_alias (KernelBrowser::class, Client::class);
4138}
4239
40+ if (!method_exists (\Symfony \Bundle \FrameworkBundle \Test \WebTestCase::class, 'runCommand ' )) {
41+ if (!class_exists (BaseWebTestCase::class, false )) {
42+ class_alias (LegacyWebTestCase::class, BaseWebTestCase::class);
43+ }
44+ } else {
45+ if (!class_exists (BaseWebTestCase::class, false )) {
46+ class_alias (ModernWebTestCase::class, BaseWebTestCase::class);
47+ }
48+ }
49+
4350/**
4451 * @author Lea Haensenberger
4552 * @author Lukas Kahwe Smith <smith@pooteeweet.org>
@@ -51,6 +58,8 @@ class_alias(KernelBrowser::class, Client::class);
5158 */
5259abstract class WebTestCase extends BaseWebTestCase
5360{
61+ public static ?self $ activeInstance = null ;
62+
5463 protected static $ env = 'test ' ;
5564
5665 protected $ containers ;
@@ -66,7 +75,7 @@ abstract class WebTestCase extends BaseWebTestCase
6675 /**
6776 * @var array|null
6877 */
69- private $ inputs ;
78+ protected $ inputs ;
7079
7180 /**
7281 * @var array
@@ -103,47 +112,6 @@ protected function setServiceMock(
103112 }
104113 }
105114
106- /**
107- * Builds up the environment to run the given command.
108- */
109- protected function runCommand (string $ name , array $ params = [], bool $ reuseKernel = false ): CommandTester
110- {
111- if (!$ reuseKernel ) {
112- if (null !== static ::$ kernel ) {
113- static ::ensureKernelShutdown ();
114- }
115-
116- $ kernel = static ::bootKernel (['environment ' => static ::$ env ]);
117- $ kernel ->boot ();
118- } else {
119- $ kernel = $ this ->getContainer ()->get ('kernel ' );
120- }
121-
122- $ application = new Application ($ kernel );
123-
124- $ options = [
125- 'interactive ' => false ,
126- 'decorated ' => $ this ->getDecorated (),
127- 'verbosity ' => $ this ->getVerbosityLevel (),
128- ];
129-
130- $ command = $ application ->find ($ name );
131- $ commandTester = new CommandTester ($ command );
132-
133- if (null !== $ inputs = $ this ->getInputs ()) {
134- $ commandTester ->setInputs ($ inputs );
135- $ options ['interactive ' ] = true ;
136- $ this ->inputs = null ;
137- }
138-
139- $ commandTester ->execute (
140- array_merge (['command ' => $ command ->getName ()], $ params ),
141- $ options
142- );
143-
144- return $ commandTester ;
145- }
146-
147115 /**
148116 * Retrieves the output verbosity level.
149117 *
@@ -535,8 +503,17 @@ public static function assertValidationErrors(array $expected, ContainerInterfac
535503 HttpAssertions::assertValidationErrors ($ expected , $ container );
536504 }
537505
506+ protected function setUp (): void
507+ {
508+ parent ::setUp ();
509+
510+ self ::$ activeInstance = $ this ;
511+ }
512+
538513 protected function tearDown (): void
539514 {
515+ self ::$ activeInstance = null ;
516+
540517 if (null !== $ this ->containers ) {
541518 foreach ($ this ->containers as $ container ) {
542519 if ($ container instanceof ResettableContainerInterface) {
0 commit comments