@@ -28,6 +28,14 @@ It comes with the following features:
28
28
constraints to apply; 2. running tests in parallel when a test suite is split
29
29
in several phpunit.xml files; 3. recording and replaying skipped tests;
30
30
31
+ * Provides polyfills for methods that are not available in older version of
32
+ PHPUnit
33
+
34
+ * Provide namespaced class name for older version of PHPUnit
35
+
36
+ * Makes compatible testSuite with both PHPUnit 8 and previous version by
37
+ removing typehint on `setUp ` and `tearDown ` methods.
38
+
31
39
Installation
32
40
------------
33
41
@@ -371,6 +379,76 @@ Running the following command will display the full stack trace:
371
379
372
380
$ SYMFONY_DEPRECATIONS_HELPER='/Doctrine\\Common\\ClassLoader is deprecated\./' ./vendor/bin/simple-phpunit
373
381
382
+ Testing with multiple version of PHPUnit
383
+ ----------------------------------------
384
+
385
+ Use Case
386
+ ~~~~~~~~
387
+
388
+ When testing a library that have to be compatible with serveral version of PHP
389
+ at the same time (like Symfony does), because of dependencies, the test suite
390
+ have to be tested by differentes version of PHPUnit. Unfortunatly, writing a
391
+ code compatible with a too wide range of version is not possible. ie:
392
+ - several function in PHPUnit 8 are deprecated but the replacements methods
393
+ didn't exists int PHPUnit 4.
394
+ - PHPUnit 8 added return typehint in method ``setUp(): void `` which is not
395
+ compatible with PHP 5.5.
396
+ - PHPUnit switch to namespaced class starting from PHPUnit 6. Tests have to
397
+ handle both case with/without namespaces.
398
+
399
+ Polyfill for the methods
400
+ ~~~~~~~~~~~~~~~~~~~~~~~~
401
+
402
+ When using the command ``simple-phpunit ``, PHPUnit Bridge injects pollyfills
403
+ for most of methods from the class ``TestCase `` and ``Assert `` in order to
404
+ write Test cases even compatible with PHPUnit 4. Some of those methods are
405
+ ``expectException ``, ``expectExcpetionMessage ``, ``expectExceptionCode ``,
406
+ ``createPartialMock ``, ``assertEqualsWithDelta ``, ``assertContainsEquals ``, ...
407
+
408
+ Remove void return typehint
409
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
410
+
411
+ When running the command ``simple-phpunit `` with the env variable
412
+ ``SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 `` the PHPUnit bridge will alterate
413
+ the code of PHPUnit to remove the return typehint (introduced in PHPUnit 8)
414
+ from methods ``setUp ``, ``tearDown ``, ``setUpBeforeClass `` and
415
+ ``tearDownAfterClass ``. Thuse allows you to write a Test compatible with both
416
+ PHP 5 and PHPUnit 8.
417
+
418
+ An alternative, is to use the trait :class: `Symfony\B ridge\P hpUnit\S etUpTearDownTrait `.
419
+ This trait will provide the right signature for the methods ``setUp ``, ``tearDown ``,
420
+ ``setUpBeforeClass `` and ``tearDownAfterClass `` and delegates the call to the methods
421
+ ``doSetUp ``, ``doTearDown ``, ``doSetUpBeforeClass `` and ``doTearDownAfterClass ``::
422
+
423
+ use PHPUnit\Framework\TestCase;
424
+ use Symfony\Bridge\PhpUnit\SetUpTearDownTrait;
425
+
426
+ class MyTest extends TestCase
427
+ {
428
+ use SetUpTearDownTrait;
429
+
430
+ private $state;
431
+
432
+ private function doSetup()
433
+ {
434
+ $this->state = 'demo';
435
+ }
436
+
437
+ protected function doSetup(): void
438
+ {
439
+ // Visibility and return typehint of method is free.
440
+ }
441
+ }
442
+
443
+
444
+ Use namespaced class
445
+ ~~~~~~~~~~~~~~~~~~~~
446
+
447
+ The PHPUnit bridge adds namespaced class aliases for most of PHPUnit class
448
+ declared in the old fashion way (ie. ``PHPUnit_Framework_Assert ``), allowing
449
+ you to always use the namespaced class declaration even when the test is
450
+ executed with PHPUnit 4.
451
+
374
452
Time-sensitive Tests
375
453
--------------------
376
454
0 commit comments