pax_global_header00006660000000000000000000000064126315144120014511gustar00rootroot0000000000000052 comment=49bc700750196c04dd6bc2c4c99cb632b893836b phpunit-mock-objects-3.0.6/000077500000000000000000000000001263151441200155645ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/.gitattributes000066400000000000000000000000171263151441200204550ustar00rootroot00000000000000*.php diff=php phpunit-mock-objects-3.0.6/.gitignore000066400000000000000000000001441263151441200175530ustar00rootroot00000000000000build/coverage build/logs cache.properties phpunit.xml /vendor /composer.lock /composer.phar /.idea phpunit-mock-objects-3.0.6/.php_cs000066400000000000000000000022361263151441200170440ustar00rootroot00000000000000files() ->in('src') ->in('tests') ->name('*.php'); return Symfony\CS\Config\Config::create() ->level(\Symfony\CS\FixerInterface::NONE_LEVEL) ->fixers( array( 'duplicate_semicolon', 'empty_return', 'extra_empty_lines', 'join_function', 'list_commas', 'no_blank_lines_after_class_opening', 'no_empty_lines_after_phpdocs', 'phpdoc_indent', 'phpdoc_no_access', 'phpdoc_no_empty_return', 'phpdoc_no_package', 'phpdoc_params', 'phpdoc_scalar', 'phpdoc_to_comment', 'phpdoc_trim', 'return', 'self_accessor', 'single_quote', 'spaces_before_semicolon', 'spaces_cast', 'ternary_spaces', 'trim_array_spaces', 'unused_use', 'whitespacy_lines', 'align_double_arrow', 'align_equals', 'concat_with_spaces', 'short_array_syntax' ) ) ->finder($finder); phpunit-mock-objects-3.0.6/.travis.yml000066400000000000000000000006101263151441200176720ustar00rootroot00000000000000language: php before_script: - composer self-update - composer install --no-interaction --prefer-source --dev script: ./vendor/bin/phpunit --configuration ./build/travis-ci.xml php: - 5.6 - 7.0 - hhvm notifications: email: false webhooks: urls: - https://webhooks.gitter.im/e/6668f52f3dd4e3f81960 on_success: always on_failure: always on_start: false phpunit-mock-objects-3.0.6/CONTRIBUTING.md000066400000000000000000000003271263151441200200170ustar00rootroot00000000000000Please refer to [https://github.com/sebastianbergmann/phpunit/blob/master/CONTRIBUTING.md](https://github.com/sebastianbergmann/phpunit/blob/master/CONTRIBUTING.md) for details on how to contribute to this project. phpunit-mock-objects-3.0.6/LICENSE000066400000000000000000000030211263151441200165650ustar00rootroot00000000000000PHPUnit_MockObject Copyright (c) 2002-2015, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sebastian Bergmann nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. phpunit-mock-objects-3.0.6/README.md000066400000000000000000000016651263151441200170530ustar00rootroot00000000000000[![Build Status](https://img.shields.io/travis/sebastianbergmann/phpunit-mock-objects/master.svg?style=flat-square)](https://travis-ci.org/sebastianbergmann/phpunit-mock-objects) [![Latest Stable Version](https://img.shields.io/packagist/v/phpunit/phpunit-mock-objects.svg?style=flat-square)](https://packagist.org/packages/phpunit/phpunit-mock-objects) # PHPUnit_MockObject **PHPUnit_MockObject** is the default mock object library for PHPUnit. ## Requirements * PHP 5.3.3 is required but using the latest version of PHP is highly recommended ## Installation To add PHPUnit_MockObject as a local, per-project dependency to your project, simply add a dependency on `phpunit/phpunit-mock-objects` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on PHPUnit_MockObject 2.3: { "require": { "phpunit/phpunit-mock-objects": "2.3.*" } } phpunit-mock-objects-3.0.6/build.xml000066400000000000000000000022701263151441200174060ustar00rootroot00000000000000 phpunit-mock-objects-3.0.6/build/000077500000000000000000000000001263151441200166635ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/build/travis-ci.xml000066400000000000000000000007121263151441200213060ustar00rootroot00000000000000 ../tests ../tests phpunit-mock-objects-3.0.6/composer.json000066400000000000000000000022031263151441200203030ustar00rootroot00000000000000{ "name": "phpunit/phpunit-mock-objects", "description": "Mock Object library for PHPUnit", "type": "library", "keywords": [ "xunit", "mock" ], "homepage": "https://github.com/sebastianbergmann/phpunit-mock-objects/", "license": "BSD-3-Clause", "authors": [ { "name": "Sebastian Bergmann", "email": "sb@sebastian-bergmann.de", "role": "lead" } ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit-mock-objects/issues", "irc": "irc://irc.freenode.net/phpunit" }, "require": { "php": ">=5.6", "phpunit/php-text-template": "~1.2", "doctrine/instantiator": "^1.0.2", "sebastian/exporter": "~1.2" }, "require-dev": { "phpunit/phpunit": "~5" }, "suggest": { "ext-soap": "*" }, "autoload": { "classmap": [ "src/" ] }, "autoload-dev": { "classmap": [ "tests/_fixture/" ] }, "extra": { "branch-alias": { "dev-master": "3.0.x-dev" } } } phpunit-mock-objects-3.0.6/phpunit.xml.dist000066400000000000000000000012451263151441200207410ustar00rootroot00000000000000 tests tests src phpunit-mock-objects-3.0.6/src/000077500000000000000000000000001263151441200163535ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/src/Framework/000077500000000000000000000000001263151441200203105ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/src/Framework/MockObject/000077500000000000000000000000001263151441200223305ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/src/Framework/MockObject/Builder/000077500000000000000000000000001263151441200237165ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/src/Framework/MockObject/Builder/Identity.php000066400000000000000000000016241263151441200262230ustar00rootroot00000000000000 * * 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 identifiation of expectation. */ public function id($id); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Builder/InvocationMocker.php000066400000000000000000000165341263151441200277120ustar00rootroot00000000000000 * * 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; /** * @param PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection * @param PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher */ public function __construct(PHPUnit_Framework_MockObject_Stub_MatcherCollection $collection, PHPUnit_Framework_MockObject_Matcher_Invocation $invocationMatcher) { $this->collection = $collection; $this->matcher = new PHPUnit_Framework_MockObject_Matcher( $invocationMatcher ); $this->collection->addMatcher($this->matcher); } /** * @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 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_Exception */ private function canDefineParameters() { if ($this->matcher->methodNameMatcher === null) { throw new PHPUnit_Framework_Exception( 'Method name matcher is not defined, cannot define parameter ' . ' matcher without one' ); } if ($this->matcher->parametersMatcher !== null) { throw new PHPUnit_Framework_Exception( 'Parameter matcher is already defined, cannot redefine' ); } } /** * @param mixed $argument, ... * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker */ public function with() { $args = func_get_args(); $this->canDefineParameters(); $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_Parameters($args); return $this; } /** * @param mixed ...$argument * @return PHPUnit_Framework_MockObject_Builder_InvocationMocker */ public function withConsecutive() { $args = func_get_args(); $this->canDefineParameters(); $this->matcher->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters($args); 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_Exception( 'Method name matcher is already defined, cannot redefine' ); } $this->matcher->methodNameMatcher = new PHPUnit_Framework_MockObject_Matcher_MethodName($constraint); return $this; } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Builder/Match.php000066400000000000000000000015271263151441200254700ustar00rootroot00000000000000 * * 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); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Builder/MethodNameMatch.php000066400000000000000000000020511263151441200274230ustar00rootroot00000000000000 * * 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); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Builder/Namespace.php000066400000000000000000000026621263151441200263310ustar00rootroot00000000000000 * * 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 identifiction 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); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Builder/ParametersMatch.php000066400000000000000000000030001263151441200275000ustar00rootroot00000000000000 * * 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: * * // 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)); * * * @return PHPUnit_Framework_MockObject_Builder_ParametersMatch */ public function with(); /** * Sets a matcher which allows any kind of parameters. * * Some examples: * * // match any number of parameters * $b->withAnyParamers(); * * * @return PHPUnit_Framework_MockObject_Matcher_AnyParameters */ public function withAnyParameters(); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Builder/Stub.php000066400000000000000000000015571263151441200253540ustar00rootroot00000000000000 * * 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 The stub object. * @return PHPUnit_Framework_MockObject_Builder_Identity */ public function will(PHPUnit_Framework_MockObject_Stub $stub); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Exception/000077500000000000000000000000001263151441200242665ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/src/Framework/MockObject/Exception/BadMethodCallException.php000066400000000000000000000007011263151441200312770ustar00rootroot00000000000000 * * 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 { } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Exception/Exception.php000066400000000000000000000006461263151441200267430ustar00rootroot00000000000000 * * 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 { } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Exception/RuntimeException.php000066400000000000000000000006651263151441200303100ustar00rootroot00000000000000 * * 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 { } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator.php000066400000000000000000001161751263151441200250020ustar00rootroot00000000000000 * * 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 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 * @return object * @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) { 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 (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_Exception( 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"', implode(', ', $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 object * @since Method available since Release 1.0.0 * @throws PHPUnit_Framework_MockObject_RuntimeException * @throws PHPUnit_Framework_Exception */ 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 object * @since Method available since Release 1.2.3 * @throws PHPUnit_Framework_MockObject_RuntimeException * @throws PHPUnit_Framework_Exception */ 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 = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR; $classTemplate = new Text_Template( $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 * @since Method available since Release 1.1.0 * @throws PHPUnit_Framework_MockObject_RuntimeException * @throws PHPUnit_Framework_Exception */ 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 = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR; $classTemplate = new Text_Template( $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 = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR; $methodTemplate = new Text_Template($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 = new Text_Template($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_Exception */ private function generateMock($type, $methods, $mockClassName, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods) { $templateDir = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR; $classTemplate = new Text_Template( $templateDir . 'mocked_class.tpl' ); $additionalInterfaces = []; $cloneTemplate = ''; $isClass = false; $isInterface = false; $mockClassName = $this->generateClassName( $type, $mockClassName, 'Mock_' ); if (is_array($type)) { foreach ($type as $_type) { if (!interface_exists($_type, $callAutoload)) { throw new PHPUnit_Framework_Exception( sprintf( 'Interface "%s" does not exist.', $_type ) ); } $additionalInterfaces[] = $_type; foreach ($this->getClassMethods($_type) as $method) { if (in_array($method, $methods)) { throw new PHPUnit_Framework_Exception( sprintf( 'Duplicate method "%s" not allowed.', $method ) ); } $methods[] = $method; } } } if (class_exists($mockClassName['fullClassName'], $callAutoload)) { $isClass = true; } else { if (interface_exists($mockClassName['fullClassName'], $callAutoload)) { $isInterface = true; } } if (!class_exists($mockClassName['fullClassName'], $callAutoload) && !interface_exists($mockClassName['fullClassName'], $callAutoload)) { $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 = new Text_Template( $templateDir . 'mocked_clone.tpl' ); } else { $class = new ReflectionClass($mockClassName['fullClassName']); if ($class->isFinal()) { throw new PHPUnit_Framework_Exception( 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 = new Text_Template( $templateDir . 'unmocked_clone.tpl' ); } else { $cloneTemplate = new Text_Template( $templateDir . 'mocked_clone.tpl' ); } } } else { $cloneTemplate = new Text_Template( $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 = ''; 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 ); } } } else { foreach ($methods as $methodName) { $mockedMethods .= $this->generateMockedMethodDefinition( $templateDir, $mockClassName['fullClassName'], $methodName, $cloneArguments ); } } $method = ''; if (!in_array('method', $methods)) { $methodTemplate = new Text_Template( $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 ] ); 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(microtime()), 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 = ''; } return $this->generateMockedMethodDefinition( $templateDir, $method->getDeclaringClass()->getName(), $method->getName(), $cloneArguments, $modifier, $this->getMethodParameters($method), $this->getMethodParameters($method, true), $returnType, $reference, $callOriginalMethods, $method->isStatic() ); } /** * @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 * @return string */ private function generateMockedMethodDefinition($templateDir, $className, $methodName, $cloneArguments = true, $modifier = 'public', $arguments_decl = '', $arguments_call = '', $return_type = '', $reference = '', $callOriginalMethods = false, $static = false) { if ($static) { $templateFile = 'mocked_static_method.tpl'; } 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; } $template = new Text_Template($templateDir . $templateFile); $template->setVar( [ 'arguments_decl' => $arguments_decl, 'arguments_call' => $arguments_call, 'return_delim' => $return_type ? ': ' : '', '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' ] ); 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; } } $default = ''; $reference = ''; $typeDeclaration = ''; if (!$forCall) { if ($this->hasType($parameter)) { $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[] = $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', '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', 'hasType') && $parameter->hasType(); } /** * @param ReflectionMethod $method * @return bool */ private function hasReturnType(ReflectionMethod $method) { return method_exists('ReflectionMethod', 'hasReturnType') && $method->hasReturnType(); } /** * @param string $className * @return array * @since Method available since Release 2.3.2 */ private function getClassMethods($className) { $class = new ReflectionClass($className); $methods = []; foreach ($class->getMethods() as $method) { if ($method->isPublic() || $method->isAbstract()) { $methods[] = $method->getName(); } } return $methods; } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator/000077500000000000000000000000001263151441200242565ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator/mocked_class.tpl.dist000066400000000000000000000021361263151441200303720ustar00rootroot00000000000000{prologue}{class_declaration} { private $__phpunit_invocationMocker; private $__phpunit_originalObject; {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; } 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} phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator/mocked_class_method.tpl.dist000066400000000000000000000003551263151441200317330ustar00rootroot00000000000000 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()); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator/mocked_clone.tpl.dist000066400000000000000000000002041263151441200303570ustar00rootroot00000000000000 public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator/mocked_method.tpl.dist000066400000000000000000000012701263151441200305430ustar00rootroot00000000000000 {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]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( '{class_name}', '{method_name}', $arguments, '{return_type}', $this, {clone_arguments} ) ); return $result; } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator/mocked_static_method.tpl.dist000066400000000000000000000002621263151441200321120ustar00rootroot00000000000000 {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} { throw new PHPUnit_Framework_MockObject_BadMethodCallException; } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator/proxied_method.tpl.dist000066400000000000000000000014001263151441200307460ustar00rootroot00000000000000 {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); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator/trait_class.tpl.dist000066400000000000000000000000671263151441200302540ustar00rootroot00000000000000{prologue}class {class_name} { use {trait_name}; } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator/unmocked_clone.tpl.dist000066400000000000000000000002371263151441200307300ustar00rootroot00000000000000 public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); parent::__clone(); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator/wsdl_class.tpl.dist000066400000000000000000000002631263151441200301000ustar00rootroot00000000000000{namespace}class {class_name} extends \SoapClient { public function __construct($wsdl, array $options) { parent::__construct('{wsdl}', $options); } {methods}} phpunit-mock-objects-3.0.6/src/Framework/MockObject/Generator/wsdl_method.tpl.dist000066400000000000000000000000741263151441200302530ustar00rootroot00000000000000 public function {method_name}({arguments}) { } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Invocation.php000066400000000000000000000007621263151441200251570ustar00rootroot00000000000000 * * 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(); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Invocation/000077500000000000000000000000001263151441200244415ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/src/Framework/MockObject/Invocation/Object.php000066400000000000000000000017341263151441200263650ustar00rootroot00000000000000 * * 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 object $cloneObjects */ public function __construct($className, $methodName, array $parameters, $returnType, $object, $cloneObjects = false) { parent::__construct($className, $methodName, $parameters, $returnType, $cloneObjects); $this->object = $object; } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Invocation/Static.php000066400000000000000000000111061263151441200264000ustar00rootroot00000000000000 * * 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; /** * @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; $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 ''; case 'float': return 0.0; case 'int': return 0; case 'bool': return false; case 'array': return []; case 'callable': case 'Closure': return function () {}; case 'Traversable': case 'Generator': $generator = function () { yield; }; return $generator(); default: $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; } } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/InvocationMocker.php000066400000000000000000000101211263151441200263060ustar00rootroot00000000000000 * * 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 = []; /** * @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_Exception */ public function registerId($id, PHPUnit_Framework_MockObject_Builder_Match $builder) { if (isset($this->builderMap[$id])) { throw new PHPUnit_Framework_Exception( '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 ); } /** * @param PHPUnit_Framework_MockObject_Invocation $invocation * @return mixed */ 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(); } } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Invokable.php000066400000000000000000000024711263151441200247570ustar00rootroot00000000000000 * * 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); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher.php000066400000000000000000000203061263151441200244250ustar00rootroot00000000000000 * * 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_Exception( 'No invocation matcher is set' ); } if ($this->methodNameMatcher === null) { throw new PHPUnit_Framework_Exception('No method matcher is set'); } if ($this->afterMatchBuilderId !== null) { $builder = $invocation->object ->__phpunit_getInvocationMocker() ->lookupId($this->afterMatchBuilderId); if (!$builder) { throw new PHPUnit_Framework_Exception( 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_Exception( 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_Exception( 'No invocation matcher is set' ); } if ($this->methodNameMatcher === null) { throw new PHPUnit_Framework_Exception('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_Exception * @throws PHPUnit_Framework_ExpectationFailedException */ public function verify() { if ($this->invocationMatcher === null) { throw new PHPUnit_Framework_Exception( 'No invocation matcher is set' ); } if ($this->methodNameMatcher === null) { throw new PHPUnit_Framework_Exception('No method matcher is set'); } try { $this->invocationMatcher->verify(); if ($this->parametersMatcher === null) { $this->parametersMatcher = new PHPUnit_Framework_MockObject_Matcher_AnyParameters; } $invocationIsAny = get_class($this->invocationMatcher) === 'PHPUnit_Framework_MockObject_Matcher_AnyInvokedCount'; $invocationIsNever = get_class($this->invocationMatcher) === '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; } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/000077500000000000000000000000001263151441200237135ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/AnyInvokedCount.php000066400000000000000000000013401263151441200275020ustar00rootroot00000000000000 * * 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() { } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/AnyParameters.php000066400000000000000000000015031263151441200271760ustar00rootroot00000000000000 * * 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; } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/ConsecutiveParameters.php000066400000000000000000000072361263151441200307470ustar00rootroot00000000000000 * * 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() ) ); } } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/Invocation.php000066400000000000000000000040041263151441200265330ustar00rootroot00000000000000 * * 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); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/InvokedAtIndex.php000066400000000000000000000044201263151441200273000ustar00rootroot00000000000000 * * 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 ) ); } } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/InvokedAtLeastCount.php000066400000000000000000000027741263151441200303240ustar00rootroot00000000000000 * * 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 occured ' . $count . ' time(s).' ); } } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/InvokedAtLeastOnce.php000066400000000000000000000023201263151441200301030ustar00rootroot00000000000000 * * 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 occured.' ); } } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/InvokedAtMostCount.php000066400000000000000000000027611263151441200301720ustar00rootroot00000000000000 * * 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 occured ' . $count . ' time(s).' ); } } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/InvokedCount.php000066400000000000000000000056401263151441200270410ustar00rootroot00000000000000 * * 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 ) ); } } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/InvokedRecorder.php000066400000000000000000000031331263151441200275110ustar00rootroot00000000000000 * * 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 occured. * * @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; } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/MethodName.php000066400000000000000000000034401263151441200264460ustar00rootroot00000000000000 * * 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); } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/Parameters.php000066400000000000000000000076451263151441200265430ustar00rootroot00000000000000 * * 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; /** * @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; return $this->verify(); } /** * 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 * @throws PHPUnit_Framework_ExpectationFailedException */ public function verify() { 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; } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Matcher/StatelessInvocation.php000066400000000000000000000041531263151441200304300ustar00rootroot00000000000000 * * 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() { } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/MockBuilder.php000066400000000000000000000164041263151441200252460ustar00rootroot00000000000000 * * 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 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; /** * @param PHPUnit_Framework_TestCase $testCase * @param array|string $type */ public function __construct(PHPUnit_Framework_TestCase $testCase, $type) { $this->testCase = $testCase; $this->type = $type; } /** * Creates a mock object using a fluent interface. * * @return PHPUnit_Framework_MockObject_MockObject */ public function getMock() { return $this->testCase->getMock( $this->type, $this->methods, $this->constructorArgs, $this->mockClassName, $this->originalConstructor, $this->originalClone, $this->autoload, $this->cloneArguments, $this->callOriginalMethods, $this->proxyTarget ); } /** * Creates a mock object for an abstract class using a fluent interface. * * @return PHPUnit_Framework_MockObject_MockObject */ public function getMockForAbstractClass() { return $this->testCase->getMockForAbstractClass( $this->type, $this->constructorArgs, $this->mockClassName, $this->originalConstructor, $this->originalClone, $this->autoload, $this->methods, $this->cloneArguments ); } /** * Creates a mock object for a trait using a fluent interface. * * @return PHPUnit_Framework_MockObject_MockObject */ public function getMockForTrait() { return $this->testCase->getMockForTrait( $this->type, $this->constructorArgs, $this->mockClassName, $this->originalConstructor, $this->originalClone, $this->autoload, $this->methods, $this->cloneArguments ); } /** * 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($methods) { $this->methods = $methods; 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; } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/MockObject.php000066400000000000000000000032131263151441200250600ustar00rootroot00000000000000 * * 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(); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Stub.php000066400000000000000000000021341263151441200237560ustar00rootroot00000000000000 * * 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); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Stub/000077500000000000000000000000001263151441200232455ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/src/Framework/MockObject/Stub/ConsecutiveCalls.php000066400000000000000000000022231263151441200272230ustar00rootroot00000000000000 * * 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) ); } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Stub/Exception.php000066400000000000000000000024241263151441200257160ustar00rootroot00000000000000 * * 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_Exception( '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) ); } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Stub/MatcherCollection.php000066400000000000000000000014721263151441200273610ustar00rootroot00000000000000 * * 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); } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Stub/Return.php000066400000000000000000000016441263151441200252420ustar00rootroot00000000000000 * * 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) ); } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Stub/ReturnArgument.php000066400000000000000000000017771263151441200267540ustar00rootroot00000000000000 * * 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); } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Stub/ReturnCallback.php000066400000000000000000000026251263151441200266570ustar00rootroot00000000000000 * * 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'; } } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Stub/ReturnSelf.php000066400000000000000000000017021263151441200260470ustar00rootroot00000000000000 * * 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_Exception( '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'; } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Stub/ReturnValueMap.php000066400000000000000000000021741263151441200266740ustar00rootroot00000000000000 * * 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'; } } phpunit-mock-objects-3.0.6/src/Framework/MockObject/Verifiable.php000066400000000000000000000012621263151441200251120ustar00rootroot00000000000000 * * 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(); } phpunit-mock-objects-3.0.6/tests/000077500000000000000000000000001263151441200167265ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/tests/GeneratorTest.php000066400000000000000000000135461263151441200222360ustar00rootroot00000000000000generator = new PHPUnit_Framework_MockObject_Generator; } /** * @covers PHPUnit_Framework_MockObject_Generator::getMock * @expectedException PHPUnit_Framework_Exception */ public function testGetMockFailsWhenInvalidFunctionNameIsPassedInAsAFunctionToMock() { $this->generator->getMock(StdClass::class, [0]); } /** * @covers PHPUnit_Framework_MockObject_Generator::getMock */ public function testGetMockCanCreateNonExistingFunctions() { $mock = $this->generator->getMock(StdClass::class, ['testFunction']); $this->assertTrue(method_exists($mock, 'testFunction')); } /** * @covers PHPUnit_Framework_MockObject_Generator::getMock * @expectedException PHPUnit_Framework_MockObject_RuntimeException * @expectedExceptionMessage duplicates: "foo, foo" */ public function testGetMockGeneratorFails() { $this->generator->getMock(StdClass::class, ['foo', 'foo']); } /** * @covers PHPUnit_Framework_MockObject_Generator::getMock * @covers PHPUnit_Framework_MockObject_Generator::isMethodNameBlacklisted * @requires PHP 7 */ public function testGetMockBlacklistedMethodNamesPhp7() { $mock = $this->generator->getMock(InterfaceWithSemiReservedMethodName::class); $this->assertTrue(method_exists($mock, 'unset')); $this->assertInstanceOf(InterfaceWithSemiReservedMethodName::class, $mock); } /** * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass */ public function testGetMockForAbstractClassDoesNotFailWhenFakingInterfaces() { $mock = $this->generator->getMockForAbstractClass(Countable::class); $this->assertTrue(method_exists($mock, 'count')); } /** * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass */ public function testGetMockForAbstractClassStubbingAbstractClass() { $mock = $this->generator->getMockForAbstractClass(AbstractMockTestClass::class); $this->assertTrue(method_exists($mock, 'doSomething')); } /** * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass */ public function testGetMockForAbstractClassWithNonExistentMethods() { $mock = $this->generator->getMockForAbstractClass( AbstractMockTestClass::class, [], '', true, true, true, ['nonexistentMethod'] ); $this->assertTrue(method_exists($mock, 'nonexistentMethod')); $this->assertTrue(method_exists($mock, 'doSomething')); } /** * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass */ public function testGetMockForAbstractClassShouldCreateStubsOnlyForAbstractMethodWhenNoMethodsWereInformed() { $mock = $this->generator->getMockForAbstractClass(AbstractMockTestClass::class); $mock->expects($this->any()) ->method('doSomething') ->willReturn('testing'); $this->assertEquals('testing', $mock->doSomething()); $this->assertEquals(1, $mock->returnAnything()); } /** * @dataProvider getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass * @expectedException PHPUnit_Framework_Exception */ public function testGetMockForAbstractClassExpectingInvalidArgumentException($className, $mockClassName) { $this->generator->getMockForAbstractClass($className, [], $mockClassName); } /** * @covers PHPUnit_Framework_MockObject_Generator::getMockForAbstractClass * @expectedException PHPUnit_Framework_MockObject_RuntimeException */ public function testGetMockForAbstractClassAbstractClassDoesNotExist() { $this->generator->getMockForAbstractClass('Tux'); } public function getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider() { return [ 'className not a string' => [[], ''], 'mockClassName not a string' => [Countable::class, new StdClass], ]; } /** * @covers PHPUnit_Framework_MockObject_Generator::getMockForTrait */ public function testGetMockForTraitWithNonExistentMethodsAndNonAbstractMethods() { $mock = $this->generator->getMockForTrait( AbstractTrait::class, [], '', true, true, true, ['nonexistentMethod'] ); $this->assertTrue(method_exists($mock, 'nonexistentMethod')); $this->assertTrue(method_exists($mock, 'doSomething')); $this->assertTrue($mock->mockableMethod()); $this->assertTrue($mock->anotherMockableMethod()); } /** * @covers PHPUnit_Framework_MockObject_Generator::getMockForTrait */ public function testGetMockForTraitStubbingAbstractMethod() { $mock = $this->generator->getMockForTrait(AbstractTrait::class); $this->assertTrue(method_exists($mock, 'doSomething')); } public function testGetMockForSingletonWithReflectionSuccess() { $mock = $this->generator->getMock(SingletonClass::class, ['doSomething'], [], '', false); $this->assertInstanceOf('SingletonClass', $mock); } /** * @covers PHPUnit_Framework_MockObject_Generator::getMock * @expectedException PHPUnit_Framework_MockObject_RuntimeException */ public function testExceptionIsRaisedForMutuallyExclusiveOptions() { $this->generator->getMock(StdClass::class, [], [], '', false, true, true, true, true); } } phpunit-mock-objects-3.0.6/tests/MockBuilderTest.php000066400000000000000000000065731263151441200225120ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * @since File available since Release 1.0.0 */ class Framework_MockBuilderTest extends PHPUnit_Framework_TestCase { public function testMockBuilderRequiresClassName() { $spec = $this->getMockBuilder('Mockable'); $mock = $spec->getMock(); $this->assertTrue($mock instanceof Mockable); } public function testByDefaultMocksAllMethods() { $spec = $this->getMockBuilder('Mockable'); $mock = $spec->getMock(); $this->assertNull($mock->mockableMethod()); $this->assertNull($mock->anotherMockableMethod()); } public function testMethodsToMockCanBeSpecified() { $spec = $this->getMockBuilder('Mockable'); $spec->setMethods(['mockableMethod']); $mock = $spec->getMock(); $this->assertNull($mock->mockableMethod()); $this->assertTrue($mock->anotherMockableMethod()); } public function testByDefaultDoesNotPassArgumentsToTheConstructor() { $spec = $this->getMockBuilder('Mockable'); $mock = $spec->getMock(); $this->assertEquals([null, null], $mock->constructorArgs); } public function testMockClassNameCanBeSpecified() { $spec = $this->getMockBuilder('Mockable'); $spec->setMockClassName('ACustomClassName'); $mock = $spec->getMock(); $this->assertTrue($mock instanceof ACustomClassName); } public function testConstructorArgumentsCanBeSpecified() { $spec = $this->getMockBuilder('Mockable'); $spec->setConstructorArgs($expected = [23, 42]); $mock = $spec->getMock(); $this->assertEquals($expected, $mock->constructorArgs); } public function testOriginalConstructorCanBeDisabled() { $spec = $this->getMockBuilder('Mockable'); $spec->disableOriginalConstructor(); $mock = $spec->getMock(); $this->assertNull($mock->constructorArgs); } public function testByDefaultOriginalCloneIsPreserved() { $spec = $this->getMockBuilder('Mockable'); $mock = $spec->getMock(); $cloned = clone $mock; $this->assertTrue($cloned->cloned); } public function testOriginalCloneCanBeDisabled() { $spec = $this->getMockBuilder('Mockable'); $spec->disableOriginalClone(); $mock = $spec->getMock(); $mock->cloned = false; $cloned = clone $mock; $this->assertFalse($cloned->cloned); } public function testCallingAutoloadCanBeDisabled() { // it is not clear to me how to test this nor the difference // between calling it or not $this->markTestIncomplete(); } public function testProvidesAFluentInterface() { $spec = $this->getMockBuilder('Mockable') ->setMethods(['mockableMethod']) ->setConstructorArgs([]) ->setMockClassName('DummyClassName') ->disableOriginalConstructor() ->disableOriginalClone() ->disableAutoload(); $this->assertTrue($spec instanceof PHPUnit_Framework_MockObject_MockBuilder); } } phpunit-mock-objects-3.0.6/tests/MockObject/000077500000000000000000000000001263151441200207465ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/tests/MockObject/232.phpt000066400000000000000000000053511263151441200221550ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true) --FILE-- hi(); } } class Foo { use ChildTrait; public function speak() { return $this->world(); } } require __DIR__ . '/../../vendor/autoload.php'; $generator = new PHPUnit_Framework_MockObject_Generator; $mock = $generator->generate( 'Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function speak() { $arguments = array(); $count = func_num_args(); if ($count > 0) { $_arguments = func_get_args(); for ($i = 0; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'speak', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/Builder/000077500000000000000000000000001263151441200223345ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/tests/MockObject/Builder/InvocationMockerTest.php000066400000000000000000000021531263151441200271600ustar00rootroot00000000000000getMock('stdClass', ['foo']); $mock ->expects($this->any()) ->method('foo') ->willReturn(1); $this->assertEquals(1, $mock->foo()); } public function testWillReturnWithMultipleValues() { $mock = $this->getMock('stdClass', ['foo']); $mock ->expects($this->any()) ->method('foo') ->willReturn(1, 2, 3); $this->assertEquals(1, $mock->foo()); $this->assertEquals(2, $mock->foo()); $this->assertEquals(3, $mock->foo()); } public function testWillReturnOnConsecutiveCalls() { $mock = $this->getMock('stdClass', ['foo']); $mock ->expects($this->any()) ->method('foo') ->willReturnOnConsecutiveCalls(1, 2, 3); $this->assertEquals(1, $mock->foo()); $this->assertEquals(2, $mock->foo()); $this->assertEquals(3, $mock->foo()); } } phpunit-mock-objects-3.0.6/tests/MockObject/Invocation/000077500000000000000000000000001263151441200230575ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/tests/MockObject/Invocation/ObjectTest.php000066400000000000000000000055431263151441200256450ustar00rootroot00000000000000assertSame('FooClass', $invocation->className); } public function testAllowToGetMethodNameSetInConstructor() { $invocation = new PHPUnit_Framework_MockObject_Invocation_Object( 'FooClass', 'FooMethod', ['an_argument'], 'ReturnType', new StdClass ); $this->assertSame('FooMethod', $invocation->methodName); } public function testAllowToGetObjectSetInConstructor() { $expectedObject = new StdClass; $invocation = new PHPUnit_Framework_MockObject_Invocation_Object( 'FooClass', 'FooMethod', ['an_argument'], 'ReturnType', $expectedObject ); $this->assertSame($expectedObject, $invocation->object); } public function testAllowToGetMethodParametersSetInConstructor() { $expectedParameters = [ 'foo', 5, ['a', 'b'], new StdClass, null, false ]; $invocation = new PHPUnit_Framework_MockObject_Invocation_Object( 'FooClass', 'FooMethod', $expectedParameters, 'ReturnType', new StdClass ); $this->assertSame($expectedParameters, $invocation->parameters); } public function testConstructorAllowToSetFlagCloneObjectsInParameters() { $parameters = [new StdClass]; $cloneObjects = true; $invocation = new PHPUnit_Framework_MockObject_Invocation_Object( 'FooClass', 'FooMethod', $parameters, 'ReturnType', new StdClass, $cloneObjects ); $this->assertEquals($parameters, $invocation->parameters); $this->assertNotSame($parameters, $invocation->parameters); } public function testAllowToGetReturnTypeSetInConstructor() { $expectedReturnType = 'string'; $invocation = new PHPUnit_Framework_MockObject_Invocation_Object( 'FooClass', 'FooMethod', ['an_argument'], $expectedReturnType, new StdClass ); $this->assertSame($expectedReturnType, $invocation->returnType); } } phpunit-mock-objects-3.0.6/tests/MockObject/Invocation/StaticTest.php000066400000000000000000000044631263151441200256660ustar00rootroot00000000000000assertSame('FooClass', $invocation->className); } public function testAllowToGetMethodNameSetInConstructor() { $invocation = new PHPUnit_Framework_MockObject_Invocation_Static( 'FooClass', 'FooMethod', ['an_argument'], 'ReturnType' ); $this->assertSame('FooMethod', $invocation->methodName); } public function testAllowToGetMethodParametersSetInConstructor() { $expectedParameters = [ 'foo', 5, ['a', 'b'], new StdClass, null, false ]; $invocation = new PHPUnit_Framework_MockObject_Invocation_Static( 'FooClass', 'FooMethod', $expectedParameters, 'ReturnType' ); $this->assertSame($expectedParameters, $invocation->parameters); } public function testConstructorAllowToSetFlagCloneObjectsInParameters() { $parameters = [new StdClass]; $cloneObjects = true; $invocation = new PHPUnit_Framework_MockObject_Invocation_Static( 'FooClass', 'FooMethod', $parameters, 'ReturnType', $cloneObjects ); $this->assertEquals($parameters, $invocation->parameters); $this->assertNotSame($parameters, $invocation->parameters); } public function testAllowToGetReturnTypeSetInConstructor() { $expectedReturnType = 'string'; $invocation = new PHPUnit_Framework_MockObject_Invocation_Static( 'FooClass', 'FooMethod', ['an_argument'], $expectedReturnType ); $this->assertSame($expectedReturnType, $invocation->returnType); } } phpunit-mock-objects-3.0.6/tests/MockObject/Matcher/000077500000000000000000000000001263151441200223315ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/tests/MockObject/Matcher/ConsecutiveParametersTest.php000066400000000000000000000023011263151441200302110ustar00rootroot00000000000000getMock('stdClass', ['foo']); $mock ->expects($this->any()) ->method('foo') ->withConsecutive( ['bar'], [21, 42] ); $mock->foo('bar'); $mock->foo(21, 42); } public function testIntegrationWithLessAssertionsThenMethodCalls() { $mock = $this->getMock('stdClass', ['foo']); $mock ->expects($this->any()) ->method('foo') ->withConsecutive( ['bar'] ); $mock->foo('bar'); $mock->foo(21, 42); } public function testIntegrationExpectingException() { $mock = $this->getMock('stdClass', ['foo']); $mock ->expects($this->any()) ->method('foo') ->withConsecutive( ['bar'], [21, 42] ); $mock->foo('bar'); $this->setExpectedException('PHPUnit_Framework_ExpectationFailedException'); $mock->foo('invalid'); } } phpunit-mock-objects-3.0.6/tests/MockObject/abstract_class.phpt000066400000000000000000000070111263151441200246320ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true) --FILE-- generate( 'Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function one() { $arguments = array(); $count = func_num_args(); if ($count > 0) { $_arguments = func_get_args(); for ($i = 0; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'one', $arguments, '', $this, true ) ); return $result; } public function two() { $arguments = array(); $count = func_num_args(); if ($count > 0) { $_arguments = func_get_args(); for ($i = 0; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'two', $arguments, '', $this, true ) ); return $result; } protected function three() { $arguments = array(); $count = func_num_args(); if ($count > 0) { $_arguments = func_get_args(); for ($i = 0; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'three', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/class.phpt000066400000000000000000000057421263151441200227600ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true) --FILE-- generate( 'Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'bar', $arguments, '', $this, true ) ); return $result; } public function baz(Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'baz', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/class_call_parent_clone.phpt000066400000000000000000000035641263151441200265040ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true) --FILE-- generate( 'Foo', array(), 'MockFoo', true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); parent::__clone(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/class_call_parent_constructor.phpt000066400000000000000000000035351263151441200277670ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true) --FILE-- generate( 'Foo', array(), 'MockFoo', true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/class_dont_call_parent_clone.phpt000066400000000000000000000035331263151441200275240ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', false) --FILE-- generate( 'Foo', array(), 'MockFoo', false ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/class_dont_call_parent_constructor.phpt000066400000000000000000000035351263151441200310130ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true) --FILE-- generate( 'Foo', array(), 'MockFoo', true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } class_implementing_interface_call_parent_constructor.phpt000066400000000000000000000036541263151441200345020ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/tests/MockObject--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true) --FILE-- generate( 'Foo', array(), 'MockFoo', true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } class_implementing_interface_dont_call_parent_constructor.phpt000066400000000000000000000036541263151441200355260ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/tests/MockObject--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true) --FILE-- generate( 'Foo', array(), 'MockFoo', true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/class_partial.phpt000066400000000000000000000047111263151441200244670ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array('bar'), 'MockFoo', true, true) --FILE-- generate( 'Foo', array('bar'), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'bar', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/class_with_method_named_method.phpt000066400000000000000000000042301263151441200300460ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true) --FILE-- generate( 'Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function method() { $arguments = array(); $count = func_num_args(); if ($count > 0) { $_arguments = func_get_args(); for ($i = 0; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'method', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/class_with_method_with_variadic_arguments.phpt000066400000000000000000000052171263151441200323320ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('ClassWithMethodWithVariadicArguments', array(), 'MockFoo', true, true) --FILE-- generate( 'ClassWithMethodWithVariadicArguments', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends ClassWithMethodWithVariadicArguments implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function methodWithVariadicArguments($a, ...$parameters) { $arguments = array($a); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'ClassWithMethodWithVariadicArguments', 'methodWithVariadicArguments', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/interface.phpt000066400000000000000000000046021263151441200236050ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true) --FILE-- generate( 'Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo implements PHPUnit_Framework_MockObject_MockObject, Foo { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'bar', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/invocation_object_clone_object.phpt000066400000000000000000000057621263151441200300620ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true, true) --FILE-- generate( 'Foo', array(), 'MockFoo', true, true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'bar', $arguments, '', $this, true ) ); return $result; } public function baz(Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'baz', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/namespaced_class.phpt000066400000000000000000000060071263151441200251330ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), 'MockFoo', true, true) --FILE-- generate( 'NS\Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(NS\Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'NS\Foo', 'bar', $arguments, '', $this, true ) ); return $result; } public function baz(NS\Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'NS\Foo', 'baz', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/namespaced_class_call_parent_clone.phpt000066400000000000000000000036151263151441200306610ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), 'MockFoo', true) --FILE-- generate( 'NS\Foo', array(), 'MockFoo', true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); parent::__clone(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/namespaced_class_call_parent_constructor.phpt000066400000000000000000000035661263151441200321530ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), 'MockFoo', true) --FILE-- generate( 'NS\Foo', array(), 'MockFoo', true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/namespaced_class_dont_call_parent_clone.phpt000066400000000000000000000035641263151441200317100ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), 'MockFoo', false) --FILE-- generate( 'NS\Foo', array(), 'MockFoo', false ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/namespaced_class_dont_call_parent_constructor.phpt000066400000000000000000000035661263151441200331770ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), 'MockFoo', true) --FILE-- generate( 'NS\Foo', array(), 'MockFoo', true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } namespaced_class_implementing_interface_call_parent_constructor.phpt000066400000000000000000000037051263151441200366570ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/tests/MockObject--TEST-- PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), 'MockFoo', true) --FILE-- generate( 'NS\Foo', array(), 'MockFoo', true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } namespaced_class_implementing_interface_dont_call_parent_constructor.phpt000066400000000000000000000037051263151441200377030ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/tests/MockObject--TEST-- PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), 'MockFoo', true) --FILE-- generate( 'NS\Foo', array(), 'MockFoo', true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/namespaced_class_partial.phpt000066400000000000000000000047501263151441200266520ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array('bar'), 'MockFoo', true, true) --FILE-- generate( 'NS\Foo', array('bar'), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(NS\Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'NS\Foo', 'bar', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/namespaced_interface.phpt000066400000000000000000000046411263151441200257700ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('NS\Foo', array(), 'MockFoo', true, true) --FILE-- generate( 'NS\Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo implements PHPUnit_Framework_MockObject_MockObject, NS\Foo { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(NS\Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'NS\Foo', 'bar', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/nonexistent_class.phpt000066400000000000000000000035631263151441200254150ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('NonExistentClass', array(), 'MockFoo', true, true) --FILE-- generate( 'NonExistentClass', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class NonExistentClass { } class MockFoo extends NonExistentClass implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/nonexistent_class_with_namespace.phpt000066400000000000000000000035501263151441200304600ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true) --FILE-- generate( 'NS\Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- namespace NS { class Foo { } } namespace { class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } } nonexistent_class_with_namespace_starting_with_separator.phpt000066400000000000000000000035511263151441200354300ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/tests/MockObject--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true) --FILE-- generate( '\NS\Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- namespace NS { class Foo { } } namespace { class MockFoo extends NS\Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } } phpunit-mock-objects-3.0.6/tests/MockObject/proxy.phpt000066400000000000000000000061461263151441200230330ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', null, 'ProxyFoo', true, true, true, true) --FILE-- generate( 'Foo', array(), 'ProxyFoo', true, true, true, true ); print $mock['code']; ?> --EXPECTF-- class ProxyFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'bar', $arguments, '', $this, true ) ); return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $arguments); } public function baz(Foo $foo) { $arguments = array($foo); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'baz', $arguments, '', $this, true ) ); return call_user_func_array(array($this->__phpunit_originalObject, "baz"), $arguments); } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/return_type_declarations_object_method.phpt000066400000000000000000000050541263151441200316450ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true) --SKIPIF-- = 7.0.0 required'; ?> --FILE-- generate( 'Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(string $baz): Bar { $arguments = array($baz); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'bar', $arguments, 'Bar', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/return_type_declarations_self.phpt000066400000000000000000000050101263151441200277600ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true) --SKIPIF-- = 7.0.0 required'; ?> --FILE-- generate( 'Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo implements PHPUnit_Framework_MockObject_MockObject, Foo { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(string $baz): Foo { $arguments = array($baz); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'bar', $arguments, 'Foo', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/return_type_declarations_static_method.phpt000066400000000000000000000042121263151441200316610ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true) --SKIPIF-- = 7.0.0 required'; ?> --FILE-- generate( 'Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public static function bar(string $baz): Bar { throw new PHPUnit_Framework_MockObject_BadMethodCallException; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/scalar_type_declarations.phpt000066400000000000000000000050051263151441200267010ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generate('Foo', array(), 'MockFoo', true, true) --SKIPIF-- = 7.0.0 required'; ?> --FILE-- generate( 'Foo', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends Foo implements PHPUnit_Framework_MockObject_MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(string $baz) { $arguments = array($baz); $count = func_num_args(); if ($count > 1) { $_arguments = func_get_args(); for ($i = 1; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new PHPUnit_Framework_MockObject_Invocation_Object( 'Foo', 'bar', $arguments, '', $this, true ) ); return $result; } public function expects(PHPUnit_Framework_MockObject_Matcher_Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } 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()); } 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; } 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; } } } phpunit-mock-objects-3.0.6/tests/MockObject/wsdl_class.phpt000066400000000000000000000015761263151441200240120ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generateClassFromWsdl('GoogleSearch.wsdl', 'GoogleSearch') --SKIPIF-- --FILE-- generateClassFromWsdl( dirname(dirname(__FILE__)) . '/_fixture/GoogleSearch.wsdl', 'GoogleSearch' ); ?> --EXPECTF-- class GoogleSearch extends \SoapClient { public function __construct($wsdl, array $options) { parent::__construct('%s/GoogleSearch.wsdl', $options); } public function doGoogleSearch($key, $q, $start, $maxResults, $filter, $restrict, $safeSearch, $lr, $ie, $oe) { } public function doGetCachedPage($key, $url) { } public function doSpellingSuggestion($key, $phrase) { } } phpunit-mock-objects-3.0.6/tests/MockObject/wsdl_class_namespace.phpt000066400000000000000000000016361263151441200260230ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generateClassFromWsdl('GoogleSearch.wsdl', 'GoogleSearch') --SKIPIF-- --FILE-- generateClassFromWsdl( dirname(dirname(__FILE__)) . '/_fixture/GoogleSearch.wsdl', 'My\\Space\\GoogleSearch' ); ?> --EXPECTF-- namespace My\Space; class GoogleSearch extends \SoapClient { public function __construct($wsdl, array $options) { parent::__construct('%s/GoogleSearch.wsdl', $options); } public function doGoogleSearch($key, $q, $start, $maxResults, $filter, $restrict, $safeSearch, $lr, $ie, $oe) { } public function doGetCachedPage($key, $url) { } public function doSpellingSuggestion($key, $phrase) { } } phpunit-mock-objects-3.0.6/tests/MockObject/wsdl_class_partial.phpt000066400000000000000000000014621263151441200255200ustar00rootroot00000000000000--TEST-- PHPUnit_Framework_MockObject_Generator::generateClassFromWsdl('GoogleSearch.wsdl', 'GoogleSearch', array('doGoogleSearch')) --SKIPIF-- --FILE-- generateClassFromWsdl( dirname(dirname(__FILE__)) . '/_fixture/GoogleSearch.wsdl', 'GoogleSearch', array('doGoogleSearch') ); ?> --EXPECTF-- class GoogleSearch extends \SoapClient { public function __construct($wsdl, array $options) { parent::__construct('%s/GoogleSearch.wsdl', $options); } public function doGoogleSearch($key, $q, $start, $maxResults, $filter, $restrict, $safeSearch, $lr, $ie, $oe) { } } phpunit-mock-objects-3.0.6/tests/MockObjectTest.php000066400000000000000000000655471263151441200223400ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * @since Class available since Release 3.0.0 */ class Framework_MockObjectTest extends PHPUnit_Framework_TestCase { public function testMockedMethodIsNeverCalled() { $mock = $this->getMock('AnInterface'); $mock->expects($this->never()) ->method('doSomething'); } public function testMockedMethodIsNeverCalledWithParameter() { $mock = $this->getMock('SomeClass'); $mock->expects($this->never()) ->method('doSomething') ->with('someArg'); } public function testMockedMethodIsNotCalledWhenExpectsAnyWithParameter() { $mock = $this->getMock('SomeClass'); $mock->expects($this->any()) ->method('doSomethingElse') ->with('someArg'); } public function testMockedMethodIsNotCalledWhenMethodSpecifiedDirectlyWithParameter() { $mock = $this->getMock('SomeClass'); $mock->method('doSomethingElse') ->with('someArg'); } public function testMockedMethodIsCalledAtLeastOnce() { $mock = $this->getMock('AnInterface'); $mock->expects($this->atLeastOnce()) ->method('doSomething'); $mock->doSomething(); } public function testMockedMethodIsCalledAtLeastOnce2() { $mock = $this->getMock('AnInterface'); $mock->expects($this->atLeastOnce()) ->method('doSomething'); $mock->doSomething(); $mock->doSomething(); } public function testMockedMethodIsCalledAtLeastTwice() { $mock = $this->getMock('AnInterface'); $mock->expects($this->atLeast(2)) ->method('doSomething'); $mock->doSomething(); $mock->doSomething(); } public function testMockedMethodIsCalledAtLeastTwice2() { $mock = $this->getMock('AnInterface'); $mock->expects($this->atLeast(2)) ->method('doSomething'); $mock->doSomething(); $mock->doSomething(); $mock->doSomething(); } public function testMockedMethodIsCalledAtMostTwice() { $mock = $this->getMock('AnInterface'); $mock->expects($this->atMost(2)) ->method('doSomething'); $mock->doSomething(); $mock->doSomething(); } public function testMockedMethodIsCalledAtMosttTwice2() { $mock = $this->getMock('AnInterface'); $mock->expects($this->atMost(2)) ->method('doSomething'); $mock->doSomething(); } public function testMockedMethodIsCalledOnce() { $mock = $this->getMock('AnInterface'); $mock->expects($this->once()) ->method('doSomething'); $mock->doSomething(); } public function testMockedMethodIsCalledOnceWithParameter() { $mock = $this->getMock('SomeClass'); $mock->expects($this->once()) ->method('doSomethingElse') ->with($this->equalTo('something')); $mock->doSomethingElse('something'); } public function testMockedMethodIsCalledExactly() { $mock = $this->getMock('AnInterface'); $mock->expects($this->exactly(2)) ->method('doSomething'); $mock->doSomething(); $mock->doSomething(); } public function testStubbedException() { $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->will($this->throwException(new Exception)); try { $mock->doSomething(); } catch (Exception $e) { return; } $this->fail(); } public function testStubbedWillThrowException() { $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->willThrowException(new Exception); try { $mock->doSomething(); } catch (Exception $e) { return; } $this->fail(); } public function testStubbedReturnValue() { $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->will($this->returnValue('something')); $this->assertEquals('something', $mock->doSomething()); $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->willReturn('something'); $this->assertEquals('something', $mock->doSomething()); } public function testStubbedReturnValueMap() { $map = [ ['a', 'b', 'c', 'd'], ['e', 'f', 'g', 'h'] ]; $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->will($this->returnValueMap($map)); $this->assertEquals('d', $mock->doSomething('a', 'b', 'c')); $this->assertEquals('h', $mock->doSomething('e', 'f', 'g')); $this->assertEquals(null, $mock->doSomething('foo', 'bar')); $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->willReturnMap($map); $this->assertEquals('d', $mock->doSomething('a', 'b', 'c')); $this->assertEquals('h', $mock->doSomething('e', 'f', 'g')); $this->assertEquals(null, $mock->doSomething('foo', 'bar')); } public function testStubbedReturnArgument() { $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->will($this->returnArgument(1)); $this->assertEquals('b', $mock->doSomething('a', 'b')); $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->willReturnArgument(1); $this->assertEquals('b', $mock->doSomething('a', 'b')); } public function testFunctionCallback() { $mock = $this->getMock('SomeClass', ['doSomething'], [], '', false); $mock->expects($this->once()) ->method('doSomething') ->will($this->returnCallback('functionCallback')); $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); $mock = $this->getMock('SomeClass', ['doSomething'], [], '', false); $mock->expects($this->once()) ->method('doSomething') ->willReturnCallback('functionCallback'); $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); } public function testStubbedReturnSelf() { $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->will($this->returnSelf()); $this->assertEquals($mock, $mock->doSomething()); $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->willReturnSelf(); $this->assertEquals($mock, $mock->doSomething()); } public function testStubbedReturnOnConsecutiveCalls() { $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->will($this->onConsecutiveCalls('a', 'b', 'c')); $this->assertEquals('a', $mock->doSomething()); $this->assertEquals('b', $mock->doSomething()); $this->assertEquals('c', $mock->doSomething()); $mock = $this->getMock('AnInterface'); $mock->expects($this->any()) ->method('doSomething') ->willReturnOnConsecutiveCalls('a', 'b', 'c'); $this->assertEquals('a', $mock->doSomething()); $this->assertEquals('b', $mock->doSomething()); $this->assertEquals('c', $mock->doSomething()); } public function testStaticMethodCallback() { $mock = $this->getMock('SomeClass', ['doSomething'], [], '', false); $mock->expects($this->once()) ->method('doSomething') ->will($this->returnCallback(['MethodCallback', 'staticCallback'])); $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); } public function testPublicMethodCallback() { $mock = $this->getMock('SomeClass', ['doSomething'], [], '', false); $mock->expects($this->once()) ->method('doSomething') ->will($this->returnCallback([new MethodCallback, 'nonStaticCallback'])); $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); } public function testMockClassOnlyGeneratedOnce() { $mock1 = $this->getMock('AnInterface'); $mock2 = $this->getMock('AnInterface'); $this->assertEquals(get_class($mock1), get_class($mock2)); } public function testMockClassDifferentForPartialMocks() { $mock1 = $this->getMock('PartialMockTestClass'); $mock2 = $this->getMock('PartialMockTestClass', ['doSomething']); $mock3 = $this->getMock('PartialMockTestClass', ['doSomething']); $mock4 = $this->getMock('PartialMockTestClass', ['doAnotherThing']); $mock5 = $this->getMock('PartialMockTestClass', ['doAnotherThing']); $this->assertNotEquals(get_class($mock1), get_class($mock2)); $this->assertNotEquals(get_class($mock1), get_class($mock3)); $this->assertNotEquals(get_class($mock1), get_class($mock4)); $this->assertNotEquals(get_class($mock1), get_class($mock5)); $this->assertEquals(get_class($mock2), get_class($mock3)); $this->assertNotEquals(get_class($mock2), get_class($mock4)); $this->assertNotEquals(get_class($mock2), get_class($mock5)); $this->assertEquals(get_class($mock4), get_class($mock5)); } public function testMockClassStoreOverrulable() { $mock1 = $this->getMock('PartialMockTestClass'); $mock2 = $this->getMock('PartialMockTestClass', [], [], 'MyMockClassNameForPartialMockTestClass1'); $mock3 = $this->getMock('PartialMockTestClass'); $mock4 = $this->getMock('PartialMockTestClass', ['doSomething'], [], 'AnotherMockClassNameForPartialMockTestClass'); $mock5 = $this->getMock('PartialMockTestClass', [], [], 'MyMockClassNameForPartialMockTestClass2'); $this->assertNotEquals(get_class($mock1), get_class($mock2)); $this->assertEquals(get_class($mock1), get_class($mock3)); $this->assertNotEquals(get_class($mock1), get_class($mock4)); $this->assertNotEquals(get_class($mock2), get_class($mock3)); $this->assertNotEquals(get_class($mock2), get_class($mock4)); $this->assertNotEquals(get_class($mock2), get_class($mock5)); $this->assertNotEquals(get_class($mock3), get_class($mock4)); $this->assertNotEquals(get_class($mock3), get_class($mock5)); $this->assertNotEquals(get_class($mock4), get_class($mock5)); } /** * @covers PHPUnit_Framework_MockObject_Generator::getMock */ public function testGetMockWithFixedClassNameCanProduceTheSameMockTwice() { $mock = $this->getMockBuilder('StdClass')->setMockClassName('FixedName')->getMock(); $mock = $this->getMockBuilder('StdClass')->setMockClassName('FixedName')->getMock(); $this->assertInstanceOf('StdClass', $mock); } public function testOriginalConstructorSettingConsidered() { $mock1 = $this->getMock('PartialMockTestClass'); $mock2 = $this->getMock('PartialMockTestClass', [], [], '', false); $this->assertTrue($mock1->constructorCalled); $this->assertFalse($mock2->constructorCalled); } public function testOriginalCloneSettingConsidered() { $mock1 = $this->getMock('PartialMockTestClass'); $mock2 = $this->getMock('PartialMockTestClass', [], [], '', true, false); $this->assertNotEquals(get_class($mock1), get_class($mock2)); } public function testGetMockForAbstractClass() { $mock = $this->getMock('AbstractMockTestClass'); $mock->expects($this->never()) ->method('doSomething'); } public function traversableProvider() { return [ ['Traversable'], ['\Traversable'], ['TraversableMockTestInterface'], [['Traversable']], [['Iterator','Traversable']], [['\Iterator','\Traversable']] ]; } /** * @dataProvider traversableProvider */ public function testGetMockForTraversable($type) { $mock = $this->getMock($type); $this->assertInstanceOf('Traversable', $mock); } public function testMultipleInterfacesCanBeMockedInSingleObject() { $mock = $this->getMock(['AnInterface', 'AnotherInterface']); $this->assertInstanceOf('AnInterface', $mock); $this->assertInstanceOf('AnotherInterface', $mock); } public function testGetMockForTrait() { $mock = $this->getMockForTrait('AbstractTrait'); $mock->expects($this->never())->method('doSomething'); $parent = get_parent_class($mock); $traits = class_uses($parent, false); $this->assertContains('AbstractTrait', $traits); } public function testClonedMockObjectShouldStillEqualTheOriginal() { $a = $this->getMock('stdClass'); $b = clone $a; $this->assertEquals($a, $b); } public function testMockObjectsConstructedIndepentantlyShouldBeEqual() { $a = $this->getMock('stdClass'); $b = $this->getMock('stdClass'); $this->assertEquals($a, $b); } public function testMockObjectsConstructedIndepentantlyShouldNotBeTheSame() { $a = $this->getMock('stdClass'); $b = $this->getMock('stdClass'); $this->assertNotSame($a, $b); } public function testClonedMockObjectCanBeUsedInPlaceOfOriginalOne() { $x = $this->getMock('stdClass'); $y = clone $x; $mock = $this->getMock('stdClass', ['foo']); $mock->expects($this->once())->method('foo')->with($this->equalTo($x)); $mock->foo($y); } public function testClonedMockObjectIsNotIdenticalToOriginalOne() { $x = $this->getMock('stdClass'); $y = clone $x; $mock = $this->getMock('stdClass', ['foo']); $mock->expects($this->once())->method('foo')->with($this->logicalNot($this->identicalTo($x))); $mock->foo($y); } public function testObjectMethodCallWithArgumentCloningEnabled() { $expectedObject = new StdClass; $mock = $this->getMockBuilder('SomeClass') ->setMethods(['doSomethingElse']) ->enableArgumentCloning() ->getMock(); $actualArguments = []; $mock->expects($this->any()) ->method('doSomethingElse') ->will($this->returnCallback(function () use (&$actualArguments) { $actualArguments = func_get_args(); })); $mock->doSomethingElse($expectedObject); $this->assertEquals(1, count($actualArguments)); $this->assertEquals($expectedObject, $actualArguments[0]); $this->assertNotSame($expectedObject, $actualArguments[0]); } public function testObjectMethodCallWithArgumentCloningDisabled() { $expectedObject = new StdClass; $mock = $this->getMockBuilder('SomeClass') ->setMethods(['doSomethingElse']) ->disableArgumentCloning() ->getMock(); $actualArguments = []; $mock->expects($this->any()) ->method('doSomethingElse') ->will($this->returnCallback(function () use (&$actualArguments) { $actualArguments = func_get_args(); })); $mock->doSomethingElse($expectedObject); $this->assertEquals(1, count($actualArguments)); $this->assertSame($expectedObject, $actualArguments[0]); } public function testArgumentCloningOptionGeneratesUniqueMock() { $mockWithCloning = $this->getMockBuilder('SomeClass') ->setMethods(['doSomethingElse']) ->enableArgumentCloning() ->getMock(); $mockWithoutCloning = $this->getMockBuilder('SomeClass') ->setMethods(['doSomethingElse']) ->disableArgumentCloning() ->getMock(); $this->assertNotEquals($mockWithCloning, $mockWithoutCloning); } public function testVerificationOfMethodNameFailsWithoutParameters() { $mock = $this->getMock('SomeClass', ['right', 'wrong'], [], '', true, true, true); $mock->expects($this->once()) ->method('right'); $mock->wrong(); try { $mock->__phpunit_verify(); $this->fail('Expected exception'); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertSame( "Expectation failed for method name is equal to when invoked 1 time(s).\n" . "Method was expected to be called 1 times, actually called 0 times.\n", $e->getMessage() ); } $this->resetMockObjects(); } public function testVerificationOfMethodNameFailsWithParameters() { $mock = $this->getMock('SomeClass', ['right', 'wrong'], [], '', true, true, true); $mock->expects($this->once()) ->method('right'); $mock->wrong(); try { $mock->__phpunit_verify(); $this->fail('Expected exception'); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertSame( "Expectation failed for method name is equal to when invoked 1 time(s).\n" . "Method was expected to be called 1 times, actually called 0 times.\n", $e->getMessage() ); } $this->resetMockObjects(); } public function testVerificationOfMethodNameFailsWithWrongParameters() { $mock = $this->getMock('SomeClass', ['right', 'wrong'], [], '', true, true, true); $mock->expects($this->once()) ->method('right') ->with(['first', 'second']); try { $mock->right(['second']); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertSame( "Expectation failed for method name is equal to when invoked 1 time(s)\n" . "Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.\n" . 'Failed asserting that two arrays are equal.', $e->getMessage() ); } try { $mock->__phpunit_verify(); $this->fail('Expected exception'); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertSame( "Expectation failed for method name is equal to when invoked 1 time(s).\n" . "Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.\n" . "Failed asserting that two arrays are equal.\n" . "--- Expected\n" . "+++ Actual\n" . "@@ @@\n" . " Array (\n" . "- 0 => 'first'\n" . "- 1 => 'second'\n" . "+ 0 => 'second'\n" . " )\n", $e->getMessage() ); } $this->resetMockObjects(); } public function testVerificationOfNeverFailsWithEmptyParameters() { $mock = $this->getMock('SomeClass', ['right', 'wrong'], [], '', true, true, true); $mock->expects($this->never()) ->method('right') ->with(); try { $mock->right(); $this->fail('Expected exception'); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertSame( 'SomeClass::right() was not expected to be called.', $e->getMessage() ); } $this->resetMockObjects(); } public function testVerificationOfNeverFailsWithAnyParameters() { $mock = $this->getMock('SomeClass', ['right', 'wrong'], [], '', true, true, true); $mock->expects($this->never()) ->method('right') ->withAnyParameters(); try { $mock->right(); $this->fail('Expected exception'); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertSame( 'SomeClass::right() was not expected to be called.', $e->getMessage() ); } $this->resetMockObjects(); } /** * @ticket 199 */ public function testWithAnythingInsteadOfWithAnyParameters() { $mock = $this->getMock('SomeClass', ['right'], [], '', true, true, true); $mock->expects($this->once()) ->method('right') ->with($this->anything()); try { $mock->right(); $this->fail('Expected exception'); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertSame( "Expectation failed for method name is equal to when invoked 1 time(s)\n" . "Parameter count for invocation SomeClass::right() is too low.\n" . 'To allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead.', $e->getMessage() ); } $this->resetMockObjects(); } /** * See https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 */ public function testMockArgumentsPassedByReference() { $foo = $this->getMockBuilder('MethodCallbackByReference') ->setMethods(['bar']) ->disableOriginalConstructor() ->disableArgumentCloning() ->getMock(); $foo->expects($this->any()) ->method('bar') ->will($this->returnCallback([$foo, 'callback'])); $a = $b = $c = 0; $foo->bar($a, $b, $c); $this->assertEquals(1, $b); } /** * See https://github.com/sebastianbergmann/phpunit-mock-objects/issues/81 */ public function testMockArgumentsPassedByReference2() { $foo = $this->getMockBuilder('MethodCallbackByReference') ->disableOriginalConstructor() ->disableArgumentCloning() ->getMock(); $foo->expects($this->any()) ->method('bar') ->will($this->returnCallback( function (&$a, &$b, $c) { $b = 1; } )); $a = $b = $c = 0; $foo->bar($a, $b, $c); $this->assertEquals(1, $b); } /** * https://github.com/sebastianbergmann/phpunit-mock-objects/issues/116 */ public function testMockArgumentsPassedByReference3() { $foo = $this->getMockBuilder('MethodCallbackByReference') ->setMethods(['bar']) ->disableOriginalConstructor() ->disableArgumentCloning() ->getMock(); $a = new stdClass(); $b = $c = 0; $foo->expects($this->any()) ->method('bar') ->with($a, $b, $c) ->will($this->returnCallback([$foo, 'callback'])); $foo->bar($a, $b, $c); } /** * https://github.com/sebastianbergmann/phpunit/issues/796 */ public function testMockArgumentsPassedByReference4() { $foo = $this->getMockBuilder('MethodCallbackByReference') ->setMethods(['bar']) ->disableOriginalConstructor() ->disableArgumentCloning() ->getMock(); $a = new stdClass(); $b = $c = 0; $foo->expects($this->any()) ->method('bar') ->with($this->isInstanceOf('stdClass'), $b, $c) ->will($this->returnCallback([$foo, 'callback'])); $foo->bar($a, $b, $c); } /** * @requires extension soap */ public function testCreateMockFromWsdl() { $mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl', 'WsdlMock'); $this->assertStringStartsWith( 'Mock_WsdlMock_', get_class($mock) ); } /** * @requires extension soap */ public function testCreateNamespacedMockFromWsdl() { $mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl', 'My\\Space\\WsdlMock'); $this->assertStringStartsWith( 'Mock_WsdlMock_', get_class($mock) ); } /** * @requires extension soap */ public function testCreateTwoMocksOfOneWsdlFile() { $mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl'); $mock = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl'); } /** * @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/156 * @ticket 156 */ public function testInterfaceWithStaticMethodCanBeStubbed() { $this->assertInstanceOf( 'InterfaceWithStaticMethod', $this->getMock('InterfaceWithStaticMethod') ); } /** * @expectedException PHPUnit_Framework_MockObject_BadMethodCallException */ public function testInvokingStubbedStaticMethodRaisesException() { $mock = $this->getMock('ClassWithStaticMethod'); $mock->staticMethod(); } /** * @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/171 * @ticket 171 */ public function testStubForClassThatImplementsSerializableCanBeCreatedWithoutInvokingTheConstructor() { $this->assertInstanceOf( 'ClassThatImplementsSerializable', $this->getMockBuilder('ClassThatImplementsSerializable') ->disableOriginalConstructor() ->getMock() ); } private function resetMockObjects() { $refl = new ReflectionObject($this); $refl = $refl->getParentClass(); $prop = $refl->getProperty('mockObjects'); $prop->setAccessible(true); $prop->setValue($this, []); } public function testStringableClassDoesNotThrow() { $mock = $this->getMock('StringableClass'); $this->assertInternalType('string', (string) $mock); } public function testStringableClassCanBeMocked() { $mock = $this->getMock('StringableClass'); $mock->method('__toString')->willReturn('foo'); $this->assertSame('foo', (string) $mock); } } phpunit-mock-objects-3.0.6/tests/ProxyObjectTest.php000066400000000000000000000021441263151441200225500ustar00rootroot00000000000000 * * 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.0 */ class Framework_ProxyObjectTest extends PHPUnit_Framework_TestCase { public function testMockedMethodIsProxiedToOriginalMethod() { $proxy = $this->getMockBuilder('Bar') ->enableProxyingToOriginalMethods() ->getMock(); $proxy->expects($this->once()) ->method('doSomethingElse'); $foo = new Foo; $this->assertEquals('result', $foo->doSomething($proxy)); } public function testMockedMethodWithReferenceIsProxiedToOriginalMethod() { $proxy = $this->getMockBuilder('MethodCallbackByReference') ->enableProxyingToOriginalMethods() ->getMock(); $a = $b = $c = 0; $proxy->callback($a, $b, $c); $this->assertEquals(1, $b); } } phpunit-mock-objects-3.0.6/tests/_fixture/000077500000000000000000000000001263151441200205535ustar00rootroot00000000000000phpunit-mock-objects-3.0.6/tests/_fixture/AbstractMockTestClass.php000066400000000000000000000002741263151441200254720ustar00rootroot00000000000000 $value) { $this->{$key} = $value; } } } phpunit-mock-objects-3.0.6/tests/_fixture/ClassWithStaticMethod.php000066400000000000000000000001341263151441200254740ustar00rootroot00000000000000doSomethingElse(); } } phpunit-mock-objects-3.0.6/tests/_fixture/FunctionCallback.php000066400000000000000000000002041263151441200244620ustar00rootroot00000000000000 phpunit-mock-objects-3.0.6/tests/_fixture/InterfaceWithSemiReservedMethodName.php000066400000000000000000000001251263151441200302760ustar00rootroot00000000000000constructorArgs = [$arg1, $arg2]; } public function mockableMethod() { // something different from NULL return true; } public function anotherMockableMethod() { // something different from NULL return true; } public function __clone() { $this->cloned = true; } } phpunit-mock-objects-3.0.6/tests/_fixture/PartialMockTestClass.php000066400000000000000000000004051263151441200253170ustar00rootroot00000000000000constructorCalled = true; } public function doSomething() { } public function doAnotherThing() { } } phpunit-mock-objects-3.0.6/tests/_fixture/SingletonClass.php000066400000000000000000000005151263151441200242150ustar00rootroot00000000000000