diff options
Diffstat (limited to 'vendor/phpunit/phpunit-mock-objects/src')
56 files changed, 4600 insertions, 0 deletions
diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Identity.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Identity.php new file mode 100644 index 0000000..cb3a8fc --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Identity.php @@ -0,0 +1,31 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Builder interface for unique identifiers. + * + * Defines the interface for recording unique identifiers. The identifiers + * can be used to define the invocation order of expectations. The expectation + * is recorded using id() and then defined in order using + * PHPUnit_Framework_MockObject_Builder_Match::after(). + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_Identity +{ + /** + * Sets the identification of the expectation to $id. + * + * @note The identifier is unique per mock object. + * + * @param string $id Unique identification of expectation. + */ + public function id($id); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/InvocationMocker.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/InvocationMocker.php new file mode 100644 index 0000000..7f507c8 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/InvocationMocker.php @@ -0,0 +1,291 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Builder for mocked or stubbed invocations. + * + * Provides methods for building expectations without having to resort to + * instantiating the various matchers manually. These methods also form a + * more natural way of reading the expectation. This class should be together + * with the test case PHPUnit_Framework_MockObject_TestCase. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Builder_InvocationMocker implements PHPUnit_Framework_MockObject_Builder_MethodNameMatch +{ + /** + * @var PHPUnit_Framework_MockObject_Stub_MatcherCollection + */ + protected $collection; + + /** + * @var PHPUnit_Framework_MockObject_Matcher + */ + protected $matcher; + + /** + * @var string[] + */ + private $configurableMethods = []; + + /** + * @param PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher + * @param array $configurableMethods + */ + public function __construct(PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection, PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher, array $configurableMethods) + { + $this->collection = $collection; + $this->matcher = new PHPUnit_Framework_MockObject_Matcher( + $invocationMatcher + ); + + $this->collection->addMatcher($this->matcher); + + $this->configurableMethods = $configurableMethods; + } + + /** + * @return PHPUnit_Framework_MockObject_Matcher + */ + public function getMatcher() + { + return $this->matcher; + } + + /** + * @param mixed $id + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function id($id) + { + $this->collection->registerId($id, $this); + + return $this; + } + + /** + * @param PHPUnit_Framework_MockObject_Stub $stub + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function will(PHPUnit_Framework_MockObject_Stub $stub) + { + $this->matcher->stub = $stub; + + return $this; + } + + /** + * @param mixed $value + * @param mixed $nextValues, ... + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function willReturn($value, ...$nextValues) + { + $stub = count($nextValues) === 0 ? + new PHPUnit_Framework_MockObject_Stub_Return($value) : + new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls( + array_merge([$value], $nextValues) + ); + + return $this->will($stub); + } + + /** + * @param mixed $reference + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function willReturnReference(&$reference) + { + $stub = new PHPUnit_Framework_MockObject_Stub_ReturnReference($reference); + + return $this->will($stub); + } + + /** + * @param array $valueMap + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function willReturnMap(array $valueMap) + { + $stub = new PHPUnit_Framework_MockObject_Stub_ReturnValueMap( + $valueMap + ); + + return $this->will($stub); + } + + /** + * @param mixed $argumentIndex + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function willReturnArgument($argumentIndex) + { + $stub = new PHPUnit_Framework_MockObject_Stub_ReturnArgument( + $argumentIndex + ); + + return $this->will($stub); + } + + /** + * @param callable $callback + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function willReturnCallback($callback) + { + $stub = new PHPUnit_Framework_MockObject_Stub_ReturnCallback( + $callback + ); + + return $this->will($stub); + } + + /** + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function willReturnSelf() + { + $stub = new PHPUnit_Framework_MockObject_Stub_ReturnSelf; + + return $this->will($stub); + } + + /** + * @param mixed $values, ... + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function willReturnOnConsecutiveCalls(...$values) + { + $stub = new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls($values); + + return $this->will($stub); + } + + /** + * @param Exception $exception + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function willThrowException(Exception $exception) + { + $stub = new PHPUnit_Framework_MockObject_Stub_Exception($exception); + + return $this->will($stub); + } + + /** + * @param mixed $id + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function after($id) + { + $this->matcher->afterMatchBuilderId = $id; + + return $this; + } + + /** + * Validate that a parameters matcher can be defined, throw exceptions otherwise. + * + * @throws PHPUnit_Framework_MockObject_RuntimeException + */ + private function canDefineParameters() + { + if ($this->matcher->methodNameMatcher === null) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + 'Method name matcher is not defined, cannot define parameter ' . + 'matcher without one' + ); + } + + if ($this->matcher->parametersMatcher !== null) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + 'Parameter matcher is already defined, cannot redefine' + ); + } + } + + /** + * @param array ...$arguments + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function with(...$arguments) + { + $this->canDefineParameters(); + + $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_Parameters($arguments); + + return $this; + } + + /** + * @param array ...$arguments + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function withConsecutive(...$arguments) + { + $this->canDefineParameters(); + + $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters($arguments); + + return $this; + } + + /** + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function withAnyParameters() + { + $this->canDefineParameters(); + + $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters; + + return $this; + } + + /** + * @param PHPUnit_Framework_Constraint|string $constraint + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function method($constraint) + { + if ($this->matcher->methodNameMatcher !== null) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + 'Method name matcher is already defined, cannot redefine' + ); + } + + if (is_string($constraint) && !in_array(strtolower($constraint), $this->configurableMethods)) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Trying to configure method "%s" which cannot be configured because it does not exist, has not been specified, is final, or is static', + $constraint + ) + ); + } + + $this->matcher->methodNameMatcher = new PHPUnit_Framework_MockObject_Matcher_MethodName($constraint); + + return $this; + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Match.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Match.php new file mode 100644 index 0000000..16880ac --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Match.php @@ -0,0 +1,27 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Builder interface for invocation order matches. + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_Match extends PHPUnit_Framework_MockObject_Builder_Stub +{ + /** + * Defines the expectation which must occur before the current is valid. + * + * @param string $id The identification of the expectation that should + * occur before this one. + * + * @return PHPUnit_Framework_MockObject_Builder_Stub + */ + public function after($id); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/MethodNameMatch.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/MethodNameMatch.php new file mode 100644 index 0000000..b3a4590 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/MethodNameMatch.php @@ -0,0 +1,27 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Builder interface for matcher of method names. + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_MethodNameMatch extends PHPUnit_Framework_MockObject_Builder_ParametersMatch +{ + /** + * Adds a new method name match and returns the parameter match object for + * further matching possibilities. + * + * @param PHPUnit_Framework_Constraint $name Constraint for matching method, if a string is passed it will use the PHPUnit_Framework_Constraint_IsEqual + * + * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch + */ + public function method($name); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Namespace.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Namespace.php new file mode 100644 index 0000000..960f455 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Namespace.php @@ -0,0 +1,38 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Interface for builders which can register builders with a given identification. + * + * This interface relates to PHPUnit_Framework_MockObject_Builder_Identity. + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_Namespace +{ + /** + * Looks up the match builder with identification $id and returns it. + * + * @param string $id The identification of the match builder + * + * @return PHPUnit_Framework_MockObject_Builder_Match + */ + public function lookupId($id); + + /** + * Registers the match builder $builder with the identification $id. The + * builder can later be looked up using lookupId() to figure out if it + * has been invoked. + * + * @param string $id The identification of the match builder + * @param PHPUnit_Framework_MockObject_Builder_Match $builder The builder which is being registered + */ + public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/ParametersMatch.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/ParametersMatch.php new file mode 100644 index 0000000..2b2097a --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/ParametersMatch.php @@ -0,0 +1,49 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Builder interface for parameter matchers. + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_ParametersMatch extends PHPUnit_Framework_MockObject_Builder_Match +{ + /** + * Sets the parameters to match for, each parameter to this funtion will + * be part of match. To perform specific matches or constraints create a + * new PHPUnit_Framework_Constraint and use it for the parameter. + * If the parameter value is not a constraint it will use the + * PHPUnit_Framework_Constraint_IsEqual for the value. + * + * Some examples: + * <code> + * // match first parameter with value 2 + * $b->with(2); + * // match first parameter with value 'smock' and second identical to 42 + * $b->with('smock', new PHPUnit_Framework_Constraint_IsEqual(42)); + * </code> + * + * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch + */ + public function with(...$arguments); + + /** + * Sets a matcher which allows any kind of parameters. + * + * Some examples: + * <code> + * // match any number of parameters + * $b->withAnyParameters(); + * </code> + * + * @return PHPUnit_Framework_MockObject_Matcher_AnyParameters + */ + public function withAnyParameters(); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Stub.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Stub.php new file mode 100644 index 0000000..103e8f2 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Builder/Stub.php @@ -0,0 +1,27 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Builder interface for stubs which are actions replacing an invocation. + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Builder_Stub extends PHPUnit_Framework_MockObject_Builder_Identity +{ + /** + * Stubs the matching method with the stub object $stub. Any invocations of + * the matched method will now be handled by the stub instead. + * + * @param PHPUnit_Framework_MockObject_Stub $stub + * + * @return PHPUnit_Framework_MockObject_Builder_Identity + */ + public function will(PHPUnit_Framework_MockObject_Stub $stub); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Exception/BadMethodCallException.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Exception/BadMethodCallException.php new file mode 100644 index 0000000..736784b --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Exception/BadMethodCallException.php @@ -0,0 +1,16 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * @since Class available since Release 2.0.6 + */ +class PHPUnit_Framework_MockObject_BadMethodCallException extends BadMethodCallException implements PHPUnit_Framework_MockObject_Exception +{ +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Exception/Exception.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Exception/Exception.php new file mode 100644 index 0000000..bc8c81d --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Exception/Exception.php @@ -0,0 +1,18 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Interface for exceptions used by PHPUnit_MockObject. + * + * @since Interface available since Release 2.0.6 + */ +interface PHPUnit_Framework_MockObject_Exception +{ +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Exception/RuntimeException.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Exception/RuntimeException.php new file mode 100644 index 0000000..1e9b6f1 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Exception/RuntimeException.php @@ -0,0 +1,16 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * @since Class available since Release 2.0.6 + */ +class PHPUnit_Framework_MockObject_RuntimeException extends RuntimeException implements PHPUnit_Framework_MockObject_Exception +{ +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php new file mode 100644 index 0000000..bfb899d --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php @@ -0,0 +1,1324 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use Doctrine\Instantiator\Instantiator; +use Doctrine\Instantiator\Exception\InvalidArgumentException as InstantiatorInvalidArgumentException; +use Doctrine\Instantiator\Exception\UnexpectedValueException as InstantiatorUnexpectedValueException; + +/** + * Mock Object Code Generator + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Generator +{ + /** + * @var array + */ + private static $cache = []; + + /** + * @var Text_Template[] + */ + private static $templates = []; + + /** + * @var array + */ + private $legacyBlacklistedMethodNames = [ + '__CLASS__' => true, + '__DIR__' => true, + '__FILE__' => true, + '__FUNCTION__' => true, + '__LINE__' => true, + '__METHOD__' => true, + '__NAMESPACE__' => true, + '__TRAIT__' => true, + '__clone' => true, + '__halt_compiler' => true, + 'abstract' => true, + 'and' => true, + 'array' => true, + 'as' => true, + 'break' => true, + 'callable' => true, + 'case' => true, + 'catch' => true, + 'class' => true, + 'clone' => true, + 'const' => true, + 'continue' => true, + 'declare' => true, + 'default' => true, + 'die' => true, + 'do' => true, + 'echo' => true, + 'else' => true, + 'elseif' => true, + 'empty' => true, + 'enddeclare' => true, + 'endfor' => true, + 'endforeach' => true, + 'endif' => true, + 'endswitch' => true, + 'endwhile' => true, + 'eval' => true, + 'exit' => true, + 'expects' => true, + 'extends' => true, + 'final' => true, + 'for' => true, + 'foreach' => true, + 'function' => true, + 'global' => true, + 'goto' => true, + 'if' => true, + 'implements' => true, + 'include' => true, + 'include_once' => true, + 'instanceof' => true, + 'insteadof' => true, + 'interface' => true, + 'isset' => true, + 'list' => true, + 'namespace' => true, + 'new' => true, + 'or' => true, + 'print' => true, + 'private' => true, + 'protected' => true, + 'public' => true, + 'require' => true, + 'require_once' => true, + 'return' => true, + 'static' => true, + 'switch' => true, + 'throw' => true, + 'trait' => true, + 'try' => true, + 'unset' => true, + 'use' => true, + 'var' => true, + 'while' => true, + 'xor' => true + ]; + + /** + * @var array + */ + private $blacklistedMethodNames = [ + '__CLASS__' => true, + '__DIR__' => true, + '__FILE__' => true, + '__FUNCTION__' => true, + '__LINE__' => true, + '__METHOD__' => true, + '__NAMESPACE__' => true, + '__TRAIT__' => true, + '__clone' => true, + '__halt_compiler' => true, + ]; + + /** + * Returns a mock object for the specified class. + * + * @param array|string $type + * @param array $methods + * @param array $arguments + * @param string $mockClassName + * @param bool $callOriginalConstructor + * @param bool $callOriginalClone + * @param bool $callAutoload + * @param bool $cloneArguments + * @param bool $callOriginalMethods + * @param object $proxyTarget + * @param bool $allowMockingUnknownTypes + * + * @return PHPUnit_Framework_MockObject_MockObject + * + * @throws InvalidArgumentException + * @throws PHPUnit_Framework_Exception + * @throws PHPUnit_Framework_MockObject_RuntimeException + * + * @since Method available since Release 1.0.0 + */ + public function getMock($type, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = true, $callOriginalMethods = false, $proxyTarget = null, $allowMockingUnknownTypes = true) + { + if (!is_array($type) && !is_string($type)) { + throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'array or string'); + } + + if (!is_string($mockClassName)) { + throw PHPUnit_Util_InvalidArgumentHelper::factory(4, 'string'); + } + + if (!is_array($methods) && !is_null($methods)) { + throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'array', $methods); + } + + if ($type === 'Traversable' || $type === '\\Traversable') { + $type = 'Iterator'; + } + + if (is_array($type)) { + $type = array_unique( + array_map( + function ($type) { + if ($type === 'Traversable' || + $type === '\\Traversable' || + $type === '\\Iterator') { + return 'Iterator'; + } + + return $type; + }, + $type + ) + ); + } + + if (!$allowMockingUnknownTypes) { + if (is_array($type)) { + foreach ($type as $_type) { + if (!class_exists($_type, $callAutoload) && + !interface_exists($_type, $callAutoload)) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Cannot stub or mock class or interface "%s" which does not exist', + $_type + ) + ); + } + } + } else { + if (!class_exists($type, $callAutoload) && + !interface_exists($type, $callAutoload) + ) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Cannot stub or mock class or interface "%s" which does not exist', + $type + ) + ); + } + } + } + + if (null !== $methods) { + foreach ($methods as $method) { + if (!preg_match('~[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*~', $method)) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Cannot stub or mock method with invalid name "%s"', + $method + ) + ); + } + } + + if ($methods != array_unique($methods)) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Cannot stub or mock using a method list that contains duplicates: "%s" (duplicate: "%s")', + implode(', ', $methods), + implode(', ', array_unique(array_diff_assoc($methods, array_unique($methods)))) + ) + ); + } + } + + if ($mockClassName != '' && class_exists($mockClassName, false)) { + $reflect = new ReflectionClass($mockClassName); + + if (!$reflect->implementsInterface('PHPUnit_Framework_MockObject_MockObject')) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Class "%s" already exists.', + $mockClassName + ) + ); + } + } + + if ($callOriginalConstructor === false && $callOriginalMethods === true) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + 'Proxying to original methods requires invoking the original constructor' + ); + } + + $mock = $this->generate( + $type, + $methods, + $mockClassName, + $callOriginalClone, + $callAutoload, + $cloneArguments, + $callOriginalMethods + ); + + return $this->getObject( + $mock['code'], + $mock['mockClassName'], + $type, + $callOriginalConstructor, + $callAutoload, + $arguments, + $callOriginalMethods, + $proxyTarget + ); + } + + /** + * @param string $code + * @param string $className + * @param array|string $type + * @param bool $callOriginalConstructor + * @param bool $callAutoload + * @param array $arguments + * @param bool $callOriginalMethods + * @param object $proxyTarget + * + * @return object + */ + private function getObject($code, $className, $type = '', $callOriginalConstructor = false, $callAutoload = false, array $arguments = [], $callOriginalMethods = false, $proxyTarget = null) + { + $this->evalClass($code, $className); + + if ($callOriginalConstructor && + is_string($type) && + !interface_exists($type, $callAutoload)) { + if (count($arguments) == 0) { + $object = new $className; + } else { + $class = new ReflectionClass($className); + $object = $class->newInstanceArgs($arguments); + } + } else { + try { + $instantiator = new Instantiator; + $object = $instantiator->instantiate($className); + } catch (InstantiatorUnexpectedValueException $exception) { + if ($exception->getPrevious()) { + $exception = $exception->getPrevious(); + } + + throw new PHPUnit_Framework_MockObject_RuntimeException( + $exception->getMessage() + ); + } catch (InstantiatorInvalidArgumentException $exception) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + $exception->getMessage() + ); + } + } + + if ($callOriginalMethods) { + if (!is_object($proxyTarget)) { + if (count($arguments) == 0) { + $proxyTarget = new $type; + } else { + $class = new ReflectionClass($type); + $proxyTarget = $class->newInstanceArgs($arguments); + } + } + + $object->__phpunit_setOriginalObject($proxyTarget); + } + + return $object; + } + + /** + * @param string $code + * @param string $className + */ + private function evalClass($code, $className) + { + if (!class_exists($className, false)) { + eval($code); + } + } + + /** + * Returns a mock object for the specified abstract class with all abstract + * methods of the class mocked. Concrete methods to mock can be specified with + * the last parameter + * + * @param string $originalClassName + * @param array $arguments + * @param string $mockClassName + * @param bool $callOriginalConstructor + * @param bool $callOriginalClone + * @param bool $callAutoload + * @param array $mockedMethods + * @param bool $cloneArguments + * + * @return PHPUnit_Framework_MockObject_MockObject + * + * @throws PHPUnit_Framework_MockObject_RuntimeException + * @throws PHPUnit_Framework_Exception + * + * @since Method available since Release 1.0.0 + */ + public function getMockForAbstractClass($originalClassName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = true) + { + if (!is_string($originalClassName)) { + throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); + } + + if (!is_string($mockClassName)) { + throw PHPUnit_Util_InvalidArgumentHelper::factory(3, 'string'); + } + + if (class_exists($originalClassName, $callAutoload) || + interface_exists($originalClassName, $callAutoload)) { + $reflector = new ReflectionClass($originalClassName); + $methods = $mockedMethods; + + foreach ($reflector->getMethods() as $method) { + if ($method->isAbstract() && !in_array($method->getName(), $methods)) { + $methods[] = $method->getName(); + } + } + + if (empty($methods)) { + $methods = null; + } + + return $this->getMock( + $originalClassName, + $methods, + $arguments, + $mockClassName, + $callOriginalConstructor, + $callOriginalClone, + $callAutoload, + $cloneArguments + ); + } else { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf('Class "%s" does not exist.', $originalClassName) + ); + } + } + + /** + * Returns a mock object for the specified trait with all abstract methods + * of the trait mocked. Concrete methods to mock can be specified with the + * `$mockedMethods` parameter. + * + * @param string $traitName + * @param array $arguments + * @param string $mockClassName + * @param bool $callOriginalConstructor + * @param bool $callOriginalClone + * @param bool $callAutoload + * @param array $mockedMethods + * @param bool $cloneArguments + * + * @return PHPUnit_Framework_MockObject_MockObject + * + * @throws PHPUnit_Framework_MockObject_RuntimeException + * @throws PHPUnit_Framework_Exception + * + * @since Method available since Release 1.2.3 + */ + public function getMockForTrait($traitName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = true) + { + if (!is_string($traitName)) { + throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); + } + + if (!is_string($mockClassName)) { + throw PHPUnit_Util_InvalidArgumentHelper::factory(3, 'string'); + } + + if (!trait_exists($traitName, $callAutoload)) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Trait "%s" does not exist.', + $traitName + ) + ); + } + + $className = $this->generateClassName( + $traitName, + '', + 'Trait_' + ); + + $templateDir = __DIR__ . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR; + $classTemplate = $this->getTemplate($templateDir . 'trait_class.tpl'); + + $classTemplate->setVar( + [ + 'prologue' => 'abstract ', + 'class_name' => $className['className'], + 'trait_name' => $traitName + ] + ); + + $this->evalClass( + $classTemplate->render(), + $className['className'] + ); + + return $this->getMockForAbstractClass($className['className'], $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $mockedMethods, $cloneArguments); + } + + /** + * Returns an object for the specified trait. + * + * @param string $traitName + * @param array $arguments + * @param string $traitClassName + * @param bool $callOriginalConstructor + * @param bool $callOriginalClone + * @param bool $callAutoload + * + * @return object + * + * @throws PHPUnit_Framework_MockObject_RuntimeException + * @throws PHPUnit_Framework_Exception + * + * @since Method available since Release 1.1.0 + */ + public function getObjectForTrait($traitName, array $arguments = [], $traitClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true) + { + if (!is_string($traitName)) { + throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); + } + + if (!is_string($traitClassName)) { + throw PHPUnit_Util_InvalidArgumentHelper::factory(3, 'string'); + } + + if (!trait_exists($traitName, $callAutoload)) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Trait "%s" does not exist.', + $traitName + ) + ); + } + + $className = $this->generateClassName( + $traitName, + $traitClassName, + 'Trait_' + ); + + $templateDir = __DIR__ . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR; + $classTemplate = $this->getTemplate($templateDir . 'trait_class.tpl'); + + $classTemplate->setVar( + [ + 'prologue' => '', + 'class_name' => $className['className'], + 'trait_name' => $traitName + ] + ); + + return $this->getObject( + $classTemplate->render(), + $className['className'] + ); + } + + /** + * @param array|string $type + * @param array $methods + * @param string $mockClassName + * @param bool $callOriginalClone + * @param bool $callAutoload + * @param bool $cloneArguments + * @param bool $callOriginalMethods + * + * @return array + */ + public function generate($type, array $methods = null, $mockClassName = '', $callOriginalClone = true, $callAutoload = true, $cloneArguments = true, $callOriginalMethods = false) + { + if (is_array($type)) { + sort($type); + } + + if ($mockClassName == '') { + $key = md5( + is_array($type) ? implode('_', $type) : $type . + serialize($methods) . + serialize($callOriginalClone) . + serialize($cloneArguments) . + serialize($callOriginalMethods) + ); + + if (isset(self::$cache[$key])) { + return self::$cache[$key]; + } + } + + $mock = $this->generateMock( + $type, + $methods, + $mockClassName, + $callOriginalClone, + $callAutoload, + $cloneArguments, + $callOriginalMethods + ); + + if (isset($key)) { + self::$cache[$key] = $mock; + } + + return $mock; + } + + /** + * @param string $wsdlFile + * @param string $className + * @param array $methods + * @param array $options + * + * @return string + * + * @throws PHPUnit_Framework_MockObject_RuntimeException + */ + public function generateClassFromWsdl($wsdlFile, $className, array $methods = [], array $options = []) + { + if (!extension_loaded('soap')) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + 'The SOAP extension is required to generate a mock object from WSDL.' + ); + } + + $options = array_merge($options, ['cache_wsdl' => WSDL_CACHE_NONE]); + $client = new SoapClient($wsdlFile, $options); + $_methods = array_unique($client->__getFunctions()); + unset($client); + + sort($_methods); + + $templateDir = __DIR__ . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR; + $methodTemplate = $this->getTemplate($templateDir . 'wsdl_method.tpl'); + $methodsBuffer = ''; + + foreach ($_methods as $method) { + $nameStart = strpos($method, ' ') + 1; + $nameEnd = strpos($method, '('); + $name = substr($method, $nameStart, $nameEnd - $nameStart); + + if (empty($methods) || in_array($name, $methods)) { + $args = explode( + ',', + substr( + $method, + $nameEnd + 1, + strpos($method, ')') - $nameEnd - 1 + ) + ); + $numArgs = count($args); + + for ($i = 0; $i < $numArgs; $i++) { + $args[$i] = substr($args[$i], strpos($args[$i], '$')); + } + + $methodTemplate->setVar( + [ + 'method_name' => $name, + 'arguments' => implode(', ', $args) + ] + ); + + $methodsBuffer .= $methodTemplate->render(); + } + } + + $optionsBuffer = 'array('; + + foreach ($options as $key => $value) { + $optionsBuffer .= $key . ' => ' . $value; + } + + $optionsBuffer .= ')'; + + $classTemplate = $this->getTemplate($templateDir . 'wsdl_class.tpl'); + $namespace = ''; + + if (strpos($className, '\\') !== false) { + $parts = explode('\\', $className); + $className = array_pop($parts); + $namespace = 'namespace ' . implode('\\', $parts) . ';' . "\n\n"; + } + + $classTemplate->setVar( + [ + 'namespace' => $namespace, + 'class_name' => $className, + 'wsdl' => $wsdlFile, + 'options' => $optionsBuffer, + 'methods' => $methodsBuffer + ] + ); + + return $classTemplate->render(); + } + + /** + * @param array|string $type + * @param array|null $methods + * @param string $mockClassName + * @param bool $callOriginalClone + * @param bool $callAutoload + * @param bool $cloneArguments + * @param bool $callOriginalMethods + * + * @return array + * + * @throws PHPUnit_Framework_MockObject_RuntimeException + */ + private function generateMock($type, $methods, $mockClassName, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods) + { + $methodReflections = []; + $templateDir = __DIR__ . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR; + $classTemplate = $this->getTemplate($templateDir . 'mocked_class.tpl'); + + $additionalInterfaces = []; + $cloneTemplate = ''; + $isClass = false; + $isInterface = false; + $isMultipleInterfaces = false; + + if (is_array($type)) { + foreach ($type as $_type) { + if (!interface_exists($_type, $callAutoload)) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Interface "%s" does not exist.', + $_type + ) + ); + } + + $isMultipleInterfaces = true; + + $additionalInterfaces[] = $_type; + $typeClass = new ReflectionClass($this->generateClassName( + $_type, + $mockClassName, + 'Mock_' + )['fullClassName'] + ); + + foreach ($this->getClassMethods($_type) as $method) { + if (in_array($method, $methods)) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Duplicate method "%s" not allowed.', + $method + ) + ); + } + + $methodReflections[$method] = $typeClass->getMethod($method); + $methods[] = $method; + } + } + } + + $mockClassName = $this->generateClassName( + $type, + $mockClassName, + 'Mock_' + ); + + if (class_exists($mockClassName['fullClassName'], $callAutoload)) { + $isClass = true; + } elseif (interface_exists($mockClassName['fullClassName'], $callAutoload)) { + $isInterface = true; + } + + if (!$isClass && !$isInterface) { + $prologue = 'class ' . $mockClassName['originalClassName'] . "\n{\n}\n\n"; + + if (!empty($mockClassName['namespaceName'])) { + $prologue = 'namespace ' . $mockClassName['namespaceName'] . + " {\n\n" . $prologue . "}\n\n" . + "namespace {\n\n"; + + $epilogue = "\n\n}"; + } + + $cloneTemplate = $this->getTemplate($templateDir . 'mocked_clone.tpl'); + } else { + $class = new ReflectionClass($mockClassName['fullClassName']); + + if ($class->isFinal()) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Class "%s" is declared "final" and cannot be mocked.', + $mockClassName['fullClassName'] + ) + ); + } + + if ($class->hasMethod('__clone')) { + $cloneMethod = $class->getMethod('__clone'); + + if (!$cloneMethod->isFinal()) { + if ($callOriginalClone && !$isInterface) { + $cloneTemplate = $this->getTemplate($templateDir . 'unmocked_clone.tpl'); + } else { + $cloneTemplate = $this->getTemplate($templateDir . 'mocked_clone.tpl'); + } + } + } else { + $cloneTemplate = $this->getTemplate($templateDir . 'mocked_clone.tpl'); + } + } + + if (is_object($cloneTemplate)) { + $cloneTemplate = $cloneTemplate->render(); + } + + if (is_array($methods) && empty($methods) && + ($isClass || $isInterface)) { + $methods = $this->getClassMethods($mockClassName['fullClassName']); + } + + if (!is_array($methods)) { + $methods = []; + } + + $mockedMethods = ''; + $configurable = []; + + foreach ($methods as $methodName) { + if ($methodName != '__construct' && $methodName != '__clone') { + $configurable[] = strtolower($methodName); + } + } + + if (isset($class)) { + // https://github.com/sebastianbergmann/phpunit-mock-objects/issues/103 + if ($isInterface && $class->implementsInterface('Traversable') && + !$class->implementsInterface('Iterator') && + !$class->implementsInterface('IteratorAggregate')) { + $additionalInterfaces[] = 'Iterator'; + $methods = array_merge($methods, $this->getClassMethods('Iterator')); + } + + foreach ($methods as $methodName) { + try { + $method = $class->getMethod($methodName); + + if ($this->canMockMethod($method)) { + $mockedMethods .= $this->generateMockedMethodDefinitionFromExisting( + $templateDir, + $method, + $cloneArguments, + $callOriginalMethods + ); + } + } catch (ReflectionException $e) { + $mockedMethods .= $this->generateMockedMethodDefinition( + $templateDir, + $mockClassName['fullClassName'], + $methodName, + $cloneArguments + ); + } + } + } elseif ($isMultipleInterfaces) { + foreach ($methods as $methodName) { + if ($this->canMockMethod($methodReflections[$methodName])) { + $mockedMethods .= $this->generateMockedMethodDefinitionFromExisting( + $templateDir, + $methodReflections[$methodName], + $cloneArguments, + $callOriginalMethods + ); + } + } + } else { + foreach ($methods as $methodName) { + $mockedMethods .= $this->generateMockedMethodDefinition( + $templateDir, + $mockClassName['fullClassName'], + $methodName, + $cloneArguments + ); + } + } + + $method = ''; + + if (!in_array('method', $methods) && (!isset($class) || !$class->hasMethod('method'))) { + $methodTemplate = $this->getTemplate($templateDir . 'mocked_class_method.tpl'); + + $method = $methodTemplate->render(); + } + + $classTemplate->setVar( + [ + 'prologue' => isset($prologue) ? $prologue : '', + 'epilogue' => isset($epilogue) ? $epilogue : '', + 'class_declaration' => $this->generateMockClassDeclaration( + $mockClassName, + $isInterface, + $additionalInterfaces + ), + 'clone' => $cloneTemplate, + 'mock_class_name' => $mockClassName['className'], + 'mocked_methods' => $mockedMethods, + 'method' => $method, + 'configurable' => '[' . implode(', ', array_map(function ($m) { return '\'' . $m . '\'';}, $configurable)) . ']' + ] + ); + + return [ + 'code' => $classTemplate->render(), + 'mockClassName' => $mockClassName['className'] + ]; + } + + /** + * @param array|string $type + * @param string $className + * @param string $prefix + * + * @return array + */ + private function generateClassName($type, $className, $prefix) + { + if (is_array($type)) { + $type = implode('_', $type); + } + + if ($type[0] == '\\') { + $type = substr($type, 1); + } + + $classNameParts = explode('\\', $type); + + if (count($classNameParts) > 1) { + $type = array_pop($classNameParts); + $namespaceName = implode('\\', $classNameParts); + $fullClassName = $namespaceName . '\\' . $type; + } else { + $namespaceName = ''; + $fullClassName = $type; + } + + if ($className == '') { + do { + $className = $prefix . $type . '_' . + substr(md5(mt_rand()), 0, 8); + } while (class_exists($className, false)); + } + + return [ + 'className' => $className, + 'originalClassName' => $type, + 'fullClassName' => $fullClassName, + 'namespaceName' => $namespaceName + ]; + } + + /** + * @param array $mockClassName + * @param bool $isInterface + * @param array $additionalInterfaces + * + * @return array + */ + private function generateMockClassDeclaration(array $mockClassName, $isInterface, array $additionalInterfaces = []) + { + $buffer = 'class '; + + $additionalInterfaces[] = 'PHPUnit_Framework_MockObject_MockObject'; + $interfaces = implode(', ', $additionalInterfaces); + + if ($isInterface) { + $buffer .= sprintf( + '%s implements %s', + $mockClassName['className'], + $interfaces + ); + + if (!in_array($mockClassName['originalClassName'], $additionalInterfaces)) { + $buffer .= ', '; + + if (!empty($mockClassName['namespaceName'])) { + $buffer .= $mockClassName['namespaceName'] . '\\'; + } + + $buffer .= $mockClassName['originalClassName']; + } + } else { + $buffer .= sprintf( + '%s extends %s%s implements %s', + $mockClassName['className'], + !empty($mockClassName['namespaceName']) ? $mockClassName['namespaceName'] . '\\' : '', + $mockClassName['originalClassName'], + $interfaces + ); + } + + return $buffer; + } + + /** + * @param string $templateDir + * @param ReflectionMethod $method + * @param bool $cloneArguments + * @param bool $callOriginalMethods + * + * @return string + */ + private function generateMockedMethodDefinitionFromExisting($templateDir, ReflectionMethod $method, $cloneArguments, $callOriginalMethods) + { + if ($method->isPrivate()) { + $modifier = 'private'; + } elseif ($method->isProtected()) { + $modifier = 'protected'; + } else { + $modifier = 'public'; + } + + if ($method->isStatic()) { + $modifier .= ' static'; + } + + if ($method->returnsReference()) { + $reference = '&'; + } else { + $reference = ''; + } + + if ($this->hasReturnType($method)) { + $returnType = (string) $method->getReturnType(); + } else { + $returnType = ''; + } + + if (preg_match('#\*[ \t]*+@deprecated[ \t]*+(.*?)\r?+\n[ \t]*+\*(?:[ \t]*+@|/$)#s', $method->getDocComment(), $deprecation)) { + $deprecation = trim(preg_replace('#[ \t]*\r?\n[ \t]*+\*[ \t]*+#', ' ', $deprecation[1])); + } else { + $deprecation = false; + } + + return $this->generateMockedMethodDefinition( + $templateDir, + $method->getDeclaringClass()->getName(), + $method->getName(), + $cloneArguments, + $modifier, + $this->getMethodParameters($method), + $this->getMethodParameters($method, true), + $returnType, + $reference, + $callOriginalMethods, + $method->isStatic(), + $deprecation, + $this->allowsReturnNull($method) + ); + } + + /** + * @param string $templateDir + * @param string $className + * @param string $methodName + * @param bool $cloneArguments + * @param string $modifier + * @param string $arguments_decl + * @param string $arguments_call + * @param string $return_type + * @param string $reference + * @param bool $callOriginalMethods + * @param bool $static + * @param string|false $deprecation + * @param bool $allowsReturnNull + * + * @return string + */ + private function generateMockedMethodDefinition($templateDir, $className, $methodName, $cloneArguments = true, $modifier = 'public', $arguments_decl = '', $arguments_call = '', $return_type = '', $reference = '', $callOriginalMethods = false, $static = false, $deprecation = false, $allowsReturnNull = false) + { + if ($static) { + $templateFile = 'mocked_static_method.tpl'; + } else { + if ($return_type === 'void') { + $templateFile = sprintf( + '%s_method_void.tpl', + $callOriginalMethods ? 'proxied' : 'mocked' + ); + } else { + $templateFile = sprintf( + '%s_method.tpl', + $callOriginalMethods ? 'proxied' : 'mocked' + ); + } + } + + // Mocked interfaces returning 'self' must explicitly declare the + // interface name as the return type. See + // https://bugs.php.net/bug.php?id=70722 + if ($return_type === 'self') { + $return_type = $className; + } + + if (false !== $deprecation) { + $deprecation = "The $className::$methodName method is deprecated ($deprecation)."; + $deprecationTemplate = $this->getTemplate($templateDir . 'deprecation.tpl'); + + $deprecationTemplate->setVar( + [ + 'deprecation' => var_export($deprecation, true), + ] + ); + + $deprecation = $deprecationTemplate->render(); + } + + $template = $this->getTemplate($templateDir . $templateFile); + + $template->setVar( + [ + 'arguments_decl' => $arguments_decl, + 'arguments_call' => $arguments_call, + 'return_delim' => $return_type ? ': ' : '', + 'return_type' => $allowsReturnNull ? '?' . $return_type : $return_type, + 'arguments_count' => !empty($arguments_call) ? count(explode(',', $arguments_call)) : 0, + 'class_name' => $className, + 'method_name' => $methodName, + 'modifier' => $modifier, + 'reference' => $reference, + 'clone_arguments' => $cloneArguments ? 'true' : 'false', + 'deprecation' => $deprecation + ] + ); + + return $template->render(); + } + + /** + * @param ReflectionMethod $method + * + * @return bool + */ + private function canMockMethod(ReflectionMethod $method) + { + if ($method->isConstructor() || + $method->isFinal() || + $method->isPrivate() || + $this->isMethodNameBlacklisted($method->getName())) { + return false; + } + + return true; + } + + /** + * Returns whether i method name is blacklisted + * + * Since PHP 7 the only names that are still reserved for method names are the ones that start with an underscore + * + * @param string $name + * + * @return bool + */ + private function isMethodNameBlacklisted($name) + { + if (PHP_MAJOR_VERSION < 7 && isset($this->legacyBlacklistedMethodNames[$name])) { + return true; + } + + if (PHP_MAJOR_VERSION >= 7 && isset($this->blacklistedMethodNames[$name])) { + return true; + } + + return false; + } + + /** + * Returns the parameters of a function or method. + * + * @param ReflectionMethod $method + * @param bool $forCall + * + * @return string + * + * @throws PHPUnit_Framework_MockObject_RuntimeException + * + * @since Method available since Release 2.0.0 + */ + private function getMethodParameters(ReflectionMethod $method, $forCall = false) + { + $parameters = []; + + foreach ($method->getParameters() as $i => $parameter) { + $name = '$' . $parameter->getName(); + + /* Note: PHP extensions may use empty names for reference arguments + * or "..." for methods taking a variable number of arguments. + */ + if ($name === '$' || $name === '$...') { + $name = '$arg' . $i; + } + + if ($this->isVariadic($parameter)) { + if ($forCall) { + continue; + } else { + $name = '...' . $name; + } + } + + $nullable = ''; + $default = ''; + $reference = ''; + $typeDeclaration = ''; + + if (!$forCall) { + if ($this->hasType($parameter) && (string) $parameter->getType() !== 'self') { + if (version_compare(PHP_VERSION, '7.1', '>=') && $parameter->allowsNull() && !$parameter->isVariadic()) { + $nullable = '?'; + } + + $typeDeclaration = (string) $parameter->getType() . ' '; + } elseif ($parameter->isArray()) { + $typeDeclaration = 'array '; + } elseif ($parameter->isCallable()) { + $typeDeclaration = 'callable '; + } else { + try { + $class = $parameter->getClass(); + } catch (ReflectionException $e) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'Cannot mock %s::%s() because a class or ' . + 'interface used in the signature is not loaded', + $method->getDeclaringClass()->getName(), + $method->getName() + ), + 0, + $e + ); + } + + if ($class !== null) { + $typeDeclaration = $class->getName() . ' '; + } + } + + if (!$this->isVariadic($parameter)) { + if ($parameter->isDefaultValueAvailable()) { + $value = $parameter->getDefaultValue(); + $default = ' = ' . var_export($value, true); + } elseif ($parameter->isOptional()) { + $default = ' = null'; + } + } + } + + if ($parameter->isPassedByReference()) { + $reference = '&'; + } + + $parameters[] = $nullable . $typeDeclaration . $reference . $name . $default; + } + + return implode(', ', $parameters); + } + + /** + * @param ReflectionParameter $parameter + * + * @return bool + * + * @since Method available since Release 2.2.1 + */ + private function isVariadic(ReflectionParameter $parameter) + { + return method_exists(ReflectionParameter::class, 'isVariadic') && $parameter->isVariadic(); + } + + /** + * @param ReflectionParameter $parameter + * + * @return bool + * + * @since Method available since Release 2.3.4 + */ + private function hasType(ReflectionParameter $parameter) + { + return method_exists(ReflectionParameter::class, 'hasType') && $parameter->hasType(); + } + + /** + * @param ReflectionMethod $method + * + * @return bool + */ + private function hasReturnType(ReflectionMethod $method) + { + return method_exists(ReflectionMethod::class, 'hasReturnType') && $method->hasReturnType(); + } + + /** + * @param ReflectionMethod $method + * + * @return bool + */ + private function allowsReturnNull(ReflectionMethod $method) + { + return method_exists(ReflectionMethod::class, 'getReturnType') + && method_exists(ReflectionType::class, 'allowsNull') + && $method->hasReturnType() + && $method->getReturnType()->allowsNull(); + } + + /** + * @param string $className + * + * @return array + * + * @since Method available since Release 2.3.2 + */ + public function getClassMethods($className) + { + $class = new ReflectionClass($className); + $methods = []; + + foreach ($class->getMethods() as $method) { + if ($method->isPublic() || $method->isAbstract()) { + $methods[] = $method->getName(); + } + } + + return $methods; + } + + /** + * @param string $filename + * + * @return Text_Template + * + * @since Method available since Release 3.2.4 + */ + private function getTemplate($filename) + { + if (!isset(self::$templates[$filename])) { + self::$templates[$filename] = new Text_Template($filename); + } + + return self::$templates[$filename]; + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/deprecation.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/deprecation.tpl.dist new file mode 100644 index 0000000..5bf06f5 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/deprecation.tpl.dist @@ -0,0 +1,2 @@ + + @trigger_error({deprecation}, E_USER_DEPRECATED); diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_class.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_class.tpl.dist new file mode 100644 index 0000000..30ec490 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_class.tpl.dist @@ -0,0 +1,40 @@ +{prologue}{class_declaration} +{ + private $__phpunit_invocationMocker; + private $__phpunit_originalObject; + private $__phpunit_configurable = {configurable}; + +{clone}{mocked_methods} + public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) + { + return $this->__phpunit_getInvocationMocker()->expects($matcher); + } +{method} + public function __phpunit_setOriginalObject($originalObject) + { + $this->__phpunit_originalObject = $originalObject; + } + + public function __phpunit_getInvocationMocker() + { + if ($this->__phpunit_invocationMocker === null) { + $this->__phpunit_invocationMocker = new PHPUnit_Framework_MockObject_InvocationMocker($this->__phpunit_configurable); + } + + return $this->__phpunit_invocationMocker; + } + + public function __phpunit_hasMatchers() + { + return $this->__phpunit_getInvocationMocker()->hasMatchers(); + } + + public function __phpunit_verify($unsetInvocationMocker = true) + { + $this->__phpunit_getInvocationMocker()->verify(); + + if ($unsetInvocationMocker) { + $this->__phpunit_invocationMocker = null; + } + } +}{epilogue} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_class_method.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_class_method.tpl.dist new file mode 100644 index 0000000..9e29c0d --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_class_method.tpl.dist @@ -0,0 +1,7 @@ + + public function method() + { + $any = new PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount; + $expects = $this->expects($any); + return call_user_func_array(array($expects, 'method'), func_get_args()); + } diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_clone.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_clone.tpl.dist new file mode 100644 index 0000000..bd846de --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_clone.tpl.dist @@ -0,0 +1,4 @@ + public function __clone() + { + $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); + } diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_method.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_method.tpl.dist new file mode 100644 index 0000000..c1e7a0d --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_method.tpl.dist @@ -0,0 +1,22 @@ + + {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} + {{deprecation} + $arguments = array({arguments_call}); + $count = func_num_args(); + + if ($count > {arguments_count}) { + $_arguments = func_get_args(); + + for ($i = {arguments_count}; $i < $count; $i++) { + $arguments[] = $_arguments[$i]; + } + } + + $result = $this->__phpunit_getInvocationMocker()->invoke( + new PHPUnit_Framework_MockObject_Invocation_Object( + '{class_name}', '{method_name}', $arguments, '{return_type}', $this, {clone_arguments} + ) + ); + + return $result; + } diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_method_void.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_method_void.tpl.dist new file mode 100644 index 0000000..03197aa --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_method_void.tpl.dist @@ -0,0 +1,20 @@ + + {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} + {{deprecation} + $arguments = array({arguments_call}); + $count = func_num_args(); + + if ($count > {arguments_count}) { + $_arguments = func_get_args(); + + for ($i = {arguments_count}; $i < $count; $i++) { + $arguments[] = $_arguments[$i]; + } + } + + $this->__phpunit_getInvocationMocker()->invoke( + new PHPUnit_Framework_MockObject_Invocation_Object( + '{class_name}', '{method_name}', $arguments, '{return_type}', $this, {clone_arguments} + ) + ); + } diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_static_method.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_static_method.tpl.dist new file mode 100644 index 0000000..45fa9bb --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/mocked_static_method.tpl.dist @@ -0,0 +1,5 @@ + + {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} + { + throw new PHPUnit_Framework_MockObject_BadMethodCallException('Static method "{method_name}" cannot be invoked on mock object'); + } diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/proxied_method.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/proxied_method.tpl.dist new file mode 100644 index 0000000..4b9cce8 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/proxied_method.tpl.dist @@ -0,0 +1,22 @@ + + {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} + { + $arguments = array({arguments_call}); + $count = func_num_args(); + + if ($count > {arguments_count}) { + $_arguments = func_get_args(); + + for ($i = {arguments_count}; $i < $count; $i++) { + $arguments[] = $_arguments[$i]; + } + } + + $this->__phpunit_getInvocationMocker()->invoke( + new PHPUnit_Framework_MockObject_Invocation_Object( + '{class_name}', '{method_name}', $arguments, '{return_type}', $this, {clone_arguments} + ) + ); + + return call_user_func_array(array($this->__phpunit_originalObject, "{method_name}"), $arguments); + } diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist new file mode 100644 index 0000000..e350436 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist @@ -0,0 +1,22 @@ + + {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} + { + $arguments = array({arguments_call}); + $count = func_num_args(); + + if ($count > {arguments_count}) { + $_arguments = func_get_args(); + + for ($i = {arguments_count}; $i < $count; $i++) { + $arguments[] = $_arguments[$i]; + } + } + + $this->__phpunit_getInvocationMocker()->invoke( + new PHPUnit_Framework_MockObject_Invocation_Object( + '{class_name}', '{method_name}', $arguments, '{return_type}', $this, {clone_arguments} + ) + ); + + call_user_func_array(array($this->__phpunit_originalObject, "{method_name}"), $arguments); + } diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/trait_class.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/trait_class.tpl.dist new file mode 100644 index 0000000..4143b0f --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/trait_class.tpl.dist @@ -0,0 +1,4 @@ +{prologue}class {class_name} +{ + use {trait_name}; +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/unmocked_clone.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/unmocked_clone.tpl.dist new file mode 100644 index 0000000..fa0e70a --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/unmocked_clone.tpl.dist @@ -0,0 +1,5 @@ + public function __clone() + { + $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); + parent::__clone(); + } diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/wsdl_class.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/wsdl_class.tpl.dist new file mode 100644 index 0000000..cc69fd3 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/wsdl_class.tpl.dist @@ -0,0 +1,7 @@ +{namespace}class {class_name} extends \SoapClient +{ + public function __construct($wsdl, array $options) + { + parent::__construct('{wsdl}', $options); + } +{methods}} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/wsdl_method.tpl.dist b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/wsdl_method.tpl.dist new file mode 100644 index 0000000..bb16e76 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator/wsdl_method.tpl.dist @@ -0,0 +1,4 @@ + + public function {method_name}({arguments}) + { + } diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation.php new file mode 100644 index 0000000..34da11a --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation.php @@ -0,0 +1,22 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Interface for invocations. + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Invocation +{ + /** + * @return mixed Mocked return value. + */ + public function generateReturnValue(); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation/Object.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation/Object.php new file mode 100644 index 0000000..3361966 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation/Object.php @@ -0,0 +1,37 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Represents a non-static invocation. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Invocation_Object extends PHPUnit_Framework_MockObject_Invocation_Static +{ + /** + * @var object + */ + public $object; + + /** + * @param string $className + * @param string $methodName + * @param array $parameters + * @param string $returnType + * @param object $object + * @param bool $cloneObjects + */ + public function __construct($className, $methodName, array $parameters, $returnType, $object, $cloneObjects = false) + { + parent::__construct($className, $methodName, $parameters, $returnType, $cloneObjects); + + $this->object = $object; + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation/Static.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation/Static.php new file mode 100644 index 0000000..d580002 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invocation/Static.php @@ -0,0 +1,207 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use SebastianBergmann\Exporter\Exporter; + +/** + * Represents a static invocation. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Invocation_Static implements PHPUnit_Framework_MockObject_Invocation, PHPUnit_Framework_SelfDescribing +{ + /** + * @var array + */ + protected static $uncloneableExtensions = [ + 'mysqli' => true, + 'SQLite' => true, + 'sqlite3' => true, + 'tidy' => true, + 'xmlwriter' => true, + 'xsl' => true + ]; + + /** + * @var array + */ + protected static $uncloneableClasses = [ + 'Closure', + 'COMPersistHelper', + 'IteratorIterator', + 'RecursiveIteratorIterator', + 'SplFileObject', + 'PDORow', + 'ZipArchive' + ]; + + /** + * @var string + */ + public $className; + + /** + * @var string + */ + public $methodName; + + /** + * @var array + */ + public $parameters; + + /** + * @var string + */ + public $returnType; + + /** + * @var bool + */ + public $returnTypeNullable = false; + + /** + * @param string $className + * @param string $methodName + * @param array $parameters + * @param string $returnType + * @param bool $cloneObjects + */ + public function __construct($className, $methodName, array $parameters, $returnType, $cloneObjects = false) + { + $this->className = $className; + $this->methodName = $methodName; + $this->parameters = $parameters; + + if (strpos($returnType, '?') === 0) { + $returnType = substr($returnType, 1); + $this->returnTypeNullable = true; + } + + $this->returnType = $returnType; + + if (!$cloneObjects) { + return; + } + + foreach ($this->parameters as $key => $value) { + if (is_object($value)) { + $this->parameters[$key] = $this->cloneObject($value); + } + } + } + + /** + * @return string + */ + public function toString() + { + $exporter = new Exporter; + + return sprintf( + '%s::%s(%s)%s', + $this->className, + $this->methodName, + implode( + ', ', + array_map( + [$exporter, 'shortenedExport'], + $this->parameters + ) + ), + $this->returnType ? sprintf(': %s', $this->returnType) : '' + ); + } + + /** + * @return mixed Mocked return value. + */ + public function generateReturnValue() + { + switch ($this->returnType) { + case '': return; + case 'string': return $this->returnTypeNullable ? null : ''; + case 'float': return $this->returnTypeNullable ? null : 0.0; + case 'int': return $this->returnTypeNullable ? null : 0; + case 'bool': return $this->returnTypeNullable ? null : false; + case 'array': return $this->returnTypeNullable ? null : []; + case 'void': return; + + case 'callable': + case 'Closure': + return function () {}; + + case 'Traversable': + case 'Generator': + $generator = function () { yield; }; + + return $generator(); + + default: + if ($this->returnTypeNullable) { + return null; + } + + $generator = new PHPUnit_Framework_MockObject_Generator; + + return $generator->getMock($this->returnType, [], [], '', false); + } + } + + /** + * @param object $original + * + * @return object + */ + protected function cloneObject($original) + { + $cloneable = null; + $object = new ReflectionObject($original); + + // Check the blacklist before asking PHP reflection to work around + // https://bugs.php.net/bug.php?id=53967 + if ($object->isInternal() && + isset(self::$uncloneableExtensions[$object->getExtensionName()])) { + $cloneable = false; + } + + if ($cloneable === null) { + foreach (self::$uncloneableClasses as $class) { + if ($original instanceof $class) { + $cloneable = false; + break; + } + } + } + + if ($cloneable === null && method_exists($object, 'isCloneable')) { + $cloneable = $object->isCloneable(); + } + + if ($cloneable === null && $object->hasMethod('__clone')) { + $method = $object->getMethod('__clone'); + $cloneable = $method->isPublic(); + } + + if ($cloneable === null) { + $cloneable = true; + } + + if ($cloneable) { + try { + return clone $original; + } catch (Exception $e) { + return $original; + } + } else { + return $original; + } + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/InvocationMocker.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/InvocationMocker.php new file mode 100644 index 0000000..88e5330 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/InvocationMocker.php @@ -0,0 +1,178 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Mocker for invocations which are sent from + * PHPUnit_Framework_MockObject_MockObject objects. + * + * Keeps track of all expectations and stubs as well as registering + * identifications for builders. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_InvocationMocker implements PHPUnit_Framework_MockObject_Stub_MatcherCollection, PHPUnit_Framework_MockObject_Invokable, PHPUnit_Framework_MockObject_Builder_Namespace +{ + /** + * @var PHPUnit_Framework_MockObject_Matcher_Invocation[] + */ + protected $matchers = []; + + /** + * @var PHPUnit_Framework_MockObject_Builder_Match[] + */ + protected $builderMap = []; + + /** + * @var string[] + */ + private $configurableMethods = []; + + /** + * @param array $configurableMethods + */ + public function __construct(array $configurableMethods) + { + $this->configurableMethods = $configurableMethods; + } + + /** + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher + */ + public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) + { + $this->matchers[] = $matcher; + } + + /** + * @since Method available since Release 1.1.0 + */ + public function hasMatchers() + { + foreach ($this->matchers as $matcher) { + if ($matcher->hasMatchers()) { + return true; + } + } + + return false; + } + + /** + * @param mixed $id + * + * @return bool|null + */ + public function lookupId($id) + { + if (isset($this->builderMap[$id])) { + return $this->builderMap[$id]; + } + + return; + } + + /** + * @param mixed $id + * @param PHPUnit_Framework_MockObject_Builder_Match $builder + * + * @throws PHPUnit_Framework_MockObject_RuntimeException + */ + public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder) + { + if (isset($this->builderMap[$id])) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + 'Match builder with id <' . $id . '> is already registered.' + ); + } + + $this->builderMap[$id] = $builder; + } + + /** + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) + { + return new PHPUnit_Framework_MockObject_Builder_InvocationMocker( + $this, + $matcher, + $this->configurableMethods + ); + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * + * @return mixed + * + * @throws Exception + */ + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $exception = null; + $hasReturnValue = false; + $returnValue = null; + + foreach ($this->matchers as $match) { + try { + if ($match->matches($invocation)) { + $value = $match->invoked($invocation); + + if (!$hasReturnValue) { + $returnValue = $value; + $hasReturnValue = true; + } + } + } catch (Exception $e) { + $exception = $e; + } + } + + if ($exception !== null) { + throw $exception; + } + + if ($hasReturnValue) { + return $returnValue; + } elseif (strtolower($invocation->methodName) == '__tostring') { + return ''; + } + + return $invocation->generateReturnValue(); + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * + * @return bool + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + foreach ($this->matchers as $matcher) { + if (!$matcher->matches($invocation)) { + return false; + } + } + + return true; + } + + /** + * @return bool + */ + public function verify() + { + foreach ($this->matchers as $matcher) { + $matcher->verify(); + } + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invokable.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invokable.php new file mode 100644 index 0000000..6f5ffda --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Invokable.php @@ -0,0 +1,39 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Interface for classes which can be invoked. + * + * The invocation will be taken from a mock object and passed to an object + * of this class. + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Invokable extends PHPUnit_Framework_MockObject_Verifiable +{ + /** + * Invokes the invocation object $invocation so that it can be checked for + * expectations or matched against stubs. + * + * @param PHPUnit_Framework_MockObject_Invocation $invocation The invocation object passed from mock object + * + * @return object + */ + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation); + + /** + * Checks if the invocation matches. + * + * @param PHPUnit_Framework_MockObject_Invocation $invocation The invocation object passed from mock object + * + * @return bool + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher.php new file mode 100644 index 0000000..ff57bf9 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher.php @@ -0,0 +1,274 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Main matcher which defines a full expectation using method, parameter and + * invocation matchers. + * This matcher encapsulates all the other matchers and allows the builder to + * set the specific matchers when the appropriate methods are called (once(), + * where() etc.). + * + * All properties are public so that they can easily be accessed by the builder. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Matcher implements PHPUnit_Framework_MockObject_Matcher_Invocation +{ + /** + * @var PHPUnit_Framework_MockObject_Matcher_Invocation + */ + public $invocationMatcher; + + /** + * @var mixed + */ + public $afterMatchBuilderId = null; + + /** + * @var bool + */ + public $afterMatchBuilderIsInvoked = false; + + /** + * @var PHPUnit_Framework_MockObject_Matcher_MethodName + */ + public $methodNameMatcher = null; + + /** + * @var PHPUnit_Framework_MockObject_Matcher_Parameters + */ + public $parametersMatcher = null; + + /** + * @var PHPUnit_Framework_MockObject_Stub + */ + public $stub = null; + + /** + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher + */ + public function __construct(PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher) + { + $this->invocationMatcher = $invocationMatcher; + } + + /** + * @return string + */ + public function toString() + { + $list = []; + + if ($this->invocationMatcher !== null) { + $list[] = $this->invocationMatcher->toString(); + } + + if ($this->methodNameMatcher !== null) { + $list[] = 'where ' . $this->methodNameMatcher->toString(); + } + + if ($this->parametersMatcher !== null) { + $list[] = 'and ' . $this->parametersMatcher->toString(); + } + + if ($this->afterMatchBuilderId !== null) { + $list[] = 'after ' . $this->afterMatchBuilderId; + } + + if ($this->stub !== null) { + $list[] = 'will ' . $this->stub->toString(); + } + + return implode(' ', $list); + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * + * @return mixed + */ + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) + { + if ($this->invocationMatcher === null) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + 'No invocation matcher is set' + ); + } + + if ($this->methodNameMatcher === null) { + throw new PHPUnit_Framework_MockObject_RuntimeException('No method matcher is set'); + } + + if ($this->afterMatchBuilderId !== null) { + $builder = $invocation->object + ->__phpunit_getInvocationMocker() + ->lookupId($this->afterMatchBuilderId); + + if (!$builder) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'No builder found for match builder identification <%s>', + $this->afterMatchBuilderId + ) + ); + } + + $matcher = $builder->getMatcher(); + + if ($matcher && $matcher->invocationMatcher->hasBeenInvoked()) { + $this->afterMatchBuilderIsInvoked = true; + } + } + + $this->invocationMatcher->invoked($invocation); + + try { + if ($this->parametersMatcher !== null && + !$this->parametersMatcher->matches($invocation)) { + $this->parametersMatcher->verify(); + } + } catch (PHPUnit_Framework_ExpectationFailedException $e) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + "Expectation failed for %s when %s\n%s", + $this->methodNameMatcher->toString(), + $this->invocationMatcher->toString(), + $e->getMessage() + ), + $e->getComparisonFailure() + ); + } + + if ($this->stub) { + return $this->stub->invoke($invocation); + } + + return $invocation->generateReturnValue(); + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * + * @return bool + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + if ($this->afterMatchBuilderId !== null) { + $builder = $invocation->object + ->__phpunit_getInvocationMocker() + ->lookupId($this->afterMatchBuilderId); + + if (!$builder) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + sprintf( + 'No builder found for match builder identification <%s>', + $this->afterMatchBuilderId + ) + ); + } + + $matcher = $builder->getMatcher(); + + if (!$matcher) { + return false; + } + + if (!$matcher->invocationMatcher->hasBeenInvoked()) { + return false; + } + } + + if ($this->invocationMatcher === null) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + 'No invocation matcher is set' + ); + } + + if ($this->methodNameMatcher === null) { + throw new PHPUnit_Framework_MockObject_RuntimeException('No method matcher is set'); + } + + if (!$this->invocationMatcher->matches($invocation)) { + return false; + } + + try { + if (!$this->methodNameMatcher->matches($invocation)) { + return false; + } + } catch (PHPUnit_Framework_ExpectationFailedException $e) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + "Expectation failed for %s when %s\n%s", + $this->methodNameMatcher->toString(), + $this->invocationMatcher->toString(), + $e->getMessage() + ), + $e->getComparisonFailure() + ); + } + + return true; + } + + /** + * @throws PHPUnit_Framework_MockObject_RuntimeException + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function verify() + { + if ($this->invocationMatcher === null) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + 'No invocation matcher is set' + ); + } + + if ($this->methodNameMatcher === null) { + throw new PHPUnit_Framework_MockObject_RuntimeException('No method matcher is set'); + } + + try { + $this->invocationMatcher->verify(); + + if ($this->parametersMatcher === null) { + $this->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters; + } + + $invocationIsAny = $this->invocationMatcher instanceof PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount; + $invocationIsNever = $this->invocationMatcher instanceof PHPUnit_Framework_MockObject_Matcher_InvokedCount && $this->invocationMatcher->isNever(); + + if (!$invocationIsAny && !$invocationIsNever) { + $this->parametersMatcher->verify(); + } + } catch (PHPUnit_Framework_ExpectationFailedException $e) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + "Expectation failed for %s when %s.\n%s", + $this->methodNameMatcher->toString(), + $this->invocationMatcher->toString(), + PHPUnit_Framework_TestFailure::exceptionToString($e) + ) + ); + } + } + + /** + * @since Method available since Release 1.2.4 + */ + public function hasMatchers() + { + if ($this->invocationMatcher !== null && + !$this->invocationMatcher instanceof PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount) { + return true; + } + + return false; + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/AnyInvokedCount.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/AnyInvokedCount.php new file mode 100644 index 0000000..480f1fd --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/AnyInvokedCount.php @@ -0,0 +1,32 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Invocation matcher which checks if a method has been invoked zero or more + * times. This matcher will always match. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder +{ + /** + * @return string + */ + public function toString() + { + return 'invoked zero or more times'; + } + + /** + */ + public function verify() + { + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/AnyParameters.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/AnyParameters.php new file mode 100644 index 0000000..02de976 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/AnyParameters.php @@ -0,0 +1,35 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Invocation matcher which allows any parameters to a method. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Matcher_AnyParameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation +{ + /** + * @return string + */ + public function toString() + { + return 'with any parameters'; + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * + * @return bool + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + return true; + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/ConsecutiveParameters.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/ConsecutiveParameters.php new file mode 100644 index 0000000..553498e --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/ConsecutiveParameters.php @@ -0,0 +1,126 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Invocation matcher which looks for sets of specific parameters in the invocations. + * + * Checks the parameters of the incoming invocations, the parameter list is + * checked against the defined constraints in $parameters. If the constraint + * is met it will return true in matches(). + * + * It takes a list of match groups and and increases a call index after each invocation. + * So the first invocation uses the first group of constraints, the second the next and so on. + */ +class PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation +{ + /** + * @var array + */ + private $parameterGroups = []; + + /** + * @var array + */ + private $invocations = []; + + /** + * @param array $parameterGroups + */ + public function __construct(array $parameterGroups) + { + foreach ($parameterGroups as $index => $parameters) { + foreach ($parameters as $parameter) { + if (!$parameter instanceof PHPUnit_Framework_Constraint) { + $parameter = new PHPUnit_Framework_Constraint_IsEqual($parameter); + } + + $this->parameterGroups[$index][] = $parameter; + } + } + } + + /** + * @return string + */ + public function toString() + { + $text = 'with consecutive parameters'; + + return $text; + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * + * @return bool + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $this->invocations[] = $invocation; + $callIndex = count($this->invocations) - 1; + + $this->verifyInvocation($invocation, $callIndex); + + return false; + } + + public function verify() + { + foreach ($this->invocations as $callIndex => $invocation) { + $this->verifyInvocation($invocation, $callIndex); + } + } + + /** + * Verify a single invocation + * + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * @param int $callIndex + * + * @throws PHPUnit_Framework_ExpectationFailedException + */ + private function verifyInvocation(PHPUnit_Framework_MockObject_Invocation $invocation, $callIndex) + { + if (isset($this->parameterGroups[$callIndex])) { + $parameters = $this->parameterGroups[$callIndex]; + } else { + // no parameter assertion for this call index + return; + } + + if ($invocation === null) { + throw new PHPUnit_Framework_ExpectationFailedException( + 'Mocked method does not exist.' + ); + } + + if (count($invocation->parameters) < count($parameters)) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + 'Parameter count for invocation %s is too low.', + $invocation->toString() + ) + ); + } + + foreach ($parameters as $i => $parameter) { + $parameter->evaluate( + $invocation->parameters[$i], + sprintf( + 'Parameter %s for invocation #%d %s does not match expected ' . + 'value.', + $i, + $callIndex, + $invocation->toString() + ) + ); + } + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/Invocation.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/Invocation.php new file mode 100644 index 0000000..befaa9c --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/Invocation.php @@ -0,0 +1,46 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Interface for classes which matches an invocation based on its + * method name, argument, order or call count. + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Matcher_Invocation extends PHPUnit_Framework_SelfDescribing, PHPUnit_Framework_MockObject_Verifiable +{ + /** + * Registers the invocation $invocation in the object as being invoked. + * This will only occur after matches() returns true which means the + * current invocation is the correct one. + * + * The matcher can store information from the invocation which can later + * be checked in verify(), or it can check the values directly and throw + * and exception if an expectation is not met. + * + * If the matcher is a stub it will also have a return value. + * + * @param PHPUnit_Framework_MockObject_Invocation $invocation Object containing information on a mocked or stubbed method which was invoked + * + * @return mixed + */ + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation); + + /** + * Checks if the invocation $invocation matches the current rules. If it does + * the matcher will get the invoked() method called which should check if an + * expectation is met. + * + * @param PHPUnit_Framework_MockObject_Invocation $invocation Object containing information on a mocked or stubbed method which was invoked + * + * @return bool + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtIndex.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtIndex.php new file mode 100644 index 0000000..9301543 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtIndex.php @@ -0,0 +1,87 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Invocation matcher which checks if a method was invoked at a certain index. + * + * If the expected index number does not match the current invocation index it + * will not match which means it skips all method and parameter matching. Only + * once the index is reached will the method and parameter start matching and + * verifying. + * + * If the index is never reached it will throw an exception in index. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Matcher_InvokedAtIndex implements PHPUnit_Framework_MockObject_Matcher_Invocation +{ + /** + * @var int + */ + protected $sequenceIndex; + + /** + * @var int + */ + protected $currentIndex = -1; + + /** + * @param int $sequenceIndex + */ + public function __construct($sequenceIndex) + { + $this->sequenceIndex = $sequenceIndex; + } + + /** + * @return string + */ + public function toString() + { + return 'invoked at sequence index ' . $this->sequenceIndex; + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * + * @return bool + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $this->currentIndex++; + + return $this->currentIndex == $this->sequenceIndex; + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + */ + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) + { + } + + /** + * Verifies that the current expectation is valid. If everything is OK the + * code should just return, if not it must throw an exception. + * + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function verify() + { + if ($this->currentIndex < $this->sequenceIndex) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + 'The expected invocation at index %s was never reached.', + $this->sequenceIndex + ) + ); + } + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtLeastCount.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtLeastCount.php new file mode 100644 index 0000000..dc5e804 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtLeastCount.php @@ -0,0 +1,57 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Invocation matcher which checks if a method has been invoked at least + * N times. + * + * @since Class available since Release 2.2.0 + */ +class PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder +{ + /** + * @var int + */ + private $requiredInvocations; + + /** + * @param int $requiredInvocations + */ + public function __construct($requiredInvocations) + { + $this->requiredInvocations = $requiredInvocations; + } + + /** + * @return string + */ + public function toString() + { + return 'invoked at least ' . $this->requiredInvocations . ' times'; + } + + /** + * Verifies that the current expectation is valid. If everything is OK the + * code should just return, if not it must throw an exception. + * + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function verify() + { + $count = $this->getInvocationCount(); + + if ($count < $this->requiredInvocations) { + throw new PHPUnit_Framework_ExpectationFailedException( + 'Expected invocation at least ' . $this->requiredInvocations . + ' times but it occurred ' . $count . ' time(s).' + ); + } + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtLeastOnce.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtLeastOnce.php new file mode 100644 index 0000000..006e908 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtLeastOnce.php @@ -0,0 +1,45 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Invocation matcher which checks if a method has been invoked at least one + * time. + * + * If the number of invocations is 0 it will throw an exception in verify. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder +{ + /** + * @return string + */ + public function toString() + { + return 'invoked at least once'; + } + + /** + * Verifies that the current expectation is valid. If everything is OK the + * code should just return, if not it must throw an exception. + * + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function verify() + { + $count = $this->getInvocationCount(); + + if ($count < 1) { + throw new PHPUnit_Framework_ExpectationFailedException( + 'Expected invocation at least once but it never occurred.' + ); + } + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtMostCount.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtMostCount.php new file mode 100644 index 0000000..592af93 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedAtMostCount.php @@ -0,0 +1,57 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Invocation matcher which checks if a method has been invoked at least + * N times. + * + * @since Class available since Release 2.2.0 + */ +class PHPUnit_Framework_MockObject_Matcher_InvokedAtMostCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder +{ + /** + * @var int + */ + private $allowedInvocations; + + /** + * @param int $allowedInvocations + */ + public function __construct($allowedInvocations) + { + $this->allowedInvocations = $allowedInvocations; + } + + /** + * @return string + */ + public function toString() + { + return 'invoked at most ' . $this->allowedInvocations . ' times'; + } + + /** + * Verifies that the current expectation is valid. If everything is OK the + * code should just return, if not it must throw an exception. + * + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function verify() + { + $count = $this->getInvocationCount(); + + if ($count > $this->allowedInvocations) { + throw new PHPUnit_Framework_ExpectationFailedException( + 'Expected invocation at most ' . $this->allowedInvocations . + ' times but it occurred ' . $count . ' time(s).' + ); + } + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedCount.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedCount.php new file mode 100644 index 0000000..fc5b15b --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedCount.php @@ -0,0 +1,110 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Invocation matcher which checks if a method has been invoked a certain amount + * of times. + * If the number of invocations exceeds the value it will immediately throw an + * exception, + * If the number is less it will later be checked in verify() and also throw an + * exception. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Matcher_InvokedCount extends PHPUnit_Framework_MockObject_Matcher_InvokedRecorder +{ + /** + * @var int + */ + protected $expectedCount; + + /** + * @param int $expectedCount + */ + public function __construct($expectedCount) + { + $this->expectedCount = $expectedCount; + } + + /** + * @return bool + */ + public function isNever() + { + return $this->expectedCount == 0; + } + + /** + * @return string + */ + public function toString() + { + return 'invoked ' . $this->expectedCount . ' time(s)'; + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) + { + parent::invoked($invocation); + + $count = $this->getInvocationCount(); + + if ($count > $this->expectedCount) { + $message = $invocation->toString() . ' '; + + switch ($this->expectedCount) { + case 0: { + $message .= 'was not expected to be called.'; + } + break; + + case 1: { + $message .= 'was not expected to be called more than once.'; + } + break; + + default: { + $message .= sprintf( + 'was not expected to be called more than %d times.', + $this->expectedCount + ); + } + } + + throw new PHPUnit_Framework_ExpectationFailedException($message); + } + } + + /** + * Verifies that the current expectation is valid. If everything is OK the + * code should just return, if not it must throw an exception. + * + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function verify() + { + $count = $this->getInvocationCount(); + + if ($count !== $this->expectedCount) { + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf( + 'Method was expected to be called %d times, ' . + 'actually called %d times.', + $this->expectedCount, + $count + ) + ); + } + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedRecorder.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedRecorder.php new file mode 100644 index 0000000..7762d7e --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/InvokedRecorder.php @@ -0,0 +1,68 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Records invocations and provides convenience methods for checking them later + * on. + * This abstract class can be implemented by matchers which needs to check the + * number of times an invocation has occurred. + * + * @since Class available since Release 1.0.0 + * @abstract + */ +abstract class PHPUnit_Framework_MockObject_Matcher_InvokedRecorder implements PHPUnit_Framework_MockObject_Matcher_Invocation +{ + /** + * @var PHPUnit_Framework_MockObject_Invocation[] + */ + protected $invocations = []; + + /** + * @return int + */ + public function getInvocationCount() + { + return count($this->invocations); + } + + /** + * @return PHPUnit_Framework_MockObject_Invocation[] + */ + public function getInvocations() + { + return $this->invocations; + } + + /** + * @return bool + */ + public function hasBeenInvoked() + { + return count($this->invocations) > 0; + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + */ + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $this->invocations[] = $invocation; + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * + * @return bool + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + return true; + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/MethodName.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/MethodName.php new file mode 100644 index 0000000..ff44c84 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/MethodName.php @@ -0,0 +1,68 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Invocation matcher which looks for a specific method name in the invocations. + * + * Checks the method name all incoming invocations, the name is checked against + * the defined constraint $constraint. If the constraint is met it will return + * true in matches(). + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Matcher_MethodName extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation +{ + /** + * @var PHPUnit_Framework_Constraint + */ + protected $constraint; + + /** + * @param PHPUnit_Framework_Constraint|string + * + * @throws PHPUnit_Framework_Constraint + */ + public function __construct($constraint) + { + if (!$constraint instanceof PHPUnit_Framework_Constraint) { + if (!is_string($constraint)) { + throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string'); + } + + $constraint = new PHPUnit_Framework_Constraint_IsEqual( + $constraint, + 0, + 10, + false, + true + ); + } + + $this->constraint = $constraint; + } + + /** + * @return string + */ + public function toString() + { + return 'method name ' . $this->constraint->toString(); + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * + * @return bool + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + return $this->constraint->evaluate($invocation->methodName, '', true); + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/Parameters.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/Parameters.php new file mode 100644 index 0000000..9cd50fc --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/Parameters.php @@ -0,0 +1,158 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Invocation matcher which looks for specific parameters in the invocations. + * + * Checks the parameters of all incoming invocations, the parameter list is + * checked against the defined constraints in $parameters. If the constraint + * is met it will return true in matches(). + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Matcher_Parameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation +{ + /** + * @var PHPUnit_Framework_Constraint[] + */ + protected $parameters = []; + + /** + * @var PHPUnit_Framework_MockObject_Invocation + */ + protected $invocation; + + /** + * @var PHPUnit_Framework_ExpectationFailedException + */ + private $parameterVerificationResult; + + /** + * @param array $parameters + */ + public function __construct(array $parameters) + { + foreach ($parameters as $parameter) { + if (!($parameter instanceof PHPUnit_Framework_Constraint)) { + $parameter = new PHPUnit_Framework_Constraint_IsEqual( + $parameter + ); + } + + $this->parameters[] = $parameter; + } + } + + /** + * @return string + */ + public function toString() + { + $text = 'with parameter'; + + foreach ($this->parameters as $index => $parameter) { + if ($index > 0) { + $text .= ' and'; + } + + $text .= ' ' . $index . ' ' . $parameter->toString(); + } + + return $text; + } + + /** + * @param PHPUnit_Framework_MockObject_Invocation $invocation + * + * @return bool + */ + public function matches(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $this->invocation = $invocation; + $this->parameterVerificationResult = null; + + try { + $this->parameterVerificationResult = $this->verify(); + + return $this->parameterVerificationResult; + } catch (PHPUnit_Framework_ExpectationFailedException $e) { + $this->parameterVerificationResult = $e; + + throw $this->parameterVerificationResult; + } + } + + /** + * Checks if the invocation $invocation matches the current rules. If it + * does the matcher will get the invoked() method called which should check + * if an expectation is met. + * + * @return bool + * + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function verify() + { + if (isset($this->parameterVerificationResult)) { + return $this->guardAgainstDuplicateEvaluationOfParameterConstraints(); + } + + if ($this->invocation === null) { + throw new PHPUnit_Framework_ExpectationFailedException( + 'Mocked method does not exist.' + ); + } + + if (count($this->invocation->parameters) < count($this->parameters)) { + $message = 'Parameter count for invocation %s is too low.'; + + // The user called `->with($this->anything())`, but may have meant + // `->withAnyParameters()`. + // + // @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/199 + if (count($this->parameters) === 1 && + get_class($this->parameters[0]) === 'PHPUnit_Framework_Constraint_IsAnything') { + $message .= "\nTo allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead."; + } + + throw new PHPUnit_Framework_ExpectationFailedException( + sprintf($message, $this->invocation->toString()) + ); + } + + foreach ($this->parameters as $i => $parameter) { + $parameter->evaluate( + $this->invocation->parameters[$i], + sprintf( + 'Parameter %s for invocation %s does not match expected ' . + 'value.', + $i, + $this->invocation->toString() + ) + ); + } + + return true; + } + + /** + * @return bool + * + * @throws PHPUnit_Framework_ExpectationFailedException + */ + private function guardAgainstDuplicateEvaluationOfParameterConstraints() + { + if ($this->parameterVerificationResult instanceof Exception) { + throw $this->parameterVerificationResult; + } + + return (bool) $this->parameterVerificationResult; + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/StatelessInvocation.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/StatelessInvocation.php new file mode 100644 index 0000000..33f3af0 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Matcher/StatelessInvocation.php @@ -0,0 +1,54 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Invocation matcher which does not care about previous state from earlier + * invocations. + * + * This abstract class can be implemented by matchers which does not care about + * state but only the current run-time value of the invocation itself. + * + * @since Class available since Release 1.0.0 + * @abstract + */ +abstract class PHPUnit_Framework_MockObject_Matcher_StatelessInvocation implements PHPUnit_Framework_MockObject_Matcher_Invocation +{ + /** + * Registers the invocation $invocation in the object as being invoked. + * This will only occur after matches() returns true which means the + * current invocation is the correct one. + * + * The matcher can store information from the invocation which can later + * be checked in verify(), or it can check the values directly and throw + * and exception if an expectation is not met. + * + * If the matcher is a stub it will also have a return value. + * + * @param PHPUnit_Framework_MockObject_Invocation $invocation Object containing information on a mocked or stubbed method which was invoked + * + * @return mixed + */ + public function invoked(PHPUnit_Framework_MockObject_Invocation $invocation) + { + } + + /** + * Checks if the invocation $invocation matches the current rules. If it does + * the matcher will get the invoked() method called which should check if an + * expectation is met. + * + * @param PHPUnit_Framework_MockObject_Invocation $invocation Object containing information on a mocked or stubbed method which was invoked + * + * @return bool + */ + public function verify() + { + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/MockBuilder.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/MockBuilder.php new file mode 100644 index 0000000..ea6804a --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/MockBuilder.php @@ -0,0 +1,408 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Implementation of the Builder pattern for Mock objects. + * + * @since File available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_MockBuilder +{ + /** + * @var PHPUnit_Framework_TestCase + */ + private $testCase; + + /** + * @var string + */ + private $type; + + /** + * @var array + */ + private $methods = []; + + /** + * @var array + */ + private $methodsExcept = []; + + /** + * @var string + */ + private $mockClassName = ''; + + /** + * @var array + */ + private $constructorArgs = []; + + /** + * @var bool + */ + private $originalConstructor = true; + + /** + * @var bool + */ + private $originalClone = true; + + /** + * @var bool + */ + private $autoload = true; + + /** + * @var bool + */ + private $cloneArguments = false; + + /** + * @var bool + */ + private $callOriginalMethods = false; + + /** + * @var object + */ + private $proxyTarget = null; + + /** + * @var bool + */ + private $allowMockingUnknownTypes = true; + + /** + * @var PHPUnit_Framework_MockObject_Generator + */ + private $generator; + + /** + * @param PHPUnit_Framework_TestCase $testCase + * @param array|string $type + */ + public function __construct(PHPUnit_Framework_TestCase $testCase, $type) + { + $this->testCase = $testCase; + $this->type = $type; + $this->generator = new PHPUnit_Framework_MockObject_Generator; + } + + /** + * Creates a mock object using a fluent interface. + * + * @return PHPUnit_Framework_MockObject_MockObject + */ + public function getMock() + { + $object = $this->generator->getMock( + $this->type, + $this->methods, + $this->constructorArgs, + $this->mockClassName, + $this->originalConstructor, + $this->originalClone, + $this->autoload, + $this->cloneArguments, + $this->callOriginalMethods, + $this->proxyTarget, + $this->allowMockingUnknownTypes + ); + + $this->testCase->registerMockObject($object); + + return $object; + } + + /** + * Creates a mock object for an abstract class using a fluent interface. + * + * @return PHPUnit_Framework_MockObject_MockObject + */ + public function getMockForAbstractClass() + { + $object = $this->generator->getMockForAbstractClass( + $this->type, + $this->constructorArgs, + $this->mockClassName, + $this->originalConstructor, + $this->originalClone, + $this->autoload, + $this->methods, + $this->cloneArguments + ); + + $this->testCase->registerMockObject($object); + + return $object; + } + + /** + * Creates a mock object for a trait using a fluent interface. + * + * @return PHPUnit_Framework_MockObject_MockObject + */ + public function getMockForTrait() + { + $object = $this->generator->getMockForTrait( + $this->type, + $this->constructorArgs, + $this->mockClassName, + $this->originalConstructor, + $this->originalClone, + $this->autoload, + $this->methods, + $this->cloneArguments + ); + + $this->testCase->registerMockObject($object); + + return $object; + } + + /** + * Specifies the subset of methods to mock. Default is to mock all of them. + * + * @param array|null $methods + * + * @return PHPUnit_Framework_MockObject_MockBuilder + */ + public function setMethods(array $methods = null) + { + $this->methods = $methods; + + return $this; + } + + /** + * Specifies the subset of methods to not mock. Default is to mock all of them. + * + * @param array $methods + * + * @return PHPUnit_Framework_MockObject_MockBuilder + */ + public function setMethodsExcept(array $methods = []) + { + $this->methodsExcept = $methods; + + $this->setMethods( + array_diff( + $this->generator->getClassMethods($this->type), + $this->methodsExcept + ) + ); + + return $this; + } + + /** + * Specifies the arguments for the constructor. + * + * @param array $args + * + * @return PHPUnit_Framework_MockObject_MockBuilder + */ + public function setConstructorArgs(array $args) + { + $this->constructorArgs = $args; + + return $this; + } + + /** + * Specifies the name for the mock class. + * + * @param string $name + * + * @return PHPUnit_Framework_MockObject_MockBuilder + */ + public function setMockClassName($name) + { + $this->mockClassName = $name; + + return $this; + } + + /** + * Disables the invocation of the original constructor. + * + * @return PHPUnit_Framework_MockObject_MockBuilder + */ + public function disableOriginalConstructor() + { + $this->originalConstructor = false; + + return $this; + } + + /** + * Enables the invocation of the original constructor. + * + * @return PHPUnit_Framework_MockObject_MockBuilder + * + * @since Method available since Release 1.2.0 + */ + public function enableOriginalConstructor() + { + $this->originalConstructor = true; + + return $this; + } + + /** + * Disables the invocation of the original clone constructor. + * + * @return PHPUnit_Framework_MockObject_MockBuilder + */ + public function disableOriginalClone() + { + $this->originalClone = false; + + return $this; + } + + /** + * Enables the invocation of the original clone constructor. + * + * @return PHPUnit_Framework_MockObject_MockBuilder + * + * @since Method available since Release 1.2.0 + */ + public function enableOriginalClone() + { + $this->originalClone = true; + + return $this; + } + + /** + * Disables the use of class autoloading while creating the mock object. + * + * @return PHPUnit_Framework_MockObject_MockBuilder + */ + public function disableAutoload() + { + $this->autoload = false; + + return $this; + } + + /** + * Enables the use of class autoloading while creating the mock object. + * + * @return PHPUnit_Framework_MockObject_MockBuilder + * + * @since Method available since Release 1.2.0 + */ + public function enableAutoload() + { + $this->autoload = true; + + return $this; + } + + /** + * Disables the cloning of arguments passed to mocked methods. + * + * @return PHPUnit_Framework_MockObject_MockBuilder + * + * @since Method available since Release 1.2.0 + */ + public function disableArgumentCloning() + { + $this->cloneArguments = false; + + return $this; + } + + /** + * Enables the cloning of arguments passed to mocked methods. + * + * @return PHPUnit_Framework_MockObject_MockBuilder + * + * @since Method available since Release 1.2.0 + */ + public function enableArgumentCloning() + { + $this->cloneArguments = true; + + return $this; + } + + /** + * Enables the invocation of the original methods. + * + * @return PHPUnit_Framework_MockObject_MockBuilder + * + * @since Method available since Release 2.0.0 + */ + public function enableProxyingToOriginalMethods() + { + $this->callOriginalMethods = true; + + return $this; + } + + /** + * Disables the invocation of the original methods. + * + * @return PHPUnit_Framework_MockObject_MockBuilder + * + * @since Method available since Release 2.0.0 + */ + public function disableProxyingToOriginalMethods() + { + $this->callOriginalMethods = false; + $this->proxyTarget = null; + + return $this; + } + + /** + * Sets the proxy target. + * + * @param object $object + * + * @return PHPUnit_Framework_MockObject_MockBuilder + * + * @since Method available since Release 2.0.0 + */ + public function setProxyTarget($object) + { + $this->proxyTarget = $object; + + return $this; + } + + /** + * @return PHPUnit_Framework_MockObject_MockBuilder + * + * @since Method available since Release 3.2.0 + */ + public function allowMockingUnknownTypes() + { + $this->allowMockingUnknownTypes = true; + + return $this; + } + + /** + * @return PHPUnit_Framework_MockObject_MockBuilder + * + * @since Method available since Release 3.2.0 + */ + public function disallowMockingUnknownTypes() + { + $this->allowMockingUnknownTypes = false; + + return $this; + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/MockObject.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/MockObject.php new file mode 100644 index 0000000..e1a2e4e --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/MockObject.php @@ -0,0 +1,55 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Interface for all mock objects which are generated by + * PHPUnit_Framework_MockObject_MockBuilder. + * + * @method PHPUnit_Framework_MockObject_Builder_InvocationMocker method($constraint) + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_MockObject /*extends PHPUnit_Framework_MockObject_Verifiable*/ +{ + /** + * Registers a new expectation in the mock object and returns the match + * object which can be infused with further details. + * + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher + * + * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker + */ + public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher); + + /** + * @return PHPUnit_Framework_MockObject_InvocationMocker + * + * @since Method available since Release 2.0.0 + */ + public function __phpunit_setOriginalObject($originalObject); + + /** + * @return PHPUnit_Framework_MockObject_InvocationMocker + */ + public function __phpunit_getInvocationMocker(); + + /** + * Verifies that the current expectation is valid. If everything is OK the + * code should just return, if not it must throw an exception. + * + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function __phpunit_verify(); + + /** + * @return bool + */ + public function __phpunit_hasMatchers(); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub.php new file mode 100644 index 0000000..558d49e --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub.php @@ -0,0 +1,30 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * An object that stubs the process of a normal method for a mock object. + * + * The stub object will replace the code for the stubbed method and return a + * specific value instead of the original value. + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Stub extends PHPUnit_Framework_SelfDescribing +{ + /** + * Fakes the processing of the invocation $invocation by returning a + * specific value. + * + * @param PHPUnit_Framework_MockObject_Invocation $invocation The invocation which was mocked and matched by the current method and argument matchers + * + * @return mixed + */ + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ConsecutiveCalls.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ConsecutiveCalls.php new file mode 100644 index 0000000..afc353d --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ConsecutiveCalls.php @@ -0,0 +1,48 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use SebastianBergmann\Exporter\Exporter; + +/** + * Stubs a method by returning a user-defined stack of values. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls implements PHPUnit_Framework_MockObject_Stub +{ + protected $stack; + protected $value; + + public function __construct($stack) + { + $this->stack = $stack; + } + + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $this->value = array_shift($this->stack); + + if ($this->value instanceof PHPUnit_Framework_MockObject_Stub) { + $this->value = $this->value->invoke($invocation); + } + + return $this->value; + } + + public function toString() + { + $exporter = new Exporter; + + return sprintf( + 'return user-specified value %s', + $exporter->export($this->value) + ); + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/Exception.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/Exception.php new file mode 100644 index 0000000..3c1b922 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/Exception.php @@ -0,0 +1,48 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use SebastianBergmann\Exporter\Exporter; + +/** + * Stubs a method by raising a user-defined exception. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Stub_Exception implements PHPUnit_Framework_MockObject_Stub +{ + protected $exception; + + public function __construct($exception) + { + // TODO Replace check with type declaration when support for PHP 5 is dropped + if (!$exception instanceof Throwable && !$exception instanceof Exception) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + 'Exception must be an instance of Throwable (PHP 7) or Exception (PHP 5)' + ); + } + + $this->exception = $exception; + } + + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + throw $this->exception; + } + + public function toString() + { + $exporter = new Exporter; + + return sprintf( + 'raise user-specified exception %s', + $exporter->export($this->exception) + ); + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/MatcherCollection.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/MatcherCollection.php new file mode 100644 index 0000000..fdc5728 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/MatcherCollection.php @@ -0,0 +1,25 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Stubs a method by returning a user-defined value. + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Stub_MatcherCollection +{ + /** + * Adds a new matcher to the collection which can be used as an expectation + * or a stub. + * + * @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher Matcher for invocations to mock objects + */ + public function addMatcher(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher); +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/Return.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/Return.php new file mode 100644 index 0000000..630504f --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/Return.php @@ -0,0 +1,41 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +use SebastianBergmann\Exporter\Exporter; + +/** + * Stubs a method by returning a user-defined value. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Stub_Return implements PHPUnit_Framework_MockObject_Stub +{ + protected $value; + + public function __construct($value) + { + $this->value = $value; + } + + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + return $this->value; + } + + public function toString() + { + $exporter = new Exporter; + + return sprintf( + 'return user-specified value %s', + $exporter->export($this->value) + ); + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnArgument.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnArgument.php new file mode 100644 index 0000000..fb79f4e --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnArgument.php @@ -0,0 +1,38 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Stubs a method by returning an argument that was passed to the mocked method. + * + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Stub_ReturnArgument extends PHPUnit_Framework_MockObject_Stub_Return +{ + protected $argumentIndex; + + public function __construct($argumentIndex) + { + $this->argumentIndex = $argumentIndex; + } + + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + if (isset($invocation->parameters[$this->argumentIndex])) { + return $invocation->parameters[$this->argumentIndex]; + } else { + return; + } + } + + public function toString() + { + return sprintf('return argument #%d', $this->argumentIndex); + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnCallback.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnCallback.php new file mode 100644 index 0000000..601b354 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnCallback.php @@ -0,0 +1,51 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * @since Class available since Release 1.0.0 + */ +class PHPUnit_Framework_MockObject_Stub_ReturnCallback implements PHPUnit_Framework_MockObject_Stub +{ + protected $callback; + + public function __construct($callback) + { + $this->callback = $callback; + } + + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + return call_user_func_array($this->callback, $invocation->parameters); + } + + public function toString() + { + if (is_array($this->callback)) { + if (is_object($this->callback[0])) { + $class = get_class($this->callback[0]); + $type = '->'; + } else { + $class = $this->callback[0]; + $type = '::'; + } + + return sprintf( + 'return result of user defined callback %s%s%s() with the ' . + 'passed arguments', + $class, + $type, + $this->callback[1] + ); + } else { + return 'return result of user defined callback ' . $this->callback . + ' with the passed arguments'; + } + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnReference.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnReference.php new file mode 100644 index 0000000..91dde3b --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnReference.php @@ -0,0 +1,22 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Stubs a method by returning a user-defined reference to a value. + * + * @since Class available since Release 3.0.7 + */ +class PHPUnit_Framework_MockObject_Stub_ReturnReference extends PHPUnit_Framework_MockObject_Stub_Return +{ + public function __construct(&$value) + { + $this->value = &$value; + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnSelf.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnSelf.php new file mode 100644 index 0000000..dbb9a6d --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnSelf.php @@ -0,0 +1,34 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Stubs a method by returning the current object. + * + * @since Class available since Release 1.1.0 + */ +class PHPUnit_Framework_MockObject_Stub_ReturnSelf implements PHPUnit_Framework_MockObject_Stub +{ + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + if (!$invocation instanceof PHPUnit_Framework_MockObject_Invocation_Object) { + throw new PHPUnit_Framework_MockObject_RuntimeException( + 'The current object can only be returned when mocking an ' . + 'object, not a static class.' + ); + } + + return $invocation->object; + } + + public function toString() + { + return 'return the current object'; + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnValueMap.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnValueMap.php new file mode 100644 index 0000000..25ba4d1 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Stub/ReturnValueMap.php @@ -0,0 +1,47 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Stubs a method by returning a value from a map. + * + * @since Class available since Release 1.1.0 + */ +class PHPUnit_Framework_MockObject_Stub_ReturnValueMap implements PHPUnit_Framework_MockObject_Stub +{ + protected $valueMap; + + public function __construct(array $valueMap) + { + $this->valueMap = $valueMap; + } + + public function invoke(PHPUnit_Framework_MockObject_Invocation $invocation) + { + $parameterCount = count($invocation->parameters); + + foreach ($this->valueMap as $map) { + if (!is_array($map) || $parameterCount != count($map) - 1) { + continue; + } + + $return = array_pop($map); + if ($invocation->parameters === $map) { + return $return; + } + } + + return; + } + + public function toString() + { + return 'return value from a map'; + } +} diff --git a/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Verifiable.php b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Verifiable.php new file mode 100644 index 0000000..c19dfb3 --- /dev/null +++ b/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Verifiable.php @@ -0,0 +1,25 @@ +<?php +/* + * This file is part of the PHPUnit_MockObject package. + * + * (c) Sebastian Bergmann <sebastian@phpunit.de> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Interface for classes which must verify a given expectation. + * + * @since Interface available since Release 1.0.0 + */ +interface PHPUnit_Framework_MockObject_Verifiable +{ + /** + * Verifies that the current expectation is valid. If everything is OK the + * code should just return, if not it must throw an exception. + * + * @throws PHPUnit_Framework_ExpectationFailedException + */ + public function verify(); +} |