Browse Source

DX: update PHPUnit usage to use external Prophecy trait and solve warning

Dariusz Ruminski 4 years ago
parent
commit
fab1e5560b
3 changed files with 26 additions and 1 deletions
  1. 1 0
      .composer-require-checker.json
  2. 1 0
      composer.json
  3. 24 1
      tests/TestCase.php

+ 1 - 0
.composer-require-checker.json

@@ -14,6 +14,7 @@
         "PHPUnitGoodPractices\\Traits\\ProphecyOverMockObjectTrait",
         "PHPUnitGoodPractices\\Traits\\ProphesizeOnlyInterfaceTrait",
         "Prophecy\\Argument",
+        "Prophecy\\PhpUnit\\ProphecyTrait",
         "Symfony\\Component\\EventDispatcher\\Event",
         "Symfony\\Contracts\\EventDispatcher\\Event",
         "Symfony\\Contracts\\EventDispatcher\\EventDispatcherInterface",

+ 1 - 0
composer.json

@@ -40,6 +40,7 @@
         "php-cs-fixer/accessible-object": "^1.0",
         "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2",
         "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1",
+        "phpspec/prophecy-phpunit": "^1.1 || ^2.0",
         "phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.13 || ^9.4.4 <9.5",
         "phpunitgoodpractices/polyfill": "^1.5",
         "phpunitgoodpractices/traits": "^1.9.1",

+ 24 - 1
tests/TestCase.php

@@ -19,14 +19,37 @@ use PHPUnitGoodPractices\Traits\ExpectOverSetExceptionTrait;
 use PHPUnitGoodPractices\Traits\IdentityOverEqualityTrait;
 use PHPUnitGoodPractices\Traits\ProphecyOverMockObjectTrait;
 use PHPUnitGoodPractices\Traits\ProphesizeOnlyInterfaceTrait;
+use Prophecy\PhpUnit\ProphecyTrait;
 
+// we check single, example DEV dependency - if it's there, we have the dev dependencies, if not, we are using PHP-CS-Fixer as library and trying to use internal TestCase...
 if (trait_exists(ProphesizeOnlyInterfaceTrait::class)) {
+    if (trait_exists(ProphecyTrait::class)) {
+        /**
+         * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
+         *
+         * @internal
+         */
+        abstract class InterimTestCase extends BaseTestCase
+        {
+            use ProphecyTrait;
+        }
+    } else {
+        /**
+         * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
+         *
+         * @internal
+         */
+        abstract class InterimTestCase extends BaseTestCase
+        {
+        }
+    }
+
     /**
      * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
      *
      * @internal
      */
-    abstract class TestCase extends BaseTestCase
+    abstract class TestCase extends InterimTestCase
     {
         use ExpectationViaCodeOverAnnotationTrait;
         use ExpectOverSetExceptionTrait;