Created
February 7, 2017 21:10
-
-
Save guilhermeblanco/7d34235ee1e4b789c6c0b8e82dc583c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tests/Regression/GitHub/2482.phpt b/tests/Regression/GitHub/2482.phpt | |
new file mode 100644 | |
index 000000000..dd887c550 | |
--- /dev/null | |
+++ b/tests/Regression/GitHub/2482.phpt | |
@@ -0,0 +1,19 @@ | |
+--TEST-- | |
+#2482: PHPUnit 6 upgrade fails 5.7 passing tests | |
+--FILE-- | |
+<?php | |
+$_SERVER['argv'][1] = '--no-configuration'; | |
+$_SERVER['argv'][2] = 'Issue2482Test'; | |
+$_SERVER['argv'][3] = __DIR__ . '/2482/Issue2482Test.php'; | |
+ | |
+require __DIR__ . '/../../bootstrap.php'; | |
+PHPUnit\TextUI\Command::main(); | |
+?> | |
+--EXPECTF-- | |
+PHPUnit %s by Sebastian Bergmann and contributors. | |
+ | |
+... 3 / 3 (100%) | |
+ | |
+Time: %s, Memory: %s | |
+ | |
+OK (3 tests, 6 assertions) | |
diff --git a/tests/Regression/GitHub/2482/Issue2482Test.php b/tests/Regression/GitHub/2482/Issue2482Test.php | |
new file mode 100644 | |
index 000000000..f154e382e | |
--- /dev/null | |
+++ b/tests/Regression/GitHub/2482/Issue2482Test.php | |
@@ -0,0 +1,95 @@ | |
+<?php | |
+ | |
+use PHPUnit\Framework\TestCase; | |
+ | |
+class DecoratedMockTest extends TestCase | |
+{ | |
+ private $wrapped; | |
+ private $decorator; | |
+ | |
+ public function setUp() | |
+ { | |
+ $this->wrapped = $this->createMock(EntityManagerInterface::class); | |
+ $this->decorator = new class($this->wrapped) extends EntityManagerDecorator {}; | |
+ } | |
+ | |
+ public function getMethodParameters() | |
+ { | |
+ $class = new \ReflectionClass(EntityManager::class); | |
+ | |
+ $methods = []; | |
+ | |
+ foreach ($class->getMethods() as $method) { | |
+ if ($method->isConstructor() || $method->isStatic() || !$method->isPublic()) { | |
+ continue; | |
+ } | |
+ | |
+ if ($method->getNumberOfRequiredParameters() === 0) { | |
+ $methods[] = [$method->getName(), []]; | |
+ } elseif ($method->getNumberOfRequiredParameters() > 0) { | |
+ $methods[] = [$method->getName(), array_fill(0, $method->getNumberOfRequiredParameters(), 'req') ?: []]; | |
+ } | |
+ | |
+ if ($method->getNumberOfParameters() != $method->getNumberOfRequiredParameters()) { | |
+ $methods[] = [$method->getName(), array_fill(0, $method->getNumberOfParameters(), 'all') ?: []]; | |
+ } | |
+ } | |
+ | |
+ return $methods; | |
+ } | |
+ | |
+ /** | |
+ * @dataProvider getMethodParameters | |
+ */ | |
+ public function testAllMethodCallsAreDelegatedToTheWrappedInstance($method, array $parameters) | |
+ { | |
+ $message = 'INNER VALUE FROM ' . $method; | |
+ $stub = $this->wrapped | |
+ ->expects(self::once()) | |
+ ->method($method) | |
+ ->willReturn($message) | |
+ ; | |
+ | |
+ call_user_func_array([$stub, 'with'], $parameters); | |
+ | |
+ self::assertEquals($message, call_user_func_array([$this->decorator, $method], $parameters)); | |
+ } | |
+} | |
+ | |
+interface ObjectManagerInterface | |
+{ | |
+ public function clear($objectName = null); | |
+ | |
+ public function persist($object); | |
+} | |
+ | |
+interface EntityManagerInterface extends ObjectManagerInterface | |
+{ | |
+} | |
+ | |
+class EntityManager implements EntityManagerInterface | |
+{ | |
+ public function clear($objectName = null) {} | |
+ | |
+ public function persist($object) {} | |
+} | |
+ | |
+abstract class EntityManagerDecorator implements EntityManagerInterface | |
+{ | |
+ protected $wrapped; | |
+ | |
+ public function __construct(EntityManagerInterface $wrapped) | |
+ { | |
+ $this->wrapped = $wrapped; | |
+ } | |
+ | |
+ public function clear($objectName = null) | |
+ { | |
+ return $this->wrapped->clear($objectName); | |
+ } | |
+ | |
+ public function persist($object) | |
+ { | |
+ return $this->wrapped->persist($object); | |
+ } | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment