composer update
This commit is contained in:
Vendored
+23
@@ -1,3 +1,26 @@
|
||||
1.10.3 / 2020/03/05
|
||||
===================
|
||||
|
||||
* [fixed] removed fatal error when phpdocumentor/reflection-docblock 5 parses an invalid `@method` tag (@stof)
|
||||
|
||||
1.10.2 / 2020/01/20
|
||||
===================
|
||||
|
||||
* [added] support for new versions of `sebastian/comparator` and `sebastian/recursion-context` (@sebastianbergmann)
|
||||
|
||||
1.10.1 / 2019/12/22
|
||||
===================
|
||||
|
||||
* [fixed] identical callables no longer match as arguments (@ciaranmcnulty)
|
||||
|
||||
1.10.0 / 2019/12/17
|
||||
===================
|
||||
|
||||
* [added] shouldHaveBeenCalled evaluation happens later so un-stubbed calls don't throw (@elvetemedve)
|
||||
* [added] methods can now be doubled case-insensitively to match PHP semantics (@michalbundyra)
|
||||
* [fixed] reduced memory usage by optimising CachedDoubler (@DonCallisto)
|
||||
* [fixed] removed fatal error nesting level when comparing large objects (@scroach)
|
||||
|
||||
1.9.0 / 2019/10/03
|
||||
==================
|
||||
|
||||
|
||||
+4
-4
@@ -20,13 +20,13 @@
|
||||
"require": {
|
||||
"php": "^5.3|^7.0",
|
||||
"phpdocumentor/reflection-docblock": "^2.0|^3.0.2|^4.0|^5.0",
|
||||
"sebastian/comparator": "^1.1|^2.0|^3.0",
|
||||
"sebastian/comparator": "^1.2.3|^2.0|^3.0|^4.0",
|
||||
"doctrine/instantiator": "^1.0.2",
|
||||
"sebastian/recursion-context": "^1.0|^2.0|^3.0"
|
||||
"sebastian/recursion-context": "^1.0|^2.0|^3.0|^4.0"
|
||||
},
|
||||
|
||||
"require-dev": {
|
||||
"phpspec/phpspec": "^2.5|^3.2",
|
||||
"phpspec/phpspec": "^2.5 || ^3.2",
|
||||
"phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5 || ^7.1"
|
||||
},
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "1.8.x-dev"
|
||||
"dev-master": "1.10.x-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,9 @@ class ExactValueToken implements TokenInterface
|
||||
try {
|
||||
$comparator->assertEquals($argument, $this->value);
|
||||
return 10;
|
||||
} catch (ComparisonFailure $failure) {}
|
||||
} catch (ComparisonFailure $failure) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// If either one is an object it should be castable to a string
|
||||
|
||||
+51
-9
@@ -16,6 +16,7 @@ use Prophecy\Prophecy\ObjectProphecy;
|
||||
use Prophecy\Argument\ArgumentsWildcard;
|
||||
use Prophecy\Util\StringUtil;
|
||||
use Prophecy\Exception\Call\UnexpectedCallException;
|
||||
use SplObjectStorage;
|
||||
|
||||
/**
|
||||
* Calls receiver & manager.
|
||||
@@ -31,6 +32,11 @@ class CallCenter
|
||||
*/
|
||||
private $recordedCalls = array();
|
||||
|
||||
/**
|
||||
* @var SplObjectStorage
|
||||
*/
|
||||
private $unexpectedCalls;
|
||||
|
||||
/**
|
||||
* Initializes call center.
|
||||
*
|
||||
@@ -39,6 +45,7 @@ class CallCenter
|
||||
public function __construct(StringUtil $util = null)
|
||||
{
|
||||
$this->util = $util ?: new StringUtil;
|
||||
$this->unexpectedCalls = new SplObjectStorage();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,23 +80,21 @@ class CallCenter
|
||||
}
|
||||
|
||||
// If no method prophecies defined, then it's a dummy, so we'll just return null
|
||||
if ('__destruct' === $methodName || 0 == count($prophecy->getMethodProphecies())) {
|
||||
if ('__destruct' === strtolower($methodName) || 0 == count($prophecy->getMethodProphecies())) {
|
||||
$this->recordedCalls[] = new Call($methodName, $arguments, null, null, $file, $line);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// There are method prophecies, so it's a fake/stub. Searching prophecy for this call
|
||||
$matches = array();
|
||||
foreach ($prophecy->getMethodProphecies($methodName) as $methodProphecy) {
|
||||
if (0 < $score = $methodProphecy->getArgumentsWildcard()->scoreArguments($arguments)) {
|
||||
$matches[] = array($score, $methodProphecy);
|
||||
}
|
||||
}
|
||||
$matches = $this->findMethodProphecies($prophecy, $methodName, $arguments);
|
||||
|
||||
// If fake/stub doesn't have method prophecy for this call - throw exception
|
||||
if (!count($matches)) {
|
||||
throw $this->createUnexpectedCallException($prophecy, $methodName, $arguments);
|
||||
$this->unexpectedCalls->attach(new Call($methodName, $arguments, null, null, $file, $line), $prophecy);
|
||||
$this->recordedCalls[] = new Call($methodName, $arguments, null, null, $file, $line);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Sort matches by their score value
|
||||
@@ -137,15 +142,33 @@ class CallCenter
|
||||
*/
|
||||
public function findCalls($methodName, ArgumentsWildcard $wildcard)
|
||||
{
|
||||
$methodName = strtolower($methodName);
|
||||
|
||||
return array_values(
|
||||
array_filter($this->recordedCalls, function (Call $call) use ($methodName, $wildcard) {
|
||||
return $methodName === $call->getMethodName()
|
||||
return $methodName === strtolower($call->getMethodName())
|
||||
&& 0 < $call->getScore($wildcard)
|
||||
;
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws UnexpectedCallException
|
||||
*/
|
||||
public function checkUnexpectedCalls()
|
||||
{
|
||||
/** @var Call $call */
|
||||
foreach ($this->unexpectedCalls as $call) {
|
||||
$prophecy = $this->unexpectedCalls[$call];
|
||||
|
||||
// If fake/stub doesn't have method prophecy for this call - throw exception
|
||||
if (!count($this->findMethodProphecies($prophecy, $call->getMethodName(), $call->getArguments()))) {
|
||||
throw $this->createUnexpectedCallException($prophecy, $call->getMethodName(), $call->getArguments());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function createUnexpectedCallException(ObjectProphecy $prophecy, $methodName,
|
||||
array $arguments)
|
||||
{
|
||||
@@ -203,4 +226,23 @@ class CallCenter
|
||||
$arguments
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ObjectProphecy $prophecy
|
||||
* @param string $methodName
|
||||
* @param array $arguments
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function findMethodProphecies(ObjectProphecy $prophecy, $methodName, array $arguments)
|
||||
{
|
||||
$matches = array();
|
||||
foreach ($prophecy->getMethodProphecies($methodName) as $methodProphecy) {
|
||||
if (0 < $score = $methodProphecy->getArgumentsWildcard()->scoreArguments($arguments)) {
|
||||
$matches[] = array($score, $methodProphecy);
|
||||
}
|
||||
}
|
||||
|
||||
return $matches;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,16 +27,18 @@ final class ClosureComparator extends Comparator
|
||||
&& is_object($actual) && $actual instanceof \Closure;
|
||||
}
|
||||
|
||||
public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false)
|
||||
public function assertEquals($expected, $actual, $delta = 0.0, $canonicalize = false, $ignoreCase = false, array &$processed = array())
|
||||
{
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
// we don't need a diff
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
'all closures are born different'
|
||||
);
|
||||
if ($expected !== $actual) {
|
||||
throw new ComparisonFailure(
|
||||
$expected,
|
||||
$actual,
|
||||
// we don't need a diff
|
||||
'',
|
||||
'',
|
||||
false,
|
||||
'all closures are different if not identical'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-14
@@ -21,17 +21,7 @@ use ReflectionClass;
|
||||
*/
|
||||
class CachedDoubler extends Doubler
|
||||
{
|
||||
private $classes = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function registerClassPatch(ClassPatch\ClassPatchInterface $patch)
|
||||
{
|
||||
$this->classes[] = array();
|
||||
|
||||
parent::registerClassPatch($patch);
|
||||
}
|
||||
private static $classes = array();
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
@@ -39,11 +29,11 @@ class CachedDoubler extends Doubler
|
||||
protected function createDoubleClass(ReflectionClass $class = null, array $interfaces)
|
||||
{
|
||||
$classId = $this->generateClassId($class, $interfaces);
|
||||
if (isset($this->classes[$classId])) {
|
||||
return $this->classes[$classId];
|
||||
if (isset(self::$classes[$classId])) {
|
||||
return self::$classes[$classId];
|
||||
}
|
||||
|
||||
return $this->classes[$classId] = parent::createDoubleClass($class, $interfaces);
|
||||
return self::$classes[$classId] = parent::createDoubleClass($class, $interfaces);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,8 +51,16 @@ class CachedDoubler extends Doubler
|
||||
foreach ($interfaces as $interface) {
|
||||
$parts[] = $interface->getName();
|
||||
}
|
||||
foreach ($this->getClassPatches() as $patch) {
|
||||
$parts[] = get_class($patch);
|
||||
}
|
||||
sort($parts);
|
||||
|
||||
return md5(implode('', $parts));
|
||||
}
|
||||
|
||||
public function resetCache()
|
||||
{
|
||||
self::$classes = array();
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -43,7 +43,7 @@ class ProphecySubjectPatch implements ClassPatchInterface
|
||||
public function apply(ClassNode $node)
|
||||
{
|
||||
$node->addInterface('Prophecy\Prophecy\ProphecySubjectInterface');
|
||||
$node->addProperty('objectProphecy', 'private');
|
||||
$node->addProperty('objectProphecyClosure', 'private');
|
||||
|
||||
foreach ($node->getMethods() as $name => $method) {
|
||||
if ('__construct' === strtolower($name)) {
|
||||
@@ -65,10 +65,10 @@ class ProphecySubjectPatch implements ClassPatchInterface
|
||||
$prophecyArgument = new ArgumentNode('prophecy');
|
||||
$prophecyArgument->setTypeHint('Prophecy\Prophecy\ProphecyInterface');
|
||||
$prophecySetter->addArgument($prophecyArgument);
|
||||
$prophecySetter->setCode('$this->objectProphecy = $prophecy;');
|
||||
$prophecySetter->setCode('$this->objectProphecyClosure = function () use ($prophecy) { return $prophecy; };');
|
||||
|
||||
$prophecyGetter = new MethodNode('getProphecy');
|
||||
$prophecyGetter->setCode('return $this->objectProphecy;');
|
||||
$prophecyGetter->setCode('return call_user_func($this->objectProphecyClosure);');
|
||||
|
||||
if ($node->hasMethod('__call')) {
|
||||
$__call = $node->getMethod('__call');
|
||||
|
||||
@@ -44,7 +44,15 @@ final class ClassTagRetriever implements MethodTagRetrieverInterface
|
||||
$this->contextFactory->createFromReflector($reflectionClass)
|
||||
);
|
||||
|
||||
return $phpdoc->getTagsByName('method');
|
||||
$methods = array();
|
||||
|
||||
foreach ($phpdoc->getTagsByName('method') as $tag) {
|
||||
if ($tag instanceof Method) {
|
||||
$methods[] = $tag;
|
||||
}
|
||||
}
|
||||
|
||||
return $methods;
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return array();
|
||||
}
|
||||
|
||||
@@ -146,7 +146,7 @@ class ObjectProphecy implements ProphecyInterface
|
||||
), $methodProphecy);
|
||||
}
|
||||
|
||||
$methodName = $methodProphecy->getMethodName();
|
||||
$methodName = strtolower($methodProphecy->getMethodName());
|
||||
|
||||
if (!isset($this->methodProphecies[$methodName])) {
|
||||
$this->methodProphecies[$methodName] = array();
|
||||
@@ -168,6 +168,8 @@ class ObjectProphecy implements ProphecyInterface
|
||||
return $this->methodProphecies;
|
||||
}
|
||||
|
||||
$methodName = strtolower($methodName);
|
||||
|
||||
if (!isset($this->methodProphecies[$methodName])) {
|
||||
return array();
|
||||
}
|
||||
@@ -208,12 +210,15 @@ class ObjectProphecy implements ProphecyInterface
|
||||
* Checks that registered method predictions do not fail.
|
||||
*
|
||||
* @throws \Prophecy\Exception\Prediction\AggregateException If any of registered predictions fail
|
||||
* @throws \Prophecy\Exception\Call\UnexpectedCallException
|
||||
*/
|
||||
public function checkProphecyMethodsPredictions()
|
||||
{
|
||||
$exception = new AggregateException(sprintf("%s:\n", get_class($this->reveal())));
|
||||
$exception->setObjectProphecy($this);
|
||||
|
||||
$this->callCenter->checkUnexpectedCalls();
|
||||
|
||||
foreach ($this->methodProphecies as $prophecies) {
|
||||
foreach ($prophecies as $prophecy) {
|
||||
try {
|
||||
|
||||
+7
-4
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Prophecy;
|
||||
|
||||
use Prophecy\Doubler\CachedDoubler;
|
||||
use Prophecy\Doubler\Doubler;
|
||||
use Prophecy\Doubler\LazyDouble;
|
||||
use Prophecy\Doubler\ClassPatch;
|
||||
@@ -45,11 +46,13 @@ class Prophet
|
||||
* @param null|RevealerInterface $revealer
|
||||
* @param null|StringUtil $util
|
||||
*/
|
||||
public function __construct(Doubler $doubler = null, RevealerInterface $revealer = null,
|
||||
StringUtil $util = null)
|
||||
{
|
||||
public function __construct(
|
||||
Doubler $doubler = null,
|
||||
RevealerInterface $revealer = null,
|
||||
StringUtil $util = null
|
||||
) {
|
||||
if (null === $doubler) {
|
||||
$doubler = new Doubler;
|
||||
$doubler = new CachedDoubler();
|
||||
$doubler->registerClassPatch(new ClassPatch\SplFileInfoPatch);
|
||||
$doubler->registerClassPatch(new ClassPatch\TraversablePatch);
|
||||
$doubler->registerClassPatch(new ClassPatch\ThrowablePatch);
|
||||
|
||||
@@ -181,9 +181,7 @@ class ExportUtil
|
||||
if (is_object($value)) {
|
||||
$class = get_class($value);
|
||||
|
||||
if ($value instanceof ProphecyInterface) {
|
||||
return sprintf('%s Object (*Prophecy*)', $class);
|
||||
} elseif ($hash = $processed->contains($value)) {
|
||||
if ($hash = $processed->contains($value)) {
|
||||
return sprintf('%s:%s Object', $class, $hash);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user