@@ -24,6 +24,14 @@ It comes with the following features:
24
24
* Provides a modified version of PHPUnit that does not embed ``symfony/yaml `` nor
25
25
``prophecy `` to prevent any conflicts with these dependencies.
26
26
27
+ * Provides polyfills for methods that are not available in older version of
28
+ PHPUnit
29
+
30
+ * Provide namespaced class name for older version of PHPUnit
31
+
32
+ * Makes compatible testSuite with both PHPUnit 8 and previous version by
33
+ removing typehint on `setUp ` and `tearDown ` methods.
34
+
27
35
Installation
28
36
------------
29
37
@@ -293,6 +301,76 @@ Running the following command will display the full stack trace:
293
301
294
302
$ SYMFONY_DEPRECATIONS_HELPER='/Doctrine\\Common\\ClassLoader is deprecated\./' ./vendor/bin/simple-phpunit
295
303
304
+ Testing with multiple version of PHPUnit
305
+ ----------------------------------------
306
+
307
+ Use Case
308
+ ~~~~~~~~
309
+
310
+ When testing a library that have to be compatible with serveral version of PHP
311
+ at the same time (like Symfony does), because of dependencies, the test suite
312
+ have to be tested by differentes version of PHPUnit. Unfortunatly, writing a
313
+ code compatible with a too wide range of version is not possible. ie:
314
+ - several function in PHPUnit 8 are deprecated but the replacements methods
315
+ didn't exists int PHPUnit 4.
316
+ - PHPUnit 8 added return typehint in method ``setUp(): void `` which is not
317
+ compatible with PHP 5.5.
318
+ - PHPUnit switch to namespaced class starting from PHPUnit 6. Tests have to
319
+ handle both case with/without namespaces.
320
+
321
+ Polyfill for the methods
322
+ ~~~~~~~~~~~~~~~~~~~~~~~~
323
+
324
+ When using the command ``simple-phpunit ``, PHPUnit Bridge injects pollyfills
325
+ for most of methods from the class ``TestCase `` and ``Assert `` in order to
326
+ write Test cases even compatible with PHPUnit 4. Some of those methods are
327
+ ``expectException ``, ``expectExcpetionMessage ``, ``expectExceptionCode ``,
328
+ ``createPartialMock ``, ``assertEqualsWithDelta ``, ``assertContainsEquals ``, ...
329
+
330
+ Remove void return typehint
331
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
332
+
333
+ When running the command ``simple-phpunit `` with the env variable
334
+ ``SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 `` the PHPUnit bridge will alterate
335
+ the code of PHPUnit to remove the return typehint (introduced in PHPUnit 8)
336
+ from methods ``setUp ``, ``tearDown ``, ``setUpBeforeClass `` and
337
+ ``tearDownAfterClass ``. Thuse allows you to write a Test compatible with both
338
+ PHP 5 and PHPUnit 8.
339
+
340
+ An alternative, is to use the trait :class: `Symfony\B ridge\P hpUnit\S etUpTearDownTrait `.
341
+ This trait will provide the right signature for the methods ``setUp ``, ``tearDown ``,
342
+ ``setUpBeforeClass `` and ``tearDownAfterClass `` and delegates the call to the methods
343
+ ``doSetUp ``, ``doTearDown ``, ``doSetUpBeforeClass `` and ``doTearDownAfterClass ``::
344
+
345
+ use PHPUnit\Framework\TestCase;
346
+ use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
347
+
348
+ class MyTest extends TestCase
349
+ {
350
+ use SetUpTearDownTrait;
351
+
352
+ private $state;
353
+
354
+ private function doSetup()
355
+ {
356
+ $this->state = 'demo';
357
+ }
358
+
359
+ protected function doSetup(): void
360
+ {
361
+ // Visibility and return typehint of method is free.
362
+ }
363
+ }
364
+
365
+
366
+ Use namespaced class
367
+ ~~~~~~~~~~~~~~~~~~~~
368
+
369
+ The PHPUnit bridge adds namespaced class aliases for most of PHPUnit class
370
+ declared in the old fashion way (ie. ``PHPUnit_Framework_Assert ``), allowing
371
+ you to always use the namespaced class declaration even when the test is
372
+ executed with PHPUnit 4.
373
+
296
374
Time-sensitive Tests
297
375
--------------------
298
376
0 commit comments