@@ -22,7 +22,7 @@ abstract class WebTestCase extends SymfonyWebTestCase
2222 /**
2323 * @var EntityManagerInterface|null
2424 */
25- protected $ em ;
25+ protected static $ em ;
2626
2727 /**
2828 * @var \Symfony\Component\BrowserKit\AbstractBrowser
@@ -34,6 +34,10 @@ abstract class WebTestCase extends SymfonyWebTestCase
3434 */
3535 private $ fixture ;
3636
37+ protected static $ authUser ;
38+
39+ protected static $ authPw ;
40+
3741 protected function setUp (): void
3842 {
3943 $ environment = $ _SERVER ['APP_ENV ' ] ?? 'test ' ;
@@ -45,7 +49,7 @@ protected function setUp(): void
4549 $ kernel ->boot ();
4650 static ::$ container = $ kernel ->getContainer ();
4751 if (static ::$ container ->has ('doctrine.orm.entity_manager ' )) {
48- $ this -> em = static ::$ container ->get ('doctrine.orm.entity_manager ' );
52+ self :: $ em = static ::$ container ->get ('doctrine.orm.entity_manager ' );
4953 }
5054 }
5155 if (!empty (static ::$ authUser ) && !empty (static ::$ authPw )) {
@@ -60,8 +64,8 @@ protected function setUp(): void
6064
6165 protected function tearDown (): void
6266 {
63- if (null !== $ this -> em ) {
64- $ this -> em ->getConnection ()->close ();
67+ if (null !== self :: $ em ) {
68+ self :: $ em ->getConnection ()->close ();
6569 }
6670 parent ::tearDown ();
6771 }
@@ -71,7 +75,7 @@ protected function tearDown(): void
7175 * See http://giorgiocefaro.com/blog/test-symfony-and-automatically-open-the-browser-with-the-response-content
7276 * You can define a "domain" parameter with the current domain of your app.
7377 */
74- protected function saveOutput (bool $ delete = true ): void
78+ protected static function saveOutput (bool $ delete = true ): void
7579 {
7680 $ browser = static ::$ container ->getParameter ('beelab_test.browser ' );
7781 $ rootDir = static ::$ container ->getParameter ('kernel.project_dir ' ).'/ ' ;
@@ -100,7 +104,7 @@ protected function saveOutput(bool $delete = true): void
100104 *
101105 * @throws \InvalidArgumentException
102106 */
103- protected function login (
string $ username =
'[email protected] ' , ?
string $ firewall =
null , ?
string $ service =
null ):
void 107+ protected static function login (
string $ username =
'[email protected] ' , ?
string $ firewall =
null , ?
string $ service =
null ):
void 104108 {
105109 $ service = $ service ?? static ::$ container ->getParameter ('beelab_test.user_service ' );
106110 if (null === $ user = static ::$ container ->get ($ service )->loadUserByUsername ($ username )) {
@@ -118,17 +122,17 @@ protected function login(string $username = '
[email protected] ', ?string $firew
118122 /**
119123 * Get an image file to be used in a form.
120124 */
121- protected function getImageFile (int $ file = 0 ): UploadedFile
125+ protected static function getImageFile (int $ file = 0 ): UploadedFile
122126 {
123127 $ data = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAADElEQVQI12P4//8/AAX+Av7czFnnAAAAAElFTkSuQmCC ' ;
124128
125- return $ this -> getFile ($ file , $ data , 'png ' , 'image/png ' );
129+ return self :: getFile ($ file , $ data , 'png ' , 'image/png ' );
126130 }
127131
128132 /**
129133 * Get a pdf file to be used in a form.
130134 */
131- protected function getPdfFile (int $ file = 0 ): UploadedFile
135+ protected static function getPdfFile (int $ file = 0 ): UploadedFile
132136 {
133137 $ data = <<<'EOF'
134138JVBERi0xLjEKJcKlwrHDqwoKMSAwIG9iagogIDw8IC9UeXBlIC9DYXRhbG9nCiAgICAgL1BhZ2VzIDIgMCBSCiAgPj4KZW5kb2JqCgoyIDAgb2JqCiAgP
@@ -142,30 +146,30 @@ protected function getPdfFile(int $file = 0): UploadedFile
142146ICAgIC9TaXplIDUKICA+PgpzdGFydHhyZWYKNTY1CiUlRU9GCg==
143147EOF;
144148
145- return $ this -> getFile ($ file , $ data , 'pdf ' , 'application/pdf ' );
149+ return self :: getFile ($ file , $ data , 'pdf ' , 'application/pdf ' );
146150 }
147151
148152 /**
149153 * Get a pdf file to be used in a form.
150154 */
151- protected function getZipFile (int $ file = 0 ): UploadedFile
155+ protected static function getZipFile (int $ file = 0 ): UploadedFile
152156 {
153157 $ data = <<<'EOF'
154158UEsDBAoAAgAAAM5RjEVOGigMAgAAAAIAAAAFABwAaC50eHRVVAkAA/OxilTzsYpUdXgLAAEE6AMAAARkAAAAaApQSwECHgMKAAIAAADOUYxF
155159ThooDAIAAAACAAAABQAYAAAAAAABAAAApIEAAAAAaC50eHRVVAUAA/OxilR1eAsAAQToAwAABGQAAABQSwUGAAAAAAEAAQBLAAAAQQAAAAAA
156160EOF;
157161
158- return $ this -> getFile ($ file , $ data , 'zip ' , 'application/zip ' );
162+ return self :: getFile ($ file , $ data , 'zip ' , 'application/zip ' );
159163 }
160164
161165 /**
162166 * Get a txt file to be used in a form.
163167 */
164- protected function getTxtFile (int $ file = 0 ): UploadedFile
168+ protected static function getTxtFile (int $ file = 0 ): UploadedFile
165169 {
166170 $ data = 'Lorem ipsum dolor sit amet ' ;
167171
168- return $ this -> getFile ($ file , $ data , 'txt ' , 'text/plain ' );
172+ return self :: getFile ($ file , $ data , 'txt ' , 'text/plain ' );
169173 }
170174
171175 /**
@@ -189,7 +193,7 @@ protected function loadFixtures(
189193 throw new \InvalidArgumentException (\sprintf ('The service "%s" is not an EntityManager ' , $ manager ));
190194 }
191195 } else {
192- $ manager = $ this -> em ;
196+ $ manager = self :: $ em ;
193197 }
194198 $ manager ->getConnection ()->exec ('SET foreign_key_checks = 0 ' );
195199 $ loader = new Loader (static ::$ container );
@@ -205,21 +209,21 @@ protected function loadFixtures(
205209 * Assert that $num mail has been sent
206210 * Need self::$client->enableProfiler() before calling.
207211 */
208- protected function assertMailSent (int $ num , string $ message = '' ): void
212+ protected static function assertMailSent (int $ num , string $ message = '' ): void
209213 {
210214 if (false !== $ profile = self ::$ client ->getProfile ()) {
211215 $ collector = $ profile ->getCollector ('swiftmailer ' );
212- $ this -> assertEquals ($ num , $ collector ->getMessageCount (), $ message );
216+ self :: assertEquals ($ num , $ collector ->getMessageCount (), $ message );
213217 } else {
214- $ this -> markTestSkipped ('Profiler not enabled. ' );
218+ self :: markTestSkipped ('Profiler not enabled. ' );
215219 }
216220 }
217221
218222 /**
219223 * Get a form field value, from its id
220224 * Useful for POSTs.
221225 */
222- protected function getFormValue (string $ fieldId , int $ position = 0 ): string
226+ protected static function getFormValue (string $ fieldId , int $ position = 0 ): string
223227 {
224228 return self ::$ client ->getCrawler ()->filter ('# ' .$ fieldId )->eq ($ position )->attr ('value ' );
225229 }
@@ -241,7 +245,7 @@ protected static function ajax(string $method, string $uri, array $params = [],
241245 * @param array $otherCommands Possible other commands to define
242246 * @param array $inputs Possible inputs to set inside command
243247 */
244- protected function commandTest (
248+ protected static function commandTest (
245249 string $ name ,
246250 Command $ command ,
247251 array $ arguments = [],
@@ -283,7 +287,7 @@ protected function getReference(string $name)
283287 /**
284288 * Get a file to be used in a form.
285289 */
286- protected function getFile (string $ file , string $ data , string $ ext , string $ mime ): UploadedFile
290+ protected static function getFile (string $ file , string $ data , string $ ext , string $ mime ): UploadedFile
287291 {
288292 $ name = 'file_ ' .$ file .'. ' .$ ext ;
289293 $ path = \tempnam (\sys_get_temp_dir (), 'sf_test_ ' ).$ name ;
@@ -297,13 +301,13 @@ protected function getFile(string $file, string $data, string $ext, string $mime
297301 *
298302 * @param string $name The name of form
299303 * @param array $values The values to submit
300- * @param array $values The values to submit for $_FILES
304+ * @param array $files The values to submit for $_FILES
301305 * @param string $method The method of form
302306 */
303- protected function postForm (string $ name , array $ values , array $ files = [], string $ method = 'POST ' ): void
307+ protected static function postForm (string $ name , array $ values , array $ files = [], string $ method = 'POST ' ): void
304308 {
305309 $ formAction = self ::$ client ->getRequest ()->getUri ();
306- $ values ['_token ' ] = $ this -> getFormValue ($ name .'__token ' );
310+ $ values ['_token ' ] = self :: getFormValue ($ name .'__token ' );
307311 $ filesValues = \count ($ files ) > 0 ? [$ name => $ files ] : [];
308312 self ::$ client ->request ($ method , $ formAction , [$ name => $ values ], $ filesValues );
309313 }
0 commit comments