@@ -32,29 +32,23 @@ final public static function _resetBrowserClients(): void
32
32
33
33
protected function pantherBrowser (array $ options = [], array $ kernelOptions = [], array $ managerOptions = []): PantherBrowser
34
34
{
35
- $ browser = PantherBrowser::create (function () use ($ options , $ kernelOptions , $ managerOptions ) {
36
- if (!$ this instanceof PantherTestCase) {
37
- throw new \RuntimeException (\sprintf ('The "%s" method can only be used on TestCases that extend "%s". ' , __METHOD__ , PantherTestCase::class));
38
- }
39
-
40
- $ class = $ _SERVER ['PANTHER_BROWSER_CLASS ' ] ?? PantherBrowser::class;
41
-
42
- if (!\is_a ($ class , PantherBrowser::class, true )) {
43
- throw new \RuntimeException (\sprintf ('"PANTHER_BROWSER_CLASS" env variable must reference a class that extends %s. ' , PantherBrowser::class));
44
- }
35
+ $ class = $ _SERVER ['PANTHER_BROWSER_CLASS ' ] ?? PantherBrowser::class;
45
36
46
- if (self :: $ primaryPantherClient ) {
47
- return new $ class( static :: createAdditionalPantherClient ( ));
48
- }
37
+ if (! \is_a ( $ class , PantherBrowser::class, true ) ) {
38
+ throw new \ RuntimeException ( \sprintf ( ' "PANTHER_BROWSER_CLASS" env variable must reference a class that extends %s. ' , PantherBrowser::class ));
39
+ }
49
40
41
+ if (self ::$ primaryPantherClient ) {
42
+ $ browser = new $ class (static ::createAdditionalPantherClient ());
43
+ } else {
50
44
self ::$ primaryPantherClient = static ::createPantherClient (
51
45
\array_merge (['browser ' => $ _SERVER ['PANTHER_BROWSER ' ] ?? static ::CHROME ], $ options ),
52
46
$ kernelOptions ,
53
47
$ managerOptions
54
48
);
55
49
56
- return new $ class (self ::$ primaryPantherClient );
57
- });
50
+ $ browser = new $ class (self ::$ primaryPantherClient );
51
+ }
58
52
59
53
BrowserExtension::registerBrowser ($ browser );
60
54
@@ -67,57 +61,50 @@ protected function pantherBrowser(array $options = [], array $kernelOptions = []
67
61
68
62
protected function httpBrowser (array $ kernelOptions = [], array $ pantherOptions = []): HttpBrowser
69
63
{
70
- $ browser = HttpBrowser::create (function () use ($ kernelOptions , $ pantherOptions ) {
71
- $ class = $ _SERVER ['HTTP_BROWSER_CLASS ' ] ?? HttpBrowser::class;
64
+ $ class = $ _SERVER ['HTTP_BROWSER_CLASS ' ] ?? HttpBrowser::class;
72
65
73
- if (!\is_a ($ class , HttpBrowser::class, true )) {
74
- throw new \RuntimeException (\sprintf ('"HTTP_BROWSER_CLASS" env variable must reference a class that extends %s. ' , HttpBrowser::class));
75
- }
76
-
77
- $ baseUri = $ _SERVER ['HTTP_BROWSER_URI ' ] ?? null ;
66
+ if (!\is_a ($ class , HttpBrowser::class, true )) {
67
+ throw new \RuntimeException (\sprintf ('"HTTP_BROWSER_CLASS" env variable must reference a class that extends %s. ' , HttpBrowser::class));
68
+ }
78
69
79
- if (!$ baseUri && !$ this instanceof PantherTestCase) {
80
- throw new \RuntimeException (\sprintf ('If not using "HTTP_BROWSER_URI", your TestCase must extend "%s". ' , PantherTestCase::class));
81
- }
70
+ $ baseUri = $ _SERVER ['HTTP_BROWSER_URI ' ] ?? null ;
82
71
83
- if (!$ baseUri ) {
84
- self ::startWebServer ($ pantherOptions );
72
+ if (!$ baseUri && !$ this instanceof PantherTestCase) {
73
+ throw new \RuntimeException (\sprintf ('If not using "HTTP_BROWSER_URI", your TestCase must extend "%s". ' , PantherTestCase::class));
74
+ }
85
75
86
- $ baseUri = self :: $ baseUri ;
87
- }
76
+ if (! $ baseUri) {
77
+ self :: startWebServer ( $ pantherOptions );
88
78
89
- // copied from PantherTestCaseTrait::createHttpBrowserClient()
90
- $ client = new HttpBrowserClient ();
91
- $ urlComponents = \parse_url ($ baseUri );
92
- $ host = $ urlComponents ['host ' ];
79
+ $ baseUri = self ::$ baseUri ;
80
+ }
93
81
94
- if (isset ($ urlComponents ['port ' ])) {
95
- $ host .= ": {$ urlComponents ['port ' ]}" ;
96
- }
82
+ // copied from PantherTestCaseTrait::createHttpBrowserClient()
83
+ $ client = new HttpBrowserClient ();
84
+ $ urlComponents = \parse_url ($ baseUri );
85
+ $ host = $ urlComponents ['host ' ];
97
86
98
- $ client ->setServerParameter ('HTTP_HOST ' , $ host );
87
+ if (isset ($ urlComponents ['port ' ])) {
88
+ $ host .= ": {$ urlComponents ['port ' ]}" ;
89
+ }
99
90
100
- if ('https ' === ($ urlComponents ['scheme ' ] ?? 'http ' )) {
101
- $ client ->setServerParameter ('HTTPS ' , 'true ' );
102
- }
91
+ $ client ->setServerParameter ('HTTP_HOST ' , $ host );
103
92
104
- /** @var HttpBrowser $browser */
105
- $ browser = new $ class (self ::$ httpBrowserClients [] = $ client );
93
+ if ('https ' === ($ urlComponents ['scheme ' ] ?? 'http ' )) {
94
+ $ client ->setServerParameter ('HTTPS ' , 'true ' );
95
+ }
106
96
107
- if (!$ this instanceof KernelTestCase) {
108
- return $ browser ;
109
- }
97
+ $ browser = new $ class (self ::$ httpBrowserClients [] = $ client );
110
98
99
+ if ($ this instanceof KernelTestCase) {
111
100
if (!static ::$ booted ) {
112
101
static ::bootKernel ($ kernelOptions );
113
102
}
114
103
115
104
if (static ::$ container ->has ('profiler ' )) {
116
105
$ browser ->setProfiler (static ::$ container ->get ('profiler ' ));
117
106
}
118
-
119
- return $ browser ;
120
- });
107
+ }
121
108
122
109
BrowserExtension::registerBrowser ($ browser );
123
110
@@ -132,28 +119,26 @@ protected function kernelBrowser(array $options = []): KernelBrowser
132
119
throw new \RuntimeException (\sprintf ('The "%s" method can only be used on TestCases that extend "%s". ' , __METHOD__ , KernelTestCase::class));
133
120
}
134
121
135
- $ browser = KernelBrowser::create (function () use ($ options ) {
136
- $ class = $ _SERVER ['KERNEL_BROWSER_CLASS ' ] ?? KernelBrowser::class;
137
-
138
- if (!\is_a ($ class , KernelBrowser::class, true )) {
139
- throw new \RuntimeException (\sprintf ('"KERNEL_BROWSER_CLASS" env variable must reference a class that extends %s. ' , KernelBrowser::class));
140
- }
122
+ $ class = $ _SERVER ['KERNEL_BROWSER_CLASS ' ] ?? KernelBrowser::class;
141
123
142
- if ($ this instanceof WebTestCase) {
143
- static ::ensureKernelShutdown ();
124
+ if (!\is_a ($ class , KernelBrowser::class, true )) {
125
+ throw new \RuntimeException (\sprintf ('"KERNEL_BROWSER_CLASS" env variable must reference a class that extends %s. ' , KernelBrowser::class));
126
+ }
144
127
145
- return new $ class ( static :: createClient ( $ options ));
146
- }
128
+ if ( $ this instanceof WebTestCase) {
129
+ static :: ensureKernelShutdown ();
147
130
131
+ $ browser = new $ class (static ::createClient ($ options ));
132
+ } else {
148
133
// reboot kernel before starting browser
149
134
static ::bootKernel ($ options );
150
135
151
136
if (!static ::$ container ->has ('test.client ' )) {
152
137
throw new \RuntimeException ('The Symfony test client is not enabled. ' );
153
138
}
154
139
155
- return new $ class (static ::$ container ->get ('test.client ' ));
156
- });
140
+ $ browser = new $ class (static ::$ container ->get ('test.client ' ));
141
+ }
157
142
158
143
BrowserExtension::registerBrowser ($ browser );
159
144
0 commit comments