Created
April 14, 2016 16:45
-
-
Save index0h/f45f8ba86bd999fde2e6ff813a1f15ff to your computer and use it in GitHub Desktop.
testAddNeverConstraints.php
This file contains 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
<?php | |
class Test { | |
protected function verifyMockObjects() | |
{ | |
$reflectionMockObjectsProperty = new \ReflectionProperty(\PHPUnit_Framework_TestCase::class, 'mockObjects'); | |
$reflectionMockObjectsProperty->setAccessible(true); | |
$reflectionConfigurableMethods = new \ReflectionProperty( | |
\PHPUnit_Framework_MockObject_InvocationMocker::class, | |
'configurableMethods' | |
); | |
$reflectionConfigurableMethods->setAccessible(true); | |
$reflectionMatchers = new \ReflectionProperty( | |
\PHPUnit_Framework_MockObject_InvocationMocker::class, | |
'matchers' | |
); | |
$reflectionMatchers->setAccessible(true); | |
/** @var \PHPUnit_Framework_MockObject_MockObject[] $mockObjects */ | |
$mockObjects = $reflectionMockObjectsProperty->getValue($this); | |
$configuredMethods = []; | |
$className = null; | |
foreach ($mockObjects as $mockObject) { | |
/** @var \PHPUnit_Framework_MockObject_InvocationMocker $invocationMocker */ | |
$invocationMocker = $mockObject->__phpunit_getInvocationMocker(); | |
/** @var \PHPUnit_Framework_MockObject_Matcher[] $matchers */ | |
$matchers = $reflectionMatchers->getValue($invocationMocker); | |
$configurableMethodNames = $reflectionConfigurableMethods->getValue($invocationMocker); | |
foreach ($matchers as $matcher) { | |
/** @var \PHPUnit_Framework_MockObject_Matcher_Invocation[] $invocations */ | |
$invocations = $matcher->invocationMatcher->getInvocations(); | |
foreach ($invocations as $invocation) { | |
$className = $invocation->className; | |
$configuredMethods[] = $invocation->methodName; | |
} | |
} | |
$classMethods = get_class_methods($className); | |
foreach ($classMethods as $classMethod) { | |
if (in_array($classMethod, $configuredMethods)) { | |
continue; | |
} | |
if (!in_array(strtolower($classMethod), $configurableMethodNames)) { | |
continue; | |
} | |
$mockObject->expects($this->never()) | |
->method($classMethod); | |
} | |
} | |
parent::verifyMockObjects(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment