@@ -56,6 +56,16 @@ trait PantherTestCaseTrait
56
56
*/
57
57
protected static $ pantherClient ;
58
58
59
+ /**
60
+ * @var array
61
+ */
62
+ protected static $ defaultOptions = [
63
+ 'webServerDir ' => __DIR__ .'/../../../../public ' , // the Flex directory structure
64
+ 'hostname ' => '127.0.0.1 ' ,
65
+ 'port ' => 9000 ,
66
+ 'router ' => '' ,
67
+ ];
68
+
59
69
public static function tearDownAfterClass ()
60
70
{
61
71
if (self ::$ stopServerOnTeardown ) {
@@ -82,28 +92,35 @@ public static function stopWebServer()
82
92
self ::$ baseUri = null ;
83
93
}
84
94
85
- public static function startWebServer (?string $ webServerDir = null , string $ hostname = '127.0.0.1 ' , int $ port = 9000 ): void
95
+ /**
96
+ * @param array $options see {@see $defaultOptions}
97
+ */
98
+ public static function startWebServer (array $ options = []): void
86
99
{
87
100
if (null !== static ::$ webServerManager ) {
88
101
return ;
89
102
}
90
103
91
- if (null === $ webServerDir ) {
92
- // Try the local $webServerDir property, or the PANTHER_WEB_SERVER_DIR env var or default to the Flex directory structure
93
- $ webServerDir = static ::$ webServerDir ?? $ _SERVER ['PANTHER_WEB_SERVER_DIR ' ] ?? __DIR__ .'/../../../../public ' ;
94
- }
104
+ $ options = [
105
+ 'webServerDir ' => $ options ['webServerDir ' ] ?? static ::$ webServerDir ?? $ _SERVER ['PANTHER_WEB_SERVER_DIR ' ] ?? self ::$ defaultOptions ['webServerDir ' ],
106
+ 'hostname ' => $ options ['webServerDir ' ] ?? self ::$ defaultOptions ['hostname ' ],
107
+ 'port ' => (int ) ($ options ['port ' ] ?? $ _SERVER ['PANTHER_WEB_SERVER_PORT ' ] ?? self ::$ defaultOptions ['port ' ]),
108
+ 'router ' => $ options ['router ' ] ?? $ _SERVER ['PANTHER_WEB_SERVER_ROUTER ' ] ?? self ::$ defaultOptions ['router ' ],
109
+ ];
95
110
96
- self ::$ webServerManager = new WebServerManager ($ webServerDir , $ hostname , $ port );
111
+ self ::$ webServerManager = new WebServerManager (... array_values ( $ options ) );
97
112
self ::$ webServerManager ->start ();
98
113
99
- self ::$ baseUri = " http:// $ hostname: $ port" ;
114
+ self ::$ baseUri = sprintf ( ' http://%s:%s ' , $ options [ ' hostname ' ], $ options [ ' port ' ]) ;
100
115
}
101
116
102
- protected static function createPantherClient (string $ hostname = '127.0.0.1 ' , ?int $ port = null , array $ kernelOptions = []): PantherClient
117
+ /**
118
+ * @param array $options see {@see $defaultOptions}
119
+ * @param array $kernelOptions
120
+ */
121
+ protected static function createPantherClient (array $ options = [], array $ kernelOptions = []): PantherClient
103
122
{
104
- $ port = (int ) ($ port ?? $ _SERVER ['PANTHER_WEB_SERVER_PORT ' ] ?? 9000 );
105
-
106
- self ::startWebServer (null , $ hostname , $ port );
123
+ self ::startWebServer ($ options );
107
124
if (null === self ::$ pantherClient ) {
108
125
self ::$ pantherClient = Client::createChromeClient (null , null , [], self ::$ baseUri );
109
126
}
@@ -115,15 +132,17 @@ protected static function createPantherClient(string $hostname = '127.0.0.1', ?i
115
132
return self ::$ pantherClient ;
116
133
}
117
134
118
- protected static function createGoutteClient (string $ hostname = '127.0.0.1 ' , ?int $ port = null , array $ kernelOptions = []): GoutteClient
135
+ /**
136
+ * @param array $options see {@see $defaultOptions}
137
+ * @param array $kernelOptions
138
+ */
139
+ protected static function createGoutteClient (array $ options = [], array $ kernelOptions = []): GoutteClient
119
140
{
120
141
if (!\class_exists (GoutteClient::class)) {
121
142
throw new \RuntimeException ('Goutte is not installed. Run "composer req fabpot/goutte". ' );
122
143
}
123
144
124
- $ port = (int ) ($ port ?? $ _SERVER ['PANTHER_WEB_SERVER_PORT ' ] ?? 9000 );
125
-
126
- self ::startWebServer (null , $ hostname , $ port );
145
+ self ::startWebServer ($ options );
127
146
if (null === self ::$ goutteClient ) {
128
147
$ goutteClient = new GoutteClient ();
129
148
$ goutteClient ->setClient (new GuzzleClient (['base_uri ' => self ::$ baseUri ]));
0 commit comments