pax_global_header00006660000000000000000000000064132240612110014502gustar00rootroot0000000000000052 comment=33fd41a76e746b8fa96d00b49a23dadfa8334cdf phpunit-mock-objects-5.0.6/000077500000000000000000000000001322406121100155575ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/.gitattributes000066400000000000000000000000171322406121100204500ustar00rootroot00000000000000*.php diff=php phpunit-mock-objects-5.0.6/.github/000077500000000000000000000000001322406121100171175ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/.github/ISSUE_TEMPLATE.md000066400000000000000000000011321322406121100216210ustar00rootroot00000000000000| Q | A | -----------------------------| --------------- | phpunit-mock-objects version | x.y.z | PHPUnit version | x.y.z | PHP version | x.y.z | Installation Method | Composer / PHAR phpunit-mock-objects-5.0.6/.gitignore000066400000000000000000000000551322406121100175470ustar00rootroot00000000000000/.idea /.php_cs.cache /composer.lock /vendor phpunit-mock-objects-5.0.6/.php_cs000066400000000000000000000062151322406121100170400ustar00rootroot00000000000000 For the full copyright and license information, please view the LICENSE file that was distributed with this source code. EOF; return PhpCsFixer\Config::create() ->setRiskyAllowed(true) ->setRules( [ 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => [ 'align_double_arrow' => true, 'align_equals' => true ], 'blank_line_after_namespace' => true, 'blank_line_before_statement' => [ 'statements' => [ 'break', 'continue', 'return', 'throw', 'try', ], ], 'braces' => true, 'cast_spaces' => true, 'concat_space' => ['spacing' => 'one'], 'elseif' => true, 'encoding' => true, 'full_opening_tag' => true, 'function_declaration' => true, 'header_comment' => ['header' => $header, 'separate' => 'none'], 'indentation_type' => true, 'line_ending' => true, 'lowercase_constants' => true, 'lowercase_keywords' => true, 'method_argument_space' => true, 'native_function_invocation' => true, 'no_alias_functions' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, 'no_closing_tag' => true, 'no_empty_phpdoc' => true, 'no_empty_statement' => true, 'no_extra_consecutive_blank_lines' => true, 'no_leading_namespace_whitespace' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_after_function_name' => true, 'no_spaces_inside_parenthesis' => true, 'no_trailing_comma_in_list_call' => true, 'no_trailing_whitespace' => true, 'no_unused_imports' => true, 'no_whitespace_in_blank_line' => true, 'ordered_imports' => true, 'phpdoc_align' => true, 'phpdoc_indent' => true, 'phpdoc_no_access' => true, 'phpdoc_no_empty_return' => true, 'phpdoc_no_package' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'phpdoc_types' => true, 'phpdoc_var_without_name' => true, 'self_accessor' => true, 'simplified_null_return' => true, 'single_blank_line_at_eof' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, 'single_quote' => true, 'ternary_operator_spaces' => true, 'trim_array_spaces' => true, 'visibility_required' => true, ] ) ->setFinder( PhpCsFixer\Finder::create() ->files() ->in(__DIR__ . '/src') ->name('*.php') ); phpunit-mock-objects-5.0.6/.travis.yml000066400000000000000000000012511322406121100176670ustar00rootroot00000000000000language: php sudo: false php: - 7.0 - 7.1 - 7.2 - master env: matrix: - DEPENDENCIES="high" - DEPENDENCIES="low" global: - DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest" before_install: - composer self-update - composer clear-cache install: - if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS; fi - if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi script: - ./vendor/bin/phpunit --coverage-clover=coverage.xml after_success: - bash <(curl -s https://codecov.io/bash) notifications: email: false phpunit-mock-objects-5.0.6/CONTRIBUTING.md000066400000000000000000000003471322406121100200140ustar00rootroot00000000000000Please refer to [https://github.com/sebastianbergmann/phpunit/blob/master/.github/CONTRIBUTING.md](https://github.com/sebastianbergmann/phpunit/blob/master/.github/CONTRIBUTING.md) for details on how to contribute to this project. phpunit-mock-objects-5.0.6/LICENSE000066400000000000000000000030231322406121100165620ustar00rootroot00000000000000phpunit-mock-objects Copyright (c) 2002-2017, 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-5.0.6/README.md000066400000000000000000000010431322406121100170340ustar00rootroot00000000000000[![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) [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.0-8892BF.svg?style=flat-square)](https://php.net/) [![Build Status](https://img.shields.io/travis/sebastianbergmann/phpunit-mock-objects/master.svg?style=flat-square)](https://phpunit.de/build-status.html) # phpunit-mock-objects **phpunit-mock-objects** is the default mock object library for PHPUnit. phpunit-mock-objects-5.0.6/build.xml000066400000000000000000000013011322406121100173730ustar00rootroot00000000000000 phpunit-mock-objects-5.0.6/composer.json000066400000000000000000000024011322406121100202760ustar00rootroot00000000000000{ "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": "sebastian@phpunit.de", "role": "lead" } ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit-mock-objects/issues" }, "prefer-stable": true, "require": { "php": "^7.0", "phpunit/php-text-template": "^1.2.1", "doctrine/instantiator": "^1.0.5", "sebastian/exporter": "^3.1" }, "require-dev": { "phpunit/phpunit": "^6.5" }, "conflict": { "phpunit/phpunit": "<6.0" }, "config": { "optimize-autoloader": true, "sort-packages": true }, "suggest": { "ext-soap": "*" }, "autoload": { "classmap": [ "src/" ] }, "autoload-dev": { "classmap": [ "tests/_fixture/" ] }, "extra": { "branch-alias": { "dev-master": "5.0.x-dev" } } } phpunit-mock-objects-5.0.6/phpunit.xml000066400000000000000000000016071322406121100177740ustar00rootroot00000000000000 tests tests src phpunit-mock-objects-5.0.6/src/000077500000000000000000000000001322406121100163465ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/src/Builder/000077500000000000000000000000001322406121100177345ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/src/Builder/Identity.php000066400000000000000000000015641322406121100222440ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; /** * 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(). */ interface Identity { /** * Sets the identification of the expectation to $id. * * @note The identifier is unique per mock object. * * @param string $id Unique identification of expectation. */ public function id($id); } phpunit-mock-objects-5.0.6/src/Builder/InvocationMocker.php000066400000000000000000000155031322406121100237230ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\MockObject\Matcher\Invocation; use PHPUnit\Framework\MockObject\RuntimeException; use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Stub\MatcherCollection; /** * 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. */ class InvocationMocker implements MethodNameMatch { /** * @var MatcherCollection */ private $collection; /** * @var Matcher */ private $matcher; /** * @var string[] */ private $configurableMethods = []; /** * @param MatcherCollection $collection * @param Invocation $invocationMatcher * @param array $configurableMethods */ public function __construct(MatcherCollection $collection, Invocation $invocationMatcher, array $configurableMethods) { $this->collection = $collection; $this->matcher = new Matcher($invocationMatcher); $this->collection->addMatcher($this->matcher); $this->configurableMethods = $configurableMethods; } /** * @return Matcher */ public function getMatcher() { return $this->matcher; } /** * @param mixed $id * * @return InvocationMocker */ public function id($id) { $this->collection->registerId($id, $this); return $this; } /** * @param Stub $stub * * @return InvocationMocker */ public function will(Stub $stub) { $this->matcher->setStub($stub); return $this; } /** * @param mixed $value * @param mixed $nextValues, ... * * @return InvocationMocker */ public function willReturn($value, ...$nextValues) { if (\count($nextValues) === 0) { $stub = new Stub\ReturnStub($value); } else { $stub = new Stub\ConsecutiveCalls( \array_merge([$value], $nextValues) ); } return $this->will($stub); } /** * @param mixed $reference * * @return InvocationMocker */ public function willReturnReference(&$reference) { $stub = new Stub\ReturnReference($reference); return $this->will($stub); } /** * @param array $valueMap * * @return InvocationMocker */ public function willReturnMap(array $valueMap) { $stub = new Stub\ReturnValueMap($valueMap); return $this->will($stub); } /** * @param mixed $argumentIndex * * @return InvocationMocker */ public function willReturnArgument($argumentIndex) { $stub = new Stub\ReturnArgument($argumentIndex); return $this->will($stub); } /** * @param callable $callback * * @return InvocationMocker */ public function willReturnCallback($callback) { $stub = new Stub\ReturnCallback($callback); return $this->will($stub); } /** * @return InvocationMocker */ public function willReturnSelf() { $stub = new Stub\ReturnSelf; return $this->will($stub); } /** * @param mixed $values, ... * * @return InvocationMocker */ public function willReturnOnConsecutiveCalls(...$values) { $stub = new Stub\ConsecutiveCalls($values); return $this->will($stub); } /** * @param \Exception $exception * * @return InvocationMocker */ public function willThrowException(\Exception $exception) { $stub = new Stub\Exception($exception); return $this->will($stub); } /** * @param mixed $id * * @return InvocationMocker */ public function after($id) { $this->matcher->setAfterMatchBuilderId($id); return $this; } /** * @param array ...$arguments * * @return InvocationMocker * * @throws RuntimeException */ public function with(...$arguments) { $this->canDefineParameters(); $this->matcher->setParametersMatcher(new Matcher\Parameters($arguments)); return $this; } /** * @param array ...$arguments * * @return InvocationMocker * * @throws RuntimeException */ public function withConsecutive(...$arguments) { $this->canDefineParameters(); $this->matcher->setParametersMatcher(new Matcher\ConsecutiveParameters($arguments)); return $this; } /** * @return InvocationMocker * * @throws RuntimeException */ public function withAnyParameters() { $this->canDefineParameters(); $this->matcher->setParametersMatcher(new Matcher\AnyParameters); return $this; } /** * @param Constraint|string $constraint * * @return InvocationMocker * * @throws RuntimeException */ public function method($constraint) { if ($this->matcher->hasMethodNameMatcher()) { throw new RuntimeException( 'Method name matcher is already defined, cannot redefine' ); } if (\is_string($constraint) && !\in_array(\strtolower($constraint), $this->configurableMethods)) { throw new RuntimeException( \sprintf( 'Trying to configure method "%s" which cannot be configured because it does not exist, has not been specified, is final, or is static', $constraint ) ); } $this->matcher->setMethodNameMatcher(new Matcher\MethodName($constraint)); return $this; } /** * Validate that a parameters matcher can be defined, throw exceptions otherwise. * * @throws RuntimeException */ private function canDefineParameters() { if (!$this->matcher->hasMethodNameMatcher()) { throw new RuntimeException( 'Method name matcher is not defined, cannot define parameter ' . 'matcher without one' ); } if ($this->matcher->hasParametersMatcher()) { throw new RuntimeException( 'Parameter matcher is already defined, cannot redefine' ); } } } phpunit-mock-objects-5.0.6/src/Builder/Match.php000066400000000000000000000012441322406121100215020ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; /** * Builder interface for invocation order matches. */ interface Match extends 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 Stub */ public function after($id); } phpunit-mock-objects-5.0.6/src/Builder/MethodNameMatch.php000066400000000000000000000014341322406121100234450ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; /** * Builder interface for matcher of method names. */ interface MethodNameMatch extends ParametersMatch { /** * Adds a new method name match and returns the parameter match object for * further matching possibilities. * * @param \PHPUnit\Framework\Constraint\Constraint $name Constraint for matching method, if a string is passed it will use the PHPUnit_Framework_Constraint_IsEqual * * @return ParametersMatch */ public function method($name); } phpunit-mock-objects-5.0.6/src/Builder/NamespaceMatch.php000066400000000000000000000020711322406121100233160ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; /** * Interface for builders which can register builders with a given identification. * * This interface relates to Identity. */ interface NamespaceMatch { /** * Looks up the match builder with identification $id and returns it. * * @param string $id The identification of the match builder * * @return 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 Match $builder The builder which is being registered */ public function registerId($id, Match $builder); } phpunit-mock-objects-5.0.6/src/Builder/ParametersMatch.php000066400000000000000000000026751322406121100235370ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; use PHPUnit\Framework\MockObject\Matcher\AnyParameters; /** * Builder interface for parameter matchers. */ interface ParametersMatch extends Match { /** * Sets the parameters to match for, each parameter to this function will * be part of match. To perform specific matches or constraints create a * new PHPUnit\Framework\Constraint\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 ParametersMatch */ public function with(...$arguments); /** * Sets a matcher which allows any kind of parameters. * * Some examples: * * // match any number of parameters * $b->withAnyParameters(); * * * @return AnyParameters */ public function withAnyParameters(); } phpunit-mock-objects-5.0.6/src/Builder/Stub.php000066400000000000000000000013501322406121100213610ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Builder; use PHPUnit\Framework\MockObject\Stub as BaseStub; /** * Builder interface for stubs which are actions replacing an invocation. */ interface Stub extends 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 BaseStub $stub * * @return Identity */ public function will(BaseStub $stub); } phpunit-mock-objects-5.0.6/src/Exception/000077500000000000000000000000001322406121100203045ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/src/Exception/BadMethodCallException.php000066400000000000000000000005741322406121100253250ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; class BadMethodCallException extends \BadMethodCallException implements Exception { } phpunit-mock-objects-5.0.6/src/Exception/Exception.php000066400000000000000000000005761322406121100227630ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * Interface for exceptions used by PHPUnit_MockObject. */ interface Exception { } phpunit-mock-objects-5.0.6/src/Exception/RuntimeException.php000066400000000000000000000005601322406121100243200ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; class RuntimeException extends \RuntimeException implements Exception { } phpunit-mock-objects-5.0.6/src/ForwardCompatibility/000077500000000000000000000000001322406121100225045ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/src/ForwardCompatibility/MockObject.php000066400000000000000000000006361322406121100252420ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use PHPUnit_Framework_MockObject_MockObject; interface MockObject extends PHPUnit_Framework_MockObject_MockObject { } phpunit-mock-objects-5.0.6/src/Generator.php000066400000000000000000001131651322406121100210140ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use Doctrine\Instantiator\Exception\ExceptionInterface as InstantiatorException; use Doctrine\Instantiator\Instantiator; use Iterator; use IteratorAggregate; use PHPUnit\Framework\Exception; use PHPUnit\Util\InvalidArgumentHelper; use ReflectionClass; use ReflectionException; use ReflectionMethod; use SoapClient; use Text_Template; use Traversable; /** * Mock Object Code Generator */ class Generator { /** * @var array */ private static $cache = []; /** * @var Text_Template[] */ private static $templates = []; /** * @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 string|string[] $type * @param array $methods * @param array $arguments * @param string $mockClassName * @param bool $callOriginalConstructor * @param bool $callOriginalClone * @param bool $callAutoload * @param bool $cloneArguments * @param bool $callOriginalMethods * @param object $proxyTarget * @param bool $allowMockingUnknownTypes * * @return MockObject * * @throws Exception * @throws RuntimeException * @throws \PHPUnit\Framework\Exception * @throws \ReflectionException */ public function getMock($type, $methods = [], array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = true, $callOriginalMethods = false, $proxyTarget = null, $allowMockingUnknownTypes = true) { if (!\is_array($type) && !\is_string($type)) { throw InvalidArgumentHelper::factory(1, 'array or string'); } if (!\is_string($mockClassName)) { throw InvalidArgumentHelper::factory(4, 'string'); } if (!\is_array($methods) && null !== $methods) { throw InvalidArgumentHelper::factory(2, 'array', $methods); } if ($type === 'Traversable' || $type === '\\Traversable') { $type = 'Iterator'; } if (\is_array($type)) { $type = \array_unique( \array_map( function ($type) { if ($type === 'Traversable' || $type === '\\Traversable' || $type === '\\Iterator') { return 'Iterator'; } return $type; }, $type ) ); } if (!$allowMockingUnknownTypes) { if (\is_array($type)) { foreach ($type as $_type) { if (!\class_exists($_type, $callAutoload) && !\interface_exists($_type, $callAutoload)) { throw new RuntimeException( \sprintf( 'Cannot stub or mock class or interface "%s" which does not exist', $_type ) ); } } } else { if (!\class_exists($type, $callAutoload) && !\interface_exists($type, $callAutoload) ) { throw new RuntimeException( \sprintf( 'Cannot stub or mock class or interface "%s" which does not exist', $type ) ); } } } if (null !== $methods) { foreach ($methods as $method) { if (!\preg_match('~[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*~', $method)) { throw new RuntimeException( \sprintf( 'Cannot stub or mock method with invalid name "%s"', $method ) ); } } if ($methods !== \array_unique($methods)) { throw new RuntimeException( \sprintf( 'Cannot stub or mock using a method list that contains duplicates: "%s" (duplicate: "%s")', \implode(', ', $methods), \implode(', ', \array_unique(\array_diff_assoc($methods, \array_unique($methods)))) ) ); } } if ($mockClassName !== '' && \class_exists($mockClassName, false)) { $reflect = new ReflectionClass($mockClassName); if (!$reflect->implementsInterface(MockObject::class)) { throw new RuntimeException( \sprintf( 'Class "%s" already exists.', $mockClassName ) ); } } if ($callOriginalConstructor === false && $callOriginalMethods === true) { throw new 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 MockObject * * @throws \ReflectionException * @throws RuntimeException */ 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 (InstantiatorException $exception) { throw new 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 MockObject * * @throws \ReflectionException * @throws RuntimeException * @throws Exception */ public function getMockForAbstractClass($originalClassName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = true) { if (!\is_string($originalClassName)) { throw InvalidArgumentHelper::factory(1, 'string'); } if (!\is_string($mockClassName)) { throw 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 ); } throw new 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 MockObject * * @throws \ReflectionException * @throws RuntimeException * @throws Exception */ public function getMockForTrait($traitName, array $arguments = [], $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = [], $cloneArguments = true) { if (!\is_string($traitName)) { throw InvalidArgumentHelper::factory(1, 'string'); } if (!\is_string($mockClassName)) { throw InvalidArgumentHelper::factory(3, 'string'); } if (!\trait_exists($traitName, $callAutoload)) { throw new RuntimeException( \sprintf( 'Trait "%s" does not exist.', $traitName ) ); } $className = $this->generateClassName( $traitName, '', 'Trait_' ); $classTemplate = $this->getTemplate('trait_class.tpl'); $classTemplate->setVar( [ 'prologue' => 'abstract ', 'class_name' => $className['className'], 'trait_name' => $traitName ] ); $this->evalClass( $classTemplate->render(), $className['className'] ); return $this->getMockForAbstractClass($className['className'], $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $mockedMethods, $cloneArguments); } /** * Returns an object for the specified trait. * * @param string $traitName * @param array $arguments * @param string $traitClassName * @param bool $callOriginalConstructor * @param bool $callOriginalClone * @param bool $callAutoload * * @return object * * @throws \ReflectionException * @throws RuntimeException * @throws Exception */ public function getObjectForTrait($traitName, array $arguments = [], $traitClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true) { if (!\is_string($traitName)) { throw InvalidArgumentHelper::factory(1, 'string'); } if (!\is_string($traitClassName)) { throw InvalidArgumentHelper::factory(3, 'string'); } if (!\trait_exists($traitName, $callAutoload)) { throw new RuntimeException( \sprintf( 'Trait "%s" does not exist.', $traitName ) ); } $className = $this->generateClassName( $traitName, $traitClassName, 'Trait_' ); $classTemplate = $this->getTemplate('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 * * @throws \ReflectionException * @throws \PHPUnit\Framework\MockObject\RuntimeException */ 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 RuntimeException */ public function generateClassFromWsdl($wsdlFile, $className, array $methods = [], array $options = []) { if (!\extension_loaded('soap')) { throw new 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); $methodTemplate = $this->getTemplate('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 ) ); foreach (\range(0, \count($args) - 1) as $i) { $args[$i] = \substr($args[$i], \strpos($args[$i], '$')); } $methodTemplate->setVar( [ 'method_name' => $name, 'arguments' => \implode(', ', $args) ] ); $methodsBuffer .= $methodTemplate->render(); } } $optionsBuffer = 'array('; foreach ($options as $key => $value) { $optionsBuffer .= $key . ' => ' . $value; } $optionsBuffer .= ')'; $classTemplate = $this->getTemplate('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 \InvalidArgumentException * @throws \ReflectionException * @throws RuntimeException */ private function generateMock($type, $methods, $mockClassName, $callOriginalClone, $callAutoload, $cloneArguments, $callOriginalMethods) { $methodReflections = []; $classTemplate = $this->getTemplate('mocked_class.tpl'); $additionalInterfaces = []; $cloneTemplate = ''; $isClass = false; $isInterface = false; $isMultipleInterfaces = false; if (\is_array($type)) { foreach ($type as $_type) { if (!\interface_exists($_type, $callAutoload)) { throw new RuntimeException( \sprintf( 'Interface "%s" does not exist.', $_type ) ); } $isMultipleInterfaces = true; $additionalInterfaces[] = $_type; $typeClass = new ReflectionClass($this->generateClassName( $_type, $mockClassName, 'Mock_' )['fullClassName'] ); foreach ($this->getClassMethods($_type) as $method) { if (\in_array($method, $methods)) { throw new RuntimeException( \sprintf( 'Duplicate method "%s" not allowed.', $method ) ); } $methodReflections[$method] = $typeClass->getMethod($method); $methods[] = $method; } } } $mockClassName = $this->generateClassName( $type, $mockClassName, 'Mock_' ); if (\class_exists($mockClassName['fullClassName'], $callAutoload)) { $isClass = true; } elseif (\interface_exists($mockClassName['fullClassName'], $callAutoload)) { $isInterface = true; } if (!$isClass && !$isInterface) { $prologue = 'class ' . $mockClassName['originalClassName'] . "\n{\n}\n\n"; if (!empty($mockClassName['namespaceName'])) { $prologue = 'namespace ' . $mockClassName['namespaceName'] . " {\n\n" . $prologue . "}\n\n" . "namespace {\n\n"; $epilogue = "\n\n}"; } $cloneTemplate = $this->getTemplate('mocked_clone.tpl'); } else { $class = new ReflectionClass($mockClassName['fullClassName']); if ($class->isFinal()) { throw new RuntimeException( \sprintf( 'Class "%s" is declared "final" and cannot be mocked.', $mockClassName['fullClassName'] ) ); } if ($class->hasMethod('__clone')) { $cloneMethod = $class->getMethod('__clone'); if (!$cloneMethod->isFinal()) { if ($callOriginalClone && !$isInterface) { $cloneTemplate = $this->getTemplate('unmocked_clone.tpl'); } else { $cloneTemplate = $this->getTemplate('mocked_clone.tpl'); } } } else { $cloneTemplate = $this->getTemplate('mocked_clone.tpl'); } } if (\is_object($cloneTemplate)) { $cloneTemplate = $cloneTemplate->render(); } if (\is_array($methods) && empty($methods) && ($isClass || $isInterface)) { $methods = $this->getClassMethods($mockClassName['fullClassName']); } if (!\is_array($methods)) { $methods = []; } $mockedMethods = ''; $configurable = []; foreach ($methods as $methodName) { if ($methodName !== '__construct' && $methodName !== '__clone') { $configurable[] = \strtolower($methodName); } } if (isset($class)) { // https://github.com/sebastianbergmann/phpunit-mock-objects/issues/103 if ($isInterface && $class->implementsInterface(Traversable::class) && !$class->implementsInterface(Iterator::class) && !$class->implementsInterface(IteratorAggregate::class)) { $additionalInterfaces[] = Iterator::class; $methods = \array_merge($methods, $this->getClassMethods(Iterator::class)); } foreach ($methods as $methodName) { try { $method = $class->getMethod($methodName); if ($this->canMockMethod($method)) { $mockedMethods .= $this->generateMockedMethodDefinitionFromExisting( $method, $cloneArguments, $callOriginalMethods ); } } catch (ReflectionException $e) { $mockedMethods .= $this->generateMockedMethodDefinition( $mockClassName['fullClassName'], $methodName, $cloneArguments ); } } } elseif ($isMultipleInterfaces) { foreach ($methods as $methodName) { if ($this->canMockMethod($methodReflections[$methodName])) { $mockedMethods .= $this->generateMockedMethodDefinitionFromExisting( $methodReflections[$methodName], $cloneArguments, $callOriginalMethods ); } } } else { foreach ($methods as $methodName) { $mockedMethods .= $this->generateMockedMethodDefinition( $mockClassName['fullClassName'], $methodName, $cloneArguments ); } } $method = ''; if (!\in_array('method', $methods) && (!isset($class) || !$class->hasMethod('method'))) { $methodTemplate = $this->getTemplate('mocked_class_method.tpl'); $method = $methodTemplate->render(); } $classTemplate->setVar( [ 'prologue' => $prologue ?? '', 'epilogue' => $epilogue ?? '', 'class_declaration' => $this->generateMockClassDeclaration( $mockClassName, $isInterface, $additionalInterfaces ), 'clone' => $cloneTemplate, 'mock_class_name' => $mockClassName['className'], 'mocked_methods' => $mockedMethods, 'method' => $method, 'configurable' => '[' . \implode(', ', \array_map(function ($m) { return '\'' . $m . '\''; }, $configurable)) . ']' ] ); return [ 'code' => $classTemplate->render(), 'mockClassName' => $mockClassName['className'] ]; } /** * @param array|string $type * @param string $className * @param string $prefix * * @return array */ private function generateClassName($type, $className, $prefix) { if (\is_array($type)) { $type = \implode('_', $type); } if ($type[0] === '\\') { $type = \substr($type, 1); } $classNameParts = \explode('\\', $type); if (\count($classNameParts) > 1) { $type = \array_pop($classNameParts); $namespaceName = \implode('\\', $classNameParts); $fullClassName = $namespaceName . '\\' . $type; } else { $namespaceName = ''; $fullClassName = $type; } if ($className === '') { do { $className = $prefix . $type . '_' . \substr(\md5(\mt_rand()), 0, 8); } while (\class_exists($className, false)); } return [ 'className' => $className, 'originalClassName' => $type, 'fullClassName' => $fullClassName, 'namespaceName' => $namespaceName ]; } /** * @param array $mockClassName * @param bool $isInterface * @param array $additionalInterfaces * * @return string */ private function generateMockClassDeclaration(array $mockClassName, $isInterface, array $additionalInterfaces = []) { $buffer = 'class '; $additionalInterfaces[] = MockObject::class; $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 ReflectionMethod $method * @param bool $cloneArguments * @param bool $callOriginalMethods * * @return string * * @throws \PHPUnit\Framework\MockObject\RuntimeException */ private function generateMockedMethodDefinitionFromExisting(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 ($method->hasReturnType()) { $returnType = (string) $method->getReturnType(); } else { $returnType = ''; } if (\preg_match('#\*[ \t]*+@deprecated[ \t]*+(.*?)\r?+\n[ \t]*+\*(?:[ \t]*+@|/$)#s', $method->getDocComment(), $deprecation)) { $deprecation = \trim(\preg_replace('#[ \t]*\r?\n[ \t]*+\*[ \t]*+#', ' ', $deprecation[1])); } else { $deprecation = false; } return $this->generateMockedMethodDefinition( $method->getDeclaringClass()->getName(), $method->getName(), $cloneArguments, $modifier, $this->getMethodParameters($method), $this->getMethodParameters($method, true), $returnType, $reference, $callOriginalMethods, $method->isStatic(), $deprecation, $method->hasReturnType() && PHP_VERSION_ID >= 70100 && $method->getReturnType()->allowsNull() ); } /** * @param string $className * @param string $methodName * @param bool $cloneArguments * @param string $modifier * @param string $argumentsForDeclaration * @param string $argumentsForCall * @param string $returnType * @param string $reference * @param bool $callOriginalMethods * @param bool $static * @param bool|string $deprecation * @param bool $allowsReturnNull * * @return string * * @throws \InvalidArgumentException */ private function generateMockedMethodDefinition($className, $methodName, $cloneArguments = true, $modifier = 'public', $argumentsForDeclaration = '', $argumentsForCall = '', $returnType = '', $reference = '', $callOriginalMethods = false, $static = false, $deprecation = false, $allowsReturnNull = false) { if ($static) { $templateFile = 'mocked_static_method.tpl'; } else { if ($returnType === 'void') { $templateFile = \sprintf( '%s_method_void.tpl', $callOriginalMethods ? 'proxied' : 'mocked' ); } else { $templateFile = \sprintf( '%s_method.tpl', $callOriginalMethods ? 'proxied' : 'mocked' ); } } // Mocked interfaces returning 'self' must explicitly declare the // interface name as the return type. See // https://bugs.php.net/bug.php?id=70722 if ($returnType === 'self') { $returnType = $className; } if (false !== $deprecation) { $deprecation = "The $className::$methodName method is deprecated ($deprecation)."; $deprecationTemplate = $this->getTemplate('deprecation.tpl'); $deprecationTemplate->setVar( [ 'deprecation' => \var_export($deprecation, true), ] ); $deprecation = $deprecationTemplate->render(); } $template = $this->getTemplate($templateFile); $template->setVar( [ 'arguments_decl' => $argumentsForDeclaration, 'arguments_call' => $argumentsForCall, 'return_delim' => $returnType ? ': ' : '', 'return_type' => $allowsReturnNull ? '?' . $returnType : $returnType, 'arguments_count' => !empty($argumentsForCall) ? \substr_count($argumentsForCall, ',') + 1 : 0, 'class_name' => $className, 'method_name' => $methodName, 'modifier' => $modifier, 'reference' => $reference, 'clone_arguments' => $cloneArguments ? 'true' : 'false', 'deprecation' => $deprecation ] ); return $template->render(); } /** * @param ReflectionMethod $method * * @return bool * * @throws \ReflectionException */ private function canMockMethod(ReflectionMethod $method) { return !($method->isConstructor() || $method->isFinal() || $method->isPrivate() || $this->isMethodNameBlacklisted($method->getName())); } /** * Returns whether a method name is blacklisted * * @param string $name * * @return bool */ private function isMethodNameBlacklisted($name) { return isset($this->blacklistedMethodNames[$name]); } /** * Returns the parameters of a function or method. * * @param ReflectionMethod $method * @param bool $forCall * * @return string * * @throws RuntimeException */ 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 ($parameter->isVariadic()) { if ($forCall) { continue; } $name = '...' . $name; } $nullable = ''; $default = ''; $reference = ''; $typeDeclaration = ''; if (!$forCall) { if (PHP_VERSION_ID >= 70100 && $parameter->hasType() && $parameter->allowsNull()) { $nullable = '?'; } if ($parameter->hasType() && (string) $parameter->getType() !== 'self') { $typeDeclaration = (string) $parameter->getType() . ' '; } elseif ($parameter->isArray()) { $typeDeclaration = 'array '; } elseif ($parameter->isCallable()) { $typeDeclaration = 'callable '; } else { try { $class = $parameter->getClass(); } catch (ReflectionException $e) { throw new 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 (!$parameter->isVariadic()) { if ($parameter->isDefaultValueAvailable()) { $value = $parameter->getDefaultValue(); $default = ' = ' . \var_export($value, true); } elseif ($parameter->isOptional()) { $default = ' = null'; } } } if ($parameter->isPassedByReference()) { $reference = '&'; } $parameters[] = $nullable . $typeDeclaration . $reference . $name . $default; } return \implode(', ', $parameters); } /** * @param string $className * * @return array * * @throws \ReflectionException */ public function getClassMethods($className) { $class = new ReflectionClass($className); $methods = []; foreach ($class->getMethods() as $method) { if ($method->isPublic() || $method->isAbstract()) { $methods[] = $method->getName(); } } return $methods; } /** * @param string $template * * @return Text_Template * * @throws \InvalidArgumentException */ private function getTemplate($template) { $filename = __DIR__ . DIRECTORY_SEPARATOR . 'Generator' . DIRECTORY_SEPARATOR . $template; if (!isset(self::$templates[$filename])) { self::$templates[$filename] = new Text_Template($filename); } return self::$templates[$filename]; } } phpunit-mock-objects-5.0.6/src/Generator/000077500000000000000000000000001322406121100202745ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/src/Generator/deprecation.tpl.dist000066400000000000000000000000731322406121100242540ustar00rootroot00000000000000 @trigger_error({deprecation}, E_USER_DEPRECATED); phpunit-mock-objects-5.0.6/src/Generator/mocked_class.tpl.dist000066400000000000000000000022651322406121100244130ustar00rootroot00000000000000{prologue}{class_declaration} { private $__phpunit_invocationMocker; private $__phpunit_originalObject; private $__phpunit_configurable = {configurable}; {clone}{mocked_methods} public function expects(\PHPUnit\Framework\MockObject\Matcher\Invocation $matcher) { return $this->__phpunit_getInvocationMocker()->expects($matcher); } {method} public function __phpunit_setOriginalObject($originalObject) { $this->__phpunit_originalObject = $originalObject; } public function __phpunit_getInvocationMocker() { if ($this->__phpunit_invocationMocker === null) { $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } }{epilogue} phpunit-mock-objects-5.0.6/src/Generator/mocked_class_method.tpl.dist000066400000000000000000000003561322406121100257520ustar00rootroot00000000000000 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-5.0.6/src/Generator/mocked_clone.tpl.dist000066400000000000000000000002041322406121100243750ustar00rootroot00000000000000 public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } phpunit-mock-objects-5.0.6/src/Generator/mocked_method.tpl.dist000066400000000000000000000013201322406121100245550ustar00rootroot00000000000000 {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} {{deprecation} $arguments = array({arguments_call}); $count = func_num_args(); if ($count > {arguments_count}) { $_arguments = func_get_args(); for ($i = {arguments_count}; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( '{class_name}', '{method_name}', $arguments, '{return_type}', $this, {clone_arguments} ) ); return $result; } phpunit-mock-objects-5.0.6/src/Generator/mocked_method_void.tpl.dist000066400000000000000000000012551322406121100256050ustar00rootroot00000000000000 {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} {{deprecation} $arguments = array({arguments_call}); $count = func_num_args(); if ($count > {arguments_count}) { $_arguments = func_get_args(); for ($i = {arguments_count}; $i < $count; $i++) { $arguments[] = $_arguments[$i]; } } $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( '{class_name}', '{method_name}', $arguments, '{return_type}', $this, {clone_arguments} ) ); } phpunit-mock-objects-5.0.6/src/Generator/mocked_static_method.tpl.dist000066400000000000000000000003651322406121100261340ustar00rootroot00000000000000 {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} { throw new \PHPUnit\Framework\MockObject\BadMethodCallException('Static method "{method_name}" cannot be invoked on mock object'); } phpunit-mock-objects-5.0.6/src/Generator/proxied_method.tpl.dist000066400000000000000000000014131322406121100247700ustar00rootroot00000000000000 {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\ObjectInvocation( '{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-5.0.6/src/Generator/proxied_method_void.tpl.dist000066400000000000000000000014041322406121100260110ustar00rootroot00000000000000 {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\ObjectInvocation( '{class_name}', '{method_name}', $arguments, '{return_type}', $this, {clone_arguments} ) ); call_user_func_array(array($this->__phpunit_originalObject, "{method_name}"), $arguments); } phpunit-mock-objects-5.0.6/src/Generator/trait_class.tpl.dist000066400000000000000000000000671322406121100242720ustar00rootroot00000000000000{prologue}class {class_name} { use {trait_name}; } phpunit-mock-objects-5.0.6/src/Generator/unmocked_clone.tpl.dist000066400000000000000000000002371322406121100247460ustar00rootroot00000000000000 public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); parent::__clone(); } phpunit-mock-objects-5.0.6/src/Generator/wsdl_class.tpl.dist000066400000000000000000000002631322406121100241160ustar00rootroot00000000000000{namespace}class {class_name} extends \SoapClient { public function __construct($wsdl, array $options) { parent::__construct('{wsdl}', $options); } {methods}} phpunit-mock-objects-5.0.6/src/Generator/wsdl_method.tpl.dist000066400000000000000000000000741322406121100242710ustar00rootroot00000000000000 public function {method_name}({arguments}) { } phpunit-mock-objects-5.0.6/src/Invocation/000077500000000000000000000000001322406121100204575ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/src/Invocation/Invocation.php000066400000000000000000000012631322406121100233030ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * Interface for invocations. */ interface Invocation { /** * @return mixed Mocked return value. */ public function generateReturnValue(); public function getClassName(): string; public function getMethodName(): string; public function getParameters(): array; public function getReturnType(): string; public function isReturnTypeNullable(): bool; } phpunit-mock-objects-5.0.6/src/Invocation/ObjectInvocation.php000066400000000000000000000017611322406121100244350ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Invocation; /** * Represents a non-static invocation. */ class ObjectInvocation extends StaticInvocation { /** * @var object */ private $object; /** * @param string $className * @param string $methodName * @param array $parameters * @param string $returnType * @param object $object * @param bool $cloneObjects */ public function __construct($className, $methodName, array $parameters, $returnType, $object, $cloneObjects = false) { parent::__construct($className, $methodName, $parameters, $returnType, $cloneObjects); $this->object = $object; } public function getObject() { return $this->object; } } phpunit-mock-objects-5.0.6/src/Invocation/StaticInvocation.php000066400000000000000000000134211322406121100244520ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Invocation; use PHPUnit\Framework\MockObject\Generator; use PHPUnit\Framework\MockObject\Invocation; use PHPUnit\Framework\SelfDescribing; use ReflectionObject; use SebastianBergmann\Exporter\Exporter; /** * Represents a static invocation. */ class StaticInvocation implements Invocation, SelfDescribing { /** * @var array */ private static $uncloneableExtensions = [ 'mysqli' => true, 'SQLite' => true, 'sqlite3' => true, 'tidy' => true, 'xmlwriter' => true, 'xsl' => true ]; /** * @var array */ private static $uncloneableClasses = [ 'Closure', 'COMPersistHelper', 'IteratorIterator', 'RecursiveIteratorIterator', 'SplFileObject', 'PDORow', 'ZipArchive' ]; /** * @var string */ private $className; /** * @var string */ private $methodName; /** * @var array */ private $parameters; /** * @var string */ private $returnType; /** * @var bool */ private $isReturnTypeNullable = false; /** * @param string $className * @param string $methodName * @param array $parameters * @param string $returnType * @param bool $cloneObjects */ public function __construct($className, $methodName, array $parameters, $returnType, $cloneObjects = false) { $this->className = $className; $this->methodName = $methodName; $this->parameters = $parameters; if (\strpos($returnType, '?') === 0) { $returnType = \substr($returnType, 1); $this->isReturnTypeNullable = true; } $this->returnType = $returnType; if (!$cloneObjects) { return; } foreach ($this->parameters as $key => $value) { if (\is_object($value)) { $this->parameters[$key] = $this->cloneObject($value); } } } public function getClassName(): string { return $this->className; } public function getMethodName(): string { return $this->methodName; } public function getParameters(): array { return $this->parameters; } public function getReturnType(): string { return $this->returnType; } public function isReturnTypeNullable(): bool { return $this->isReturnTypeNullable; } /** * @return mixed Mocked return value * * @throws \ReflectionException * @throws \PHPUnit\Framework\MockObject\RuntimeException * @throws \PHPUnit\Framework\Exception */ public function generateReturnValue() { if ($this->isReturnTypeNullable) { return; } switch (\strtolower($this->returnType)) { case '': case 'void': return; case 'string': return ''; case 'float': return 0.0; case 'int': return 0; case 'bool': return false; case 'array': return []; case 'object': return new \stdClass; case 'callable': case 'closure': return function () { }; case 'traversable': case 'generator': case 'iterable': $generator = function () { yield; }; return $generator(); default: $generator = new Generator; return $generator->getMock($this->returnType, [], [], '', false); } } public function toString(): string { $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) : '' ); } /** * @param object $original * * @return object */ private 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) { $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-5.0.6/src/InvocationMocker.php000066400000000000000000000102011322406121100223230ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use Exception; use PHPUnit\Framework\MockObject\Builder\InvocationMocker as BuilderInvocationMocker; use PHPUnit\Framework\MockObject\Builder\Match; use PHPUnit\Framework\MockObject\Builder\NamespaceMatch; use PHPUnit\Framework\MockObject\Matcher\Invocation as MatcherInvocation; use PHPUnit\Framework\MockObject\Stub\MatcherCollection; /** * Mocker for invocations which are sent from * MockObject objects. * * Keeps track of all expectations and stubs as well as registering * identifications for builders. */ class InvocationMocker implements MatcherCollection, Invokable, NamespaceMatch { /** * @var MatcherInvocation[] */ private $matchers = []; /** * @var Match[] */ private $builderMap = []; /** * @var string[] */ private $configurableMethods = []; /** * @param array $configurableMethods */ public function __construct(array $configurableMethods) { $this->configurableMethods = $configurableMethods; } /** * @param MatcherInvocation $matcher */ public function addMatcher(MatcherInvocation $matcher) { $this->matchers[] = $matcher; } 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 Match $builder * * @throws RuntimeException */ public function registerId($id, Match $builder) { if (isset($this->builderMap[$id])) { throw new RuntimeException( 'Match builder with id <' . $id . '> is already registered.' ); } $this->builderMap[$id] = $builder; } /** * @param MatcherInvocation $matcher * * @return BuilderInvocationMocker */ public function expects(MatcherInvocation $matcher) { return new BuilderInvocationMocker( $this, $matcher, $this->configurableMethods ); } /** * @param Invocation $invocation * * @return mixed * * @throws Exception */ public function invoke(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; } if (\strtolower($invocation->getMethodName()) === '__tostring') { return ''; } return $invocation->generateReturnValue(); } /** * @param Invocation $invocation * * @return bool */ public function matches(Invocation $invocation) { foreach ($this->matchers as $matcher) { if (!$matcher->matches($invocation)) { return false; } } return true; } /** * @return bool * * @throws \PHPUnit\Framework\ExpectationFailedException */ public function verify() { foreach ($this->matchers as $matcher) { $matcher->verify(); } } } phpunit-mock-objects-5.0.6/src/Invokable.php000066400000000000000000000020041322406121100207650ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; /** * Interface for classes which can be invoked. * * The invocation will be taken from a mock object and passed to an object * of this class. */ interface Invokable extends Verifiable { /** * Invokes the invocation object $invocation so that it can be checked for * expectations or matched against stubs. * * @param Invocation $invocation The invocation object passed from mock object * * @return object */ public function invoke(Invocation $invocation); /** * Checks if the invocation matches. * * @param Invocation $invocation The invocation object passed from mock object * * @return bool */ public function matches(Invocation $invocation); } phpunit-mock-objects-5.0.6/src/Matcher.php000066400000000000000000000214371322406121100204510ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Matcher\AnyInvokedCount; use PHPUnit\Framework\MockObject\Matcher\AnyParameters; use PHPUnit\Framework\MockObject\Matcher\Invocation as MatcherInvocation; use PHPUnit\Framework\MockObject\Matcher\InvokedCount; use PHPUnit\Framework\MockObject\Matcher\MethodName; use PHPUnit\Framework\MockObject\Matcher\Parameters; use PHPUnit\Framework\TestFailure; /** * 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. */ class Matcher implements MatcherInvocation { /** * @var MatcherInvocation */ private $invocationMatcher; /** * @var mixed */ private $afterMatchBuilderId = null; /** * @var bool */ private $afterMatchBuilderIsInvoked = false; /** * @var MethodName */ private $methodNameMatcher = null; /** * @var Parameters */ private $parametersMatcher = null; /** * @var Stub */ private $stub = null; /** * @param MatcherInvocation $invocationMatcher */ public function __construct(MatcherInvocation $invocationMatcher) { $this->invocationMatcher = $invocationMatcher; } public function hasMatchers(): bool { return $this->invocationMatcher !== null && !$this->invocationMatcher instanceof AnyInvokedCount; } public function hasMethodNameMatcher(): bool { return $this->methodNameMatcher !== null; } public function getMethodNameMatcher(): MethodName { return $this->methodNameMatcher; } public function setMethodNameMatcher(MethodName $matcher) { $this->methodNameMatcher = $matcher; } public function hasParametersMatcher(): bool { return $this->parametersMatcher !== null; } public function getParametersMatcher(): Parameters { return $this->parametersMatcher; } public function setParametersMatcher($matcher) { $this->parametersMatcher = $matcher; } public function setStub($stub) { $this->stub = $stub; } public function setAfterMatchBuilderId($id) { $this->afterMatchBuilderId = $id; } /** * @param Invocation $invocation * * @return mixed * * @throws \Exception * @throws RuntimeException * @throws ExpectationFailedException */ public function invoked(Invocation $invocation) { if ($this->invocationMatcher === null) { throw new RuntimeException( 'No invocation matcher is set' ); } if ($this->methodNameMatcher === null) { throw new RuntimeException('No method matcher is set'); } if ($this->afterMatchBuilderId !== null) { $builder = $invocation->getObject() ->__phpunit_getInvocationMocker() ->lookupId($this->afterMatchBuilderId); if (!$builder) { throw new RuntimeException( \sprintf( 'No builder found for match builder identification <%s>', $this->afterMatchBuilderId ) ); } $matcher = $builder->getMatcher(); if ($matcher && $matcher->invocationMatcher->hasBeenInvoked()) { $this->afterMatchBuilderIsInvoked = true; } } $this->invocationMatcher->invoked($invocation); try { if ($this->parametersMatcher !== null && !$this->parametersMatcher->matches($invocation)) { $this->parametersMatcher->verify(); } } catch (ExpectationFailedException $e) { throw new 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 Invocation $invocation * * @return bool * * @throws RuntimeException * @throws ExpectationFailedException */ public function matches(Invocation $invocation) { if ($this->afterMatchBuilderId !== null) { $builder = $invocation->getObject() ->__phpunit_getInvocationMocker() ->lookupId($this->afterMatchBuilderId); if (!$builder) { throw new RuntimeException( \sprintf( 'No builder found for match builder identification <%s>', $this->afterMatchBuilderId ) ); } $matcher = $builder->getMatcher(); if (!$matcher) { return false; } if (!$matcher->invocationMatcher->hasBeenInvoked()) { return false; } } if ($this->invocationMatcher === null) { throw new RuntimeException( 'No invocation matcher is set' ); } if ($this->methodNameMatcher === null) { throw new RuntimeException('No method matcher is set'); } if (!$this->invocationMatcher->matches($invocation)) { return false; } try { if (!$this->methodNameMatcher->matches($invocation)) { return false; } } catch (ExpectationFailedException $e) { throw new ExpectationFailedException( \sprintf( "Expectation failed for %s when %s\n%s", $this->methodNameMatcher->toString(), $this->invocationMatcher->toString(), $e->getMessage() ), $e->getComparisonFailure() ); } return true; } /** * @throws RuntimeException * @throws ExpectationFailedException */ public function verify() { if ($this->invocationMatcher === null) { throw new RuntimeException( 'No invocation matcher is set' ); } if ($this->methodNameMatcher === null) { throw new RuntimeException('No method matcher is set'); } try { $this->invocationMatcher->verify(); if ($this->parametersMatcher === null) { $this->parametersMatcher = new AnyParameters; } $invocationIsAny = $this->invocationMatcher instanceof AnyInvokedCount; $invocationIsNever = $this->invocationMatcher instanceof InvokedCount && $this->invocationMatcher->isNever(); if (!$invocationIsAny && !$invocationIsNever) { $this->parametersMatcher->verify(); } } catch (ExpectationFailedException $e) { throw new ExpectationFailedException( \sprintf( "Expectation failed for %s when %s.\n%s", $this->methodNameMatcher->toString(), $this->invocationMatcher->toString(), TestFailure::exceptionToString($e) ) ); } } /** * @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); } } phpunit-mock-objects-5.0.6/src/Matcher/000077500000000000000000000000001322406121100177315ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/src/Matcher/AnyInvokedCount.php000066400000000000000000000012071322406121100235220ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; /** * Invocation matcher which checks if a method has been invoked zero or more * times. This matcher will always match. */ class AnyInvokedCount extends InvokedRecorder { /** * @return string */ public function toString() { return 'invoked zero or more times'; } public function verify() { } } phpunit-mock-objects-5.0.6/src/Matcher/AnyParameters.php000066400000000000000000000014161322406121100232170ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * Invocation matcher which allows any parameters to a method. */ class AnyParameters extends StatelessInvocation { /** * @return string */ public function toString() { return 'with any parameters'; } /** * @param BaseInvocation $invocation * * @return bool */ public function matches(BaseInvocation $invocation) { return true; } } phpunit-mock-objects-5.0.6/src/Matcher/ConsecutiveParameters.php000066400000000000000000000073221322406121100247610ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\IsEqual; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * 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 ConsecutiveParameters extends StatelessInvocation { /** * @var array */ private $parameterGroups = []; /** * @var array */ private $invocations = []; /** * @param array $parameterGroups * * @throws \PHPUnit\Framework\Exception */ public function __construct(array $parameterGroups) { foreach ($parameterGroups as $index => $parameters) { foreach ($parameters as $parameter) { if (!$parameter instanceof Constraint) { $parameter = new IsEqual($parameter); } $this->parameterGroups[$index][] = $parameter; } } } /** * @return string */ public function toString() { return 'with consecutive parameters'; } /** * @param BaseInvocation $invocation * * @return bool * * @throws \PHPUnit\Framework\ExpectationFailedException */ public function matches(BaseInvocation $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 BaseInvocation $invocation * @param int $callIndex * * @throws ExpectationFailedException */ private function verifyInvocation(BaseInvocation $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 ExpectationFailedException( 'Mocked method does not exist.' ); } if (\count($invocation->getParameters()) < \count($parameters)) { throw new ExpectationFailedException( \sprintf( 'Parameter count for invocation %s is too low.', $invocation->toString() ) ); } foreach ($parameters as $i => $parameter) { $parameter->evaluate( $invocation->getParameters()[$i], \sprintf( 'Parameter %s for invocation #%d %s does not match expected ' . 'value.', $i, $callIndex, $invocation->toString() ) ); } } } phpunit-mock-objects-5.0.6/src/Matcher/Invocation.php000066400000000000000000000033321322406121100225540ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; use PHPUnit\Framework\MockObject\Verifiable; use PHPUnit\Framework\SelfDescribing; /** * Interface for classes which matches an invocation based on its * method name, argument, order or call count. */ interface Invocation extends SelfDescribing, 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 BaseInvocation $invocation Object containing information on a mocked or stubbed method which was invoked * * @return mixed */ public function invoked(BaseInvocation $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 BaseInvocation $invocation Object containing information on a mocked or stubbed method which was invoked * * @return bool */ public function matches(BaseInvocation $invocation); } phpunit-mock-objects-5.0.6/src/Matcher/InvokedAtIndex.php000066400000000000000000000042641322406121100233240ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * 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. */ class InvokedAtIndex implements Invocation { /** * @var int */ private $sequenceIndex; /** * @var int */ private $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 BaseInvocation $invocation * * @return bool */ public function matches(BaseInvocation $invocation) { $this->currentIndex++; return $this->currentIndex == $this->sequenceIndex; } /** * @param BaseInvocation $invocation */ public function invoked(BaseInvocation $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 ExpectationFailedException */ public function verify() { if ($this->currentIndex < $this->sequenceIndex) { throw new ExpectationFailedException( \sprintf( 'The expected invocation at index %s was never reached.', $this->sequenceIndex ) ); } } } phpunit-mock-objects-5.0.6/src/Matcher/InvokedAtLeastCount.php000066400000000000000000000027031322406121100243320ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\ExpectationFailedException; /** * Invocation matcher which checks if a method has been invoked at least * N times. */ class InvokedAtLeastCount extends 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 ExpectationFailedException */ public function verify() { $count = $this->getInvocationCount(); if ($count < $this->requiredInvocations) { throw new ExpectationFailedException( 'Expected invocation at least ' . $this->requiredInvocations . ' times but it occurred ' . $count . ' time(s).' ); } } } phpunit-mock-objects-5.0.6/src/Matcher/InvokedAtLeastOnce.php000066400000000000000000000022271322406121100241270ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\ExpectationFailedException; /** * 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. */ class InvokedAtLeastOnce extends 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 ExpectationFailedException */ public function verify() { $count = $this->getInvocationCount(); if ($count < 1) { throw new ExpectationFailedException( 'Expected invocation at least once but it never occurred.' ); } } } phpunit-mock-objects-5.0.6/src/Matcher/InvokedAtMostCount.php000066400000000000000000000026701322406121100242070ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\ExpectationFailedException; /** * Invocation matcher which checks if a method has been invoked at least * N times. */ class InvokedAtMostCount extends 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 ExpectationFailedException */ public function verify() { $count = $this->getInvocationCount(); if ($count > $this->allowedInvocations) { throw new ExpectationFailedException( 'Expected invocation at most ' . $this->allowedInvocations . ' times but it occurred ' . $count . ' time(s).' ); } } } phpunit-mock-objects-5.0.6/src/Matcher/InvokedCount.php000066400000000000000000000054331322406121100230570ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * 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. */ class InvokedCount extends InvokedRecorder { /** * @var int */ private $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 BaseInvocation $invocation * * @throws ExpectationFailedException */ public function invoked(BaseInvocation $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 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 ExpectationFailedException */ public function verify() { $count = $this->getInvocationCount(); if ($count !== $this->expectedCount) { throw new ExpectationFailedException( \sprintf( 'Method was expected to be called %d times, ' . 'actually called %d times.', $this->expectedCount, $count ) ); } } } phpunit-mock-objects-5.0.6/src/Matcher/InvokedRecorder.php000066400000000000000000000026661322406121100235410ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * Records invocations and provides convenience methods for checking them later * on. * This abstract class can be implemented by matchers which needs to check the * number of times an invocation has occurred. */ abstract class InvokedRecorder implements Invocation { /** * @var BaseInvocation[] */ private $invocations = []; /** * @return int */ public function getInvocationCount() { return \count($this->invocations); } /** * @return BaseInvocation[] */ public function getInvocations() { return $this->invocations; } /** * @return bool */ public function hasBeenInvoked() { return \count($this->invocations) > 0; } /** * @param BaseInvocation $invocation */ public function invoked(BaseInvocation $invocation) { $this->invocations[] = $invocation; } /** * @param BaseInvocation $invocation * * @return bool */ public function matches(BaseInvocation $invocation) { return true; } } phpunit-mock-objects-5.0.6/src/Matcher/MethodName.php000066400000000000000000000034571322406121100224740ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\IsEqual; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; use PHPUnit\Util\InvalidArgumentHelper; /** * 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(). */ class MethodName extends StatelessInvocation { /** * @var Constraint */ private $constraint; /** * @param Constraint|string * * @throws Constraint * @throws \PHPUnit\Framework\Exception */ public function __construct($constraint) { if (!$constraint instanceof Constraint) { if (!\is_string($constraint)) { throw InvalidArgumentHelper::factory(1, 'string'); } $constraint = new IsEqual( $constraint, 0, 10, false, true ); } $this->constraint = $constraint; } /** * @return string */ public function toString() { return 'method name ' . $this->constraint->toString(); } /** * @param BaseInvocation $invocation * * @return bool */ public function matches(BaseInvocation $invocation) { return $this->constraint->evaluate($invocation->getMethodName(), '', true); } } phpunit-mock-objects-5.0.6/src/Matcher/Parameters.php000066400000000000000000000111371322406121100225500ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\Constraint\Constraint; use PHPUnit\Framework\Constraint\IsAnything; use PHPUnit\Framework\Constraint\IsEqual; use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * 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(). */ class Parameters extends StatelessInvocation { /** * @var Constraint[] */ private $parameters = []; /** * @var BaseInvocation */ private $invocation; /** * @var ExpectationFailedException */ private $parameterVerificationResult; /** * @param array $parameters * * @throws \PHPUnit\Framework\Exception */ public function __construct(array $parameters) { foreach ($parameters as $parameter) { if (!($parameter instanceof Constraint)) { $parameter = new 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 BaseInvocation $invocation * * @return bool * * @throws \Exception */ public function matches(BaseInvocation $invocation) { $this->invocation = $invocation; $this->parameterVerificationResult = null; try { $this->parameterVerificationResult = $this->verify(); return $this->parameterVerificationResult; } catch (ExpectationFailedException $e) { $this->parameterVerificationResult = $e; throw $this->parameterVerificationResult; } } /** * Checks if the invocation $invocation matches the current rules. If it * does the matcher will get the invoked() method called which should check * if an expectation is met. * * @return bool * * @throws ExpectationFailedException */ public function verify() { if (isset($this->parameterVerificationResult)) { return $this->guardAgainstDuplicateEvaluationOfParameterConstraints(); } if ($this->invocation === null) { throw new ExpectationFailedException('Mocked method does not exist.'); } if (\count($this->invocation->getParameters()) < \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]) === IsAnything::class) { $message .= "\nTo allow 0 or more parameters with any value, omit ->with() or use ->withAnyParameters() instead."; } throw new ExpectationFailedException( \sprintf($message, $this->invocation->toString()) ); } foreach ($this->parameters as $i => $parameter) { $parameter->evaluate( $this->invocation->getParameters()[$i], \sprintf( 'Parameter %s for invocation %s does not match expected ' . 'value.', $i, $this->invocation->toString() ) ); } return true; } /** * @return bool * * @throws ExpectationFailedException */ private function guardAgainstDuplicateEvaluationOfParameterConstraints() { if ($this->parameterVerificationResult instanceof \Exception) { throw $this->parameterVerificationResult; } return (bool) $this->parameterVerificationResult; } } phpunit-mock-objects-5.0.6/src/Matcher/StatelessInvocation.php000066400000000000000000000034041322406121100244440ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\MockObject\Invocation as BaseInvocation; /** * 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. */ abstract class StatelessInvocation implements 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 BaseInvocation $invocation Object containing information on a mocked or stubbed method which was invoked * * @return mixed */ public function invoked(BaseInvocation $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 Invocation $invocation Object containing information on a mocked or stubbed method which was invoked * * @return bool */ public function verify() { } } phpunit-mock-objects-5.0.6/src/MockBuilder.php000066400000000000000000000170751322406121100212710ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use PHPUnit\Framework\TestCase; /** * Implementation of the Builder pattern for Mock objects. */ class MockBuilder { /** * @var TestCase */ private $testCase; /** * @var string */ private $type; /** * @var array */ private $methods = []; /** * @var array */ private $methodsExcept = []; /** * @var string */ private $mockClassName = ''; /** * @var array */ private $constructorArgs = []; /** * @var bool */ private $originalConstructor = true; /** * @var bool */ private $originalClone = true; /** * @var bool */ private $autoload = true; /** * @var bool */ private $cloneArguments = false; /** * @var bool */ private $callOriginalMethods = false; /** * @var object */ private $proxyTarget = null; /** * @var bool */ private $allowMockingUnknownTypes = true; /** * @var Generator */ private $generator; /** * @param TestCase $testCase * @param array|string $type */ public function __construct(TestCase $testCase, $type) { $this->testCase = $testCase; $this->type = $type; $this->generator = new Generator; } /** * Creates a mock object using a fluent interface. * * @return MockObject */ public function getMock() { $object = $this->generator->getMock( $this->type, $this->methods, $this->constructorArgs, $this->mockClassName, $this->originalConstructor, $this->originalClone, $this->autoload, $this->cloneArguments, $this->callOriginalMethods, $this->proxyTarget, $this->allowMockingUnknownTypes ); $this->testCase->registerMockObject($object); return $object; } /** * Creates a mock object for an abstract class using a fluent interface. * * @return MockObject */ public function getMockForAbstractClass() { $object = $this->generator->getMockForAbstractClass( $this->type, $this->constructorArgs, $this->mockClassName, $this->originalConstructor, $this->originalClone, $this->autoload, $this->methods, $this->cloneArguments ); $this->testCase->registerMockObject($object); return $object; } /** * Creates a mock object for a trait using a fluent interface. * * @return MockObject */ public function getMockForTrait() { $object = $this->generator->getMockForTrait( $this->type, $this->constructorArgs, $this->mockClassName, $this->originalConstructor, $this->originalClone, $this->autoload, $this->methods, $this->cloneArguments ); $this->testCase->registerMockObject($object); return $object; } /** * Specifies the subset of methods to mock. Default is to mock none of them. * * @param array|null $methods * * @return MockBuilder */ public function setMethods(array $methods = null) { $this->methods = $methods; return $this; } /** * Specifies the subset of methods to not mock. Default is to mock all of them. * * @param array $methods * * @return MockBuilder */ public function setMethodsExcept(array $methods = []) { $this->methodsExcept = $methods; $this->setMethods( \array_diff( $this->generator->getClassMethods($this->type), $this->methodsExcept ) ); return $this; } /** * Specifies the arguments for the constructor. * * @param array $args * * @return MockBuilder */ public function setConstructorArgs(array $args) { $this->constructorArgs = $args; return $this; } /** * Specifies the name for the mock class. * * @param string $name * * @return MockBuilder */ public function setMockClassName($name) { $this->mockClassName = $name; return $this; } /** * Disables the invocation of the original constructor. * * @return MockBuilder */ public function disableOriginalConstructor() { $this->originalConstructor = false; return $this; } /** * Enables the invocation of the original constructor. * * @return MockBuilder */ public function enableOriginalConstructor() { $this->originalConstructor = true; return $this; } /** * Disables the invocation of the original clone constructor. * * @return MockBuilder */ public function disableOriginalClone() { $this->originalClone = false; return $this; } /** * Enables the invocation of the original clone constructor. * * @return MockBuilder */ public function enableOriginalClone() { $this->originalClone = true; return $this; } /** * Disables the use of class autoloading while creating the mock object. * * @return MockBuilder */ public function disableAutoload() { $this->autoload = false; return $this; } /** * Enables the use of class autoloading while creating the mock object. * * @return MockBuilder */ public function enableAutoload() { $this->autoload = true; return $this; } /** * Disables the cloning of arguments passed to mocked methods. * * @return MockBuilder */ public function disableArgumentCloning() { $this->cloneArguments = false; return $this; } /** * Enables the cloning of arguments passed to mocked methods. * * @return MockBuilder */ public function enableArgumentCloning() { $this->cloneArguments = true; return $this; } /** * Enables the invocation of the original methods. * * @return MockBuilder */ public function enableProxyingToOriginalMethods() { $this->callOriginalMethods = true; return $this; } /** * Disables the invocation of the original methods. * * @return MockBuilder */ public function disableProxyingToOriginalMethods() { $this->callOriginalMethods = false; $this->proxyTarget = null; return $this; } /** * Sets the proxy target. * * @param object $object * * @return MockBuilder */ public function setProxyTarget($object) { $this->proxyTarget = $object; return $this; } /** * @return MockBuilder */ public function allowMockingUnknownTypes() { $this->allowMockingUnknownTypes = true; return $this; } /** * @return MockBuilder */ public function disallowMockingUnknownTypes() { $this->allowMockingUnknownTypes = false; return $this; } } phpunit-mock-objects-5.0.6/src/MockObject.php000066400000000000000000000026601322406121100211030ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\Builder\InvocationMocker; use PHPUnit\Framework\MockObject\Matcher\Invocation; /** * Interface for all mock objects which are generated by * MockBuilder. * * @method InvocationMocker method($constraint) */ interface PHPUnit_Framework_MockObject_MockObject /*extends Verifiable*/ { /** * Registers a new expectation in the mock object and returns the match * object which can be infused with further details. * * @param Invocation $matcher * * @return InvocationMocker */ public function expects(Invocation $matcher); /** * @return InvocationMocker */ public function __phpunit_setOriginalObject($originalObject); /** * @return 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 ExpectationFailedException */ public function __phpunit_verify(); /** * @return bool */ public function __phpunit_hasMatchers(); } phpunit-mock-objects-5.0.6/src/Stub.php000066400000000000000000000016161322406121100200000ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use PHPUnit\Framework\SelfDescribing; /** * 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. */ interface Stub extends SelfDescribing { /** * Fakes the processing of the invocation $invocation by returning a * specific value. * * @param Invocation $invocation The invocation which was mocked and matched by the current method and argument matchers * * @return mixed */ public function invoke(Invocation $invocation); } phpunit-mock-objects-5.0.6/src/Stub/000077500000000000000000000000001322406121100172635ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/src/Stub/ConsecutiveCalls.php000066400000000000000000000022651322406121100232470ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; use PHPUnit\Framework\MockObject\Stub; use SebastianBergmann\Exporter\Exporter; /** * Stubs a method by returning a user-defined stack of values. */ class ConsecutiveCalls implements Stub { /** * @var array */ private $stack; /** * @var mixed */ private $value; public function __construct(array $stack) { $this->stack = $stack; } public function invoke(Invocation $invocation) { $this->value = \array_shift($this->stack); if ($this->value instanceof 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-5.0.6/src/Stub/Exception.php000066400000000000000000000017031322406121100217330ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; use PHPUnit\Framework\MockObject\Stub; use SebastianBergmann\Exporter\Exporter; /** * Stubs a method by raising a user-defined exception. */ class Exception implements Stub { private $exception; public function __construct(\Throwable $exception) { $this->exception = $exception; } public function invoke(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-5.0.6/src/Stub/MatcherCollection.php000066400000000000000000000012661322406121100234000ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Matcher\Invocation; /** * Stubs a method by returning a user-defined value. */ interface MatcherCollection { /** * Adds a new matcher to the collection which can be used as an expectation * or a stub. * * @param Invocation $matcher Matcher for invocations to mock objects */ public function addMatcher(Invocation $matcher); } phpunit-mock-objects-5.0.6/src/Stub/ReturnArgument.php000066400000000000000000000020071322406121100227550ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; use PHPUnit\Framework\MockObject\Stub; /** * Stubs a method by returning an argument that was passed to the mocked method. */ class ReturnArgument implements Stub { /** * @var int */ private $argumentIndex; public function __construct($argumentIndex) { $this->argumentIndex = $argumentIndex; } public function invoke(Invocation $invocation) { if (isset($invocation->getParameters()[$this->argumentIndex])) { return $invocation->getParameters()[$this->argumentIndex]; } return; } public function toString() { return \sprintf('return argument #%d', $this->argumentIndex); } } phpunit-mock-objects-5.0.6/src/Stub/ReturnCallback.php000066400000000000000000000025671322406121100227020ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; use PHPUnit\Framework\MockObject\Stub; class ReturnCallback implements Stub { private $callback; public function __construct($callback) { $this->callback = $callback; } public function invoke(Invocation $invocation) { return \call_user_func_array($this->callback, $invocation->getParameters()); } 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] ); } return 'return result of user defined callback ' . $this->callback . ' with the passed arguments'; } } phpunit-mock-objects-5.0.6/src/Stub/ReturnReference.php000066400000000000000000000017611322406121100230770ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; use PHPUnit\Framework\MockObject\Stub; use SebastianBergmann\Exporter\Exporter; /** * Stubs a method by returning a user-defined reference to a value. */ class ReturnReference implements Stub { /** * @var mixed */ private $reference; public function __construct(&$reference) { $this->reference = &$reference; } public function invoke(Invocation $invocation) { return $this->reference; } public function toString() { $exporter = new Exporter; return \sprintf( 'return user-specified reference %s', $exporter->export($this->reference) ); } } phpunit-mock-objects-5.0.6/src/Stub/ReturnSelf.php000066400000000000000000000020061322406121100220630ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; use PHPUnit\Framework\MockObject\Invocation\ObjectInvocation; use PHPUnit\Framework\MockObject\RuntimeException; use PHPUnit\Framework\MockObject\Stub; /** * Stubs a method by returning the current object. */ class ReturnSelf implements Stub { public function invoke(Invocation $invocation) { if (!$invocation instanceof ObjectInvocation) { throw new RuntimeException( 'The current object can only be returned when mocking an ' . 'object, not a static class.' ); } return $invocation->getObject(); } public function toString() { return 'return the current object'; } } phpunit-mock-objects-5.0.6/src/Stub/ReturnStub.php000066400000000000000000000016771322406121100221240ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; use PHPUnit\Framework\MockObject\Stub; use SebastianBergmann\Exporter\Exporter; /** * Stubs a method by returning a user-defined value. */ class ReturnStub implements Stub { /** * @var mixed */ private $value; public function __construct($value) { $this->value = $value; } public function invoke(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-5.0.6/src/Stub/ReturnValueMap.php000066400000000000000000000022451322406121100227110ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\MockObject\Invocation; use PHPUnit\Framework\MockObject\Stub; /** * Stubs a method by returning a value from a map. */ class ReturnValueMap implements Stub { /** * @var array */ private $valueMap; public function __construct(array $valueMap) { $this->valueMap = $valueMap; } public function invoke(Invocation $invocation) { $parameterCount = \count($invocation->getParameters()); foreach ($this->valueMap as $map) { if (!\is_array($map) || $parameterCount !== (\count($map) - 1)) { continue; } $return = \array_pop($map); if ($invocation->getParameters() === $map) { return $return; } } return; } public function toString() { return 'return value from a map'; } } phpunit-mock-objects-5.0.6/src/Verifiable.php000066400000000000000000000012531322406121100211300ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace PHPUnit\Framework\MockObject; use PHPUnit\Framework\ExpectationFailedException; /** * Interface for classes which must verify a given expectation. */ interface 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 ExpectationFailedException */ public function verify(); } phpunit-mock-objects-5.0.6/tests/000077500000000000000000000000001322406121100167215ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/tests/Builder/000077500000000000000000000000001322406121100203075ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/tests/Builder/InvocationMockerTest.php000066400000000000000000000040261322406121100251340ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use PHPUnit\Framework\TestCase; class InvocationMockerTest extends TestCase { public function testWillReturnWithOneValue() { $mock = $this->getMockBuilder(stdClass::class) ->setMethods(['foo']) ->getMock(); $mock->expects($this->any()) ->method('foo') ->willReturn(1); $this->assertEquals(1, $mock->foo()); } public function testWillReturnWithMultipleValues() { $mock = $this->getMockBuilder(stdClass::class) ->setMethods(['foo']) ->getMock(); $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->getMockBuilder(stdClass::class) ->setMethods(['foo']) ->getMock(); $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()); } public function testWillReturnByReference() { $mock = $this->getMockBuilder(stdClass::class) ->setMethods(['foo']) ->getMock(); $mock->expects($this->any()) ->method('foo') ->willReturnReference($value); $this->assertSame(null, $mock->foo()); $value = 'foo'; $this->assertSame('foo', $mock->foo()); $value = 'bar'; $this->assertSame('bar', $mock->foo()); } } phpunit-mock-objects-5.0.6/tests/Generator/000077500000000000000000000000001322406121100206475ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/tests/Generator/232.phpt000066400000000000000000000055111322406121100220540ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['speak']; 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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/397.phpt000066400000000000000000000047241322406121100220750ustar00rootroot00000000000000--TEST-- https://github.com/sebastianbergmann/phpunit-mock-objects/issues/397 --FILE-- generate( C::class, [], 'MockC', true, true ); print $mock['code']; --EXPECTF-- class MockC extends C implements PHPUnit\Framework\MockObject\MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; private $__phpunit_configurable = ['m']; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function m(?C $other): C { $arguments = array($other); $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\ObjectInvocation( 'C', 'm', $arguments, 'C', $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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/abstract_class.phpt000066400000000000000000000072151322406121100245410ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['one', 'two', 'three']; 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\ObjectInvocation( '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\ObjectInvocation( '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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/class.phpt000066400000000000000000000061221322406121100226520ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar', 'baz']; 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\ObjectInvocation( '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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/class_call_parent_clone.phpt000066400000000000000000000037021322406121100263770ustar00rootroot00000000000000--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/class_call_parent_constructor.phpt000066400000000000000000000036531322406121100276710ustar00rootroot00000000000000--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/class_dont_call_parent_clone.phpt000066400000000000000000000036511322406121100274260ustar00rootroot00000000000000--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/class_dont_call_parent_constructor.phpt000066400000000000000000000036531322406121100307150ustar00rootroot00000000000000--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/class_implementing_interface_call_parent_constructor.phpt000066400000000000000000000037721322406121100344630ustar00rootroot00000000000000--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } class_implementing_interface_dont_call_parent_constructor.phpt000066400000000000000000000037721322406121100354300ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/tests/Generator--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/class_partial.phpt000066400000000000000000000050471322406121100243730ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar']; 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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/class_with_deprecated_method.phpt000066400000000000000000000055231322406121100274310ustar00rootroot00000000000000--TEST-- \PHPUnit\Framework\MockObject\Generator::generate('ClassWithDeprecatedMethod', array(), 'MockFoo', TRUE, TRUE) --FILE-- generate( 'ClassWithDeprecatedMethod', array(), 'MockFoo', TRUE, TRUE ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends ClassWithDeprecatedMethod implements PHPUnit\Framework\MockObject\MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; private $__phpunit_configurable = ['deprecatedmethod']; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function deprecatedMethod() { @trigger_error('The ClassWithDeprecatedMethod::deprecatedMethod method is deprecated (this method is deprecated).', E_USER_DEPRECATED); $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\ObjectInvocation( 'ClassWithDeprecatedMethod', 'deprecatedMethod', $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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/class_with_method_named_method.phpt000066400000000000000000000043701322406121100277540ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['method']; 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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } class_with_method_with_nullable_typehinted_variadic_arguments.phpt000066400000000000000000000060141322406121100362630ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/tests/Generator--TEST-- \PHPUnit\Framework\MockObject\Generator::generate('ClassWithMethodWithVariadicArguments', array(), 'MockFoo', true, true) --SKIPIF-- =')) print 'skip: PHP >= 7.1 required'; ?> --FILE-- generate( 'ClassWithMethodWithNullableTypehintedVariadicArguments', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends ClassWithMethodWithNullableTypehintedVariadicArguments implements PHPUnit\Framework\MockObject\MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; private $__phpunit_configurable = ['methodwithnullabletypehintedvariadicarguments']; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function methodWithNullableTypehintedVariadicArguments($a, ?string ...$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\ObjectInvocation( 'ClassWithMethodWithNullableTypehintedVariadicArguments', 'methodWithNullableTypehintedVariadicArguments', $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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/class_with_method_with_typehinted_variadic_arguments.phpt000066400000000000000000000055431322406121100344720ustar00rootroot00000000000000--TEST-- \PHPUnit\Framework\MockObject\Generator::generate('ClassWithMethodWithVariadicArguments', array(), 'MockFoo', true, true) --FILE-- generate( 'ClassWithMethodWithTypehintedVariadicArguments', array(), 'MockFoo', true, true ); print $mock['code']; ?> --EXPECTF-- class MockFoo extends ClassWithMethodWithTypehintedVariadicArguments implements PHPUnit\Framework\MockObject\MockObject { private $__phpunit_invocationMocker; private $__phpunit_originalObject; private $__phpunit_configurable = ['methodwithtypehintedvariadicarguments']; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function methodWithTypehintedVariadicArguments($a, string ...$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\ObjectInvocation( 'ClassWithMethodWithTypehintedVariadicArguments', 'methodWithTypehintedVariadicArguments', $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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/class_with_method_with_variadic_arguments.phpt000066400000000000000000000054051322406121100322320ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['methodwithvariadicarguments']; 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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/interface.phpt000066400000000000000000000047401322406121100235110ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar']; 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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/invocation_object_clone_object.phpt000066400000000000000000000061421322406121100277540ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar', 'baz']; 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\ObjectInvocation( '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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/namespaced_class.phpt000066400000000000000000000061661322406121100250420ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar', 'baz']; 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\ObjectInvocation( '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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/namespaced_class_call_parent_clone.phpt000066400000000000000000000037321322406121100305620ustar00rootroot00000000000000--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/namespaced_class_call_parent_constructor.phpt000066400000000000000000000037031322406121100320450ustar00rootroot00000000000000--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/namespaced_class_dont_call_parent_clone.phpt000066400000000000000000000037011322406121100316020ustar00rootroot00000000000000--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/namespaced_class_dont_call_parent_constructor.phpt000066400000000000000000000037031322406121100330710ustar00rootroot00000000000000--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } namespaced_class_implementing_interface_call_parent_constructor.phpt000066400000000000000000000040221322406121100365510ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/tests/Generator--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } namespaced_class_implementing_interface_dont_call_parent_constructor.phpt000066400000000000000000000040221322406121100375750ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/tests/Generator--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/namespaced_class_partial.phpt000066400000000000000000000051051322406121100265460ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar']; 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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/namespaced_interface.phpt000066400000000000000000000047761322406121100257020ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar']; 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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/nonexistent_class.phpt000066400000000000000000000037011322406121100253100ustar00rootroot00000000000000--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/nonexistent_class_with_namespace.phpt000066400000000000000000000036661322406121100303710ustar00rootroot00000000000000--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } } nonexistent_class_with_namespace_starting_with_separator.phpt000066400000000000000000000036671322406121100353410ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/tests/Generator--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; private $__phpunit_configurable = []; 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } } phpunit-mock-objects-5.0.6/tests/Generator/nullable_types.phpt000066400000000000000000000051211322406121100245650ustar00rootroot00000000000000--TEST-- \PHPUnit\Framework\MockObject\Generator::generate('Foo', array(), 'MockFoo', true, true) --SKIPIF-- =')) print 'skip: PHP >= 7.1 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; private $__phpunit_configurable = ['bar']; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(?int $x) { $arguments = array($x); $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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/proxy.phpt000066400000000000000000000063261322406121100227340ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar', 'baz']; 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\ObjectInvocation( '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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/return_type_declarations_closure.phpt000066400000000000000000000047451322406121100304220ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar']; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(): Closure { $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\ObjectInvocation( 'Foo', 'bar', $arguments, 'Closure', $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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/return_type_declarations_final.phpt000066400000000000000000000052401322406121100300260ustar00rootroot00000000000000--TEST-- \PHPUnit\Framework\MockObject\Generator::generate('Foo', array(), 'MockFoo', true, true) --SKIPIF-- =')) print 'skip: PHP >= 7.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; private $__phpunit_configurable = ['bar']; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(): FinalClass { $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\ObjectInvocation( 'Foo', 'bar', $arguments, 'FinalClass', $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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/return_type_declarations_generator.phpt000066400000000000000000000047531322406121100307330ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar']; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(): Generator { $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\ObjectInvocation( 'Foo', 'bar', $arguments, 'Generator', $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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/return_type_declarations_nullable.phpt000066400000000000000000000051461322406121100305400ustar00rootroot00000000000000--TEST-- \PHPUnit\Framework\MockObject\Generator::generate('Foo', array(), 'MockFoo', true, true) --SKIPIF-- =')) print 'skip: PHP >= 7.1 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; private $__phpunit_configurable = ['bar']; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(string $baz): ?string { $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\ObjectInvocation( 'Foo', 'bar', $arguments, '?string', $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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/return_type_declarations_object_method.phpt000066400000000000000000000050301322406121100315400ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar']; 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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/return_type_declarations_self.phpt000066400000000000000000000047641322406121100277000ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar']; 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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/return_type_declarations_static_method.phpt000066400000000000000000000042441322406121100315670ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar']; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public static function bar(string $baz): Bar { throw new \PHPUnit\Framework\MockObject\BadMethodCallException('Static method "bar" cannot be invoked on mock object'); } 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/return_type_declarations_void.phpt000066400000000000000000000050721322406121100277010ustar00rootroot00000000000000--TEST-- \PHPUnit\Framework\MockObject\Generator::generate('Foo', array(), 'MockFoo', true, true) --SKIPIF-- =')) print 'skip: PHP >= 7.1 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; private $__phpunit_configurable = ['bar']; public function __clone() { $this->__phpunit_invocationMocker = clone $this->__phpunit_getInvocationMocker(); } public function bar(string $baz): void { $arguments = array($baz); $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\ObjectInvocation( 'Foo', 'bar', $arguments, 'void', $this, true ) ); } 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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/scalar_type_declarations.phpt000066400000000000000000000047641322406121100266150ustar00rootroot00000000000000--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; private $__phpunit_configurable = ['bar']; 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\ObjectInvocation( '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($this->__phpunit_configurable); } return $this->__phpunit_invocationMocker; } public function __phpunit_hasMatchers() { return $this->__phpunit_getInvocationMocker()->hasMatchers(); } public function __phpunit_verify($unsetInvocationMocker = true) { $this->__phpunit_getInvocationMocker()->verify(); if ($unsetInvocationMocker) { $this->__phpunit_invocationMocker = null; } } } phpunit-mock-objects-5.0.6/tests/Generator/wsdl_class.phpt000066400000000000000000000015601322406121100237040ustar00rootroot00000000000000--TEST-- \PHPUnit\Framework\MockObject\Generator::generateClassFromWsdl('GoogleSearch.wsdl', 'GoogleSearch') --SKIPIF-- --FILE-- generateClassFromWsdl( __DIR__ . '/../_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-5.0.6/tests/Generator/wsdl_class_namespace.phpt000066400000000000000000000016201322406121100257150ustar00rootroot00000000000000--TEST-- \PHPUnit\Framework\MockObject\Generator::generateClassFromWsdl('GoogleSearch.wsdl', 'GoogleSearch') --SKIPIF-- --FILE-- generateClassFromWsdl( __DIR__ . '/../_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-5.0.6/tests/Generator/wsdl_class_partial.phpt000066400000000000000000000014441322406121100254210ustar00rootroot00000000000000--TEST-- \PHPUnit\Framework\MockObject\Generator::generateClassFromWsdl('GoogleSearch.wsdl', 'GoogleSearch', array('doGoogleSearch')) --SKIPIF-- --FILE-- generateClassFromWsdl( __DIR__ . '/../_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-5.0.6/tests/GeneratorTest.php000066400000000000000000000152051322406121100222230ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use PHPUnit\Framework\MockObject\Generator; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; /** * @covers \PHPUnit\Framework\MockObject\Generator * * @uses \PHPUnit\Framework\MockObject\InvocationMocker * @uses \PHPUnit\Framework\MockObject\Builder\InvocationMocker * @uses \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation * @uses \PHPUnit\Framework\MockObject\Invocation\StaticInvocation * @uses \PHPUnit\Framework\MockObject\Matcher * @uses \PHPUnit\Framework\MockObject\Matcher\InvokedRecorder * @uses \PHPUnit\Framework\MockObject\Matcher\MethodName * @uses \PHPUnit\Framework\MockObject\Stub\ReturnStub * @uses \PHPUnit\Framework\MockObject\Matcher\InvokedCount */ class GeneratorTest extends TestCase { /** * @var Generator */ private $generator; protected function setUp() { $this->generator = new Generator; } public function testGetMockFailsWhenInvalidFunctionNameIsPassedInAsAFunctionToMock() { $this->expectException(\PHPUnit\Framework\MockObject\RuntimeException::class); $this->generator->getMock(stdClass::class, [0]); } public function testGetMockCanCreateNonExistingFunctions() { $mock = $this->generator->getMock(stdClass::class, ['testFunction']); $this->assertTrue(method_exists($mock, 'testFunction')); } public function testGetMockGeneratorFails() { $this->expectException(\PHPUnit\Framework\MockObject\RuntimeException::class); $this->expectExceptionMessage('duplicates: "foo, bar, foo" (duplicate: "foo")'); $this->generator->getMock(stdClass::class, ['foo', 'bar', 'foo']); } /** * @requires PHP 7 */ public function testGetMockBlacklistedMethodNamesPhp7() { $mock = $this->generator->getMock(InterfaceWithSemiReservedMethodName::class); $this->assertTrue(method_exists($mock, 'unset')); $this->assertInstanceOf(InterfaceWithSemiReservedMethodName::class, $mock); } public function testGetMockForAbstractClassDoesNotFailWhenFakingInterfaces() { $mock = $this->generator->getMockForAbstractClass(Countable::class); $this->assertTrue(method_exists($mock, 'count')); } public function testGetMockForAbstractClassStubbingAbstractClass() { $mock = $this->generator->getMockForAbstractClass(AbstractMockTestClass::class); $this->assertTrue(method_exists($mock, 'doSomething')); } 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')); } 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 */ public function testGetMockForAbstractClassExpectingInvalidArgumentException($className, $mockClassName) { $this->expectException(PHPUnit\Framework\Exception::class); $this->generator->getMockForAbstractClass($className, [], $mockClassName); } public function testGetMockForAbstractClassAbstractClassDoesNotExist() { $this->expectException(\PHPUnit\Framework\MockObject\RuntimeException::class); $this->generator->getMockForAbstractClass('Tux'); } public function getMockForAbstractClassExpectsInvalidArgumentExceptionDataprovider() { return [ 'className not a string' => [[], ''], 'mockClassName not a string' => [Countable::class, new stdClass], ]; } 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()); } 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); } public function testExceptionIsRaisedForMutuallyExclusiveOptions() { $this->expectException(\PHPUnit\Framework\MockObject\RuntimeException::class); $this->generator->getMock(stdClass::class, [], [], '', false, true, true, true, true); } /** * @requires PHP 7 */ public function testCanImplementInterfacesThatHaveMethodsWithReturnTypes() { $stub = $this->generator->getMock([AnInterfaceWithReturnType::class, AnInterface::class]); $this->assertInstanceOf(AnInterfaceWithReturnType::class, $stub); $this->assertInstanceOf(AnInterface::class, $stub); $this->assertInstanceOf(MockObject::class, $stub); } public function testCanConfigureMethodsForDoubleOfNonExistentClass() { $className = 'X' . md5(microtime()); $mock = $this->generator->getMock($className, ['someMethod']); $this->assertInstanceOf($className, $mock); } public function testCanInvokeMethodsOfNonExistentClass() { $className = 'X' . md5(microtime()); $mock = $this->generator->getMock($className, ['someMethod']); $mock->expects($this->once())->method('someMethod'); $this->assertNull($mock->someMethod()); } } phpunit-mock-objects-5.0.6/tests/Invocation/000077500000000000000000000000001322406121100210325ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/tests/Invocation/ObjectInvocationTest.php000066400000000000000000000061161322406121100256470ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use PHPUnit\Framework\MockObject\Invocation\ObjectInvocation; use PHPUnit\Framework\TestCase; class ObjectInvocationTest extends TestCase { public function testConstructorRequiresClassAndMethodAndParametersAndObject() { $this->assertInstanceOf( ObjectInvocation::class, new ObjectInvocation( 'FooClass', 'FooMethod', ['an_argument'], 'ReturnType', new stdClass ) ); } public function testAllowToGetClassNameSetInConstructor() { $invocation = new ObjectInvocation( 'FooClass', 'FooMethod', ['an_argument'], 'ReturnType', new stdClass ); $this->assertSame('FooClass', $invocation->getClassName()); } public function testAllowToGetMethodNameSetInConstructor() { $invocation = new ObjectInvocation( 'FooClass', 'FooMethod', ['an_argument'], 'ReturnType', new stdClass ); $this->assertSame('FooMethod', $invocation->getMethodName()); } public function testAllowToGetObjectSetInConstructor() { $expectedObject = new stdClass; $invocation = new ObjectInvocation( 'FooClass', 'FooMethod', ['an_argument'], 'ReturnType', $expectedObject ); $this->assertSame($expectedObject, $invocation->getObject()); } public function testAllowToGetMethodParametersSetInConstructor() { $expectedParameters = [ 'foo', 5, ['a', 'b'], new stdClass, null, false ]; $invocation = new ObjectInvocation( 'FooClass', 'FooMethod', $expectedParameters, 'ReturnType', new stdClass ); $this->assertSame($expectedParameters, $invocation->getParameters()); } public function testConstructorAllowToSetFlagCloneObjectsInParameters() { $parameters = [new stdClass]; $cloneObjects = true; $invocation = new ObjectInvocation( 'FooClass', 'FooMethod', $parameters, 'ReturnType', new stdClass, $cloneObjects ); $this->assertEquals($parameters, $invocation->getParameters()); $this->assertNotSame($parameters, $invocation->getParameters()); } public function testAllowToGetReturnTypeSetInConstructor() { $expectedReturnType = 'string'; $invocation = new ObjectInvocation( 'FooClass', 'FooMethod', ['an_argument'], $expectedReturnType, new stdClass ); $this->assertSame($expectedReturnType, $invocation->getReturnType()); } } phpunit-mock-objects-5.0.6/tests/Invocation/StaticInvocationTest.php000066400000000000000000000050621322406121100256670ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\MockObject\Invocation\StaticInvocation; class StaticInvocationTest extends TestCase { public function testConstructorRequiresClassAndMethodAndParameters() { $this->assertInstanceOf( StaticInvocation::class, new StaticInvocation( 'FooClass', 'FooMethod', ['an_argument'], 'ReturnType' ) ); } public function testAllowToGetClassNameSetInConstructor() { $invocation = new StaticInvocation( 'FooClass', 'FooMethod', ['an_argument'], 'ReturnType' ); $this->assertSame('FooClass', $invocation->getClassName()); } public function testAllowToGetMethodNameSetInConstructor() { $invocation = new StaticInvocation( 'FooClass', 'FooMethod', ['an_argument'], 'ReturnType' ); $this->assertSame('FooMethod', $invocation->getMethodName()); } public function testAllowToGetMethodParametersSetInConstructor() { $expectedParameters = [ 'foo', 5, ['a', 'b'], new stdClass, null, false ]; $invocation = new StaticInvocation( 'FooClass', 'FooMethod', $expectedParameters, 'ReturnType' ); $this->assertSame($expectedParameters, $invocation->getParameters()); } public function testConstructorAllowToSetFlagCloneObjectsInParameters() { $parameters = [new stdClass]; $cloneObjects = true; $invocation = new StaticInvocation( 'FooClass', 'FooMethod', $parameters, 'ReturnType', $cloneObjects ); $this->assertEquals($parameters, $invocation->getParameters()); $this->assertNotSame($parameters, $invocation->getParameters()); } public function testAllowToGetReturnTypeSetInConstructor() { $expectedReturnType = 'string'; $invocation = new StaticInvocation( 'FooClass', 'FooMethod', ['an_argument'], $expectedReturnType ); $this->assertSame($expectedReturnType, $invocation->getReturnType()); } } phpunit-mock-objects-5.0.6/tests/Matcher/000077500000000000000000000000001322406121100203045ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/tests/Matcher/ConsecutiveParametersTest.php000066400000000000000000000033631322406121100261750ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\ExpectationFailedException; class ConsecutiveParametersTest extends TestCase { public function testIntegration() { $mock = $this->getMockBuilder(stdClass::class) ->setMethods(['foo']) ->getMock(); $mock->expects($this->any()) ->method('foo') ->withConsecutive( ['bar'], [21, 42] ); $this->assertNull($mock->foo('bar')); $this->assertNull($mock->foo(21, 42)); } public function testIntegrationWithLessAssertionsThanMethodCalls() { $mock = $this->getMockBuilder(stdClass::class) ->setMethods(['foo']) ->getMock(); $mock->expects($this->any()) ->method('foo') ->withConsecutive( ['bar'] ); $this->assertNull($mock->foo('bar')); $this->assertNull($mock->foo(21, 42)); } public function testIntegrationExpectingException() { $mock = $this->getMockBuilder(stdClass::class) ->setMethods(['foo']) ->getMock(); $mock->expects($this->any()) ->method('foo') ->withConsecutive( ['bar'], [21, 42] ); $mock->foo('bar'); $this->expectException(ExpectationFailedException::class); $mock->foo('invalid'); } } phpunit-mock-objects-5.0.6/tests/MockBuilderTest.php000066400000000000000000000073641322406121100225040ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use PHPUnit\Framework\TestCase; use PHPUnit\Framework\MockObject\MockBuilder; class MockBuilderTest extends TestCase { public function testMockBuilderRequiresClassName() { $mock = $this->getMockBuilder(Mockable::class)->getMock(); $this->assertTrue($mock instanceof Mockable); } public function testByDefaultMocksAllMethods() { $mock = $this->getMockBuilder(Mockable::class)->getMock(); $this->assertNull($mock->mockableMethod()); $this->assertNull($mock->anotherMockableMethod()); } public function testMethodsToMockCanBeSpecified() { $mock = $this->getMockBuilder(Mockable::class) ->setMethods(['mockableMethod']) ->getMock(); $this->assertNull($mock->mockableMethod()); $this->assertTrue($mock->anotherMockableMethod()); } public function testMethodExceptionsToMockCanBeSpecified() { $mock = $this->getMockBuilder(Mockable::class) ->setMethodsExcept(['mockableMethod']) ->getMock(); $this->assertTrue($mock->mockableMethod()); $this->assertNull($mock->anotherMockableMethod()); } public function testEmptyMethodExceptionsToMockCanBeSpecified() { $mock = $this->getMockBuilder(Mockable::class) ->setMethodsExcept() ->getMock(); $this->assertNull($mock->mockableMethod()); $this->assertNull($mock->anotherMockableMethod()); } public function testByDefaultDoesNotPassArgumentsToTheConstructor() { $mock = $this->getMockBuilder(Mockable::class)->getMock(); $this->assertEquals([null, null], $mock->constructorArgs); } public function testMockClassNameCanBeSpecified() { $mock = $this->getMockBuilder(Mockable::class) ->setMockClassName('ACustomClassName') ->getMock(); $this->assertTrue($mock instanceof ACustomClassName); } public function testConstructorArgumentsCanBeSpecified() { $mock = $this->getMockBuilder(Mockable::class) ->setConstructorArgs([23, 42]) ->getMock(); $this->assertEquals([23, 42], $mock->constructorArgs); } public function testOriginalConstructorCanBeDisabled() { $mock = $this->getMockBuilder(Mockable::class) ->disableOriginalConstructor() ->getMock(); $this->assertNull($mock->constructorArgs); } public function testByDefaultOriginalCloneIsPreserved() { $mock = $this->getMockBuilder(Mockable::class) ->getMock(); $cloned = clone $mock; $this->assertTrue($cloned->cloned); } public function testOriginalCloneCanBeDisabled() { $mock = $this->getMockBuilder(Mockable::class) ->disableOriginalClone() ->getMock(); $mock->cloned = false; $cloned = clone $mock; $this->assertFalse($cloned->cloned); } public function testProvidesAFluentInterface() { $spec = $this->getMockBuilder(Mockable::class) ->setMethods(['mockableMethod']) ->setConstructorArgs([]) ->setMockClassName('DummyClassName') ->disableOriginalConstructor() ->disableOriginalClone() ->disableAutoload(); $this->assertTrue($spec instanceof MockBuilder); } } phpunit-mock-objects-5.0.6/tests/MockObjectTest.php000066400000000000000000001017301322406121100223140ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use PHPUnit\Framework\ExpectationFailedException; class MockObjectTest extends TestCase { public function testMockedMethodIsNeverCalled() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->never()) ->method('doSomething'); } public function testMockedMethodIsNeverCalledWithParameter() { $mock = $this->getMockBuilder(SomeClass::class) ->getMock(); $mock->expects($this->never()) ->method('doSomething') ->with('someArg'); } /** * @doesNotPerformAssertions */ public function testMockedMethodIsNotCalledWhenExpectsAnyWithParameter() { $mock = $this->getMockBuilder(SomeClass::class) ->getMock(); $mock->expects($this->any()) ->method('doSomethingElse') ->with('someArg'); } /** * @doesNotPerformAssertions */ public function testMockedMethodIsNotCalledWhenMethodSpecifiedDirectlyWithParameter() { $mock = $this->getMockBuilder(SomeClass::class) ->getMock(); $mock->method('doSomethingElse') ->with('someArg'); } public function testMockedMethodIsCalledAtLeastOnce() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->atLeastOnce()) ->method('doSomething'); $mock->doSomething(); } public function testMockedMethodIsCalledAtLeastOnce2() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->atLeastOnce()) ->method('doSomething'); $mock->doSomething(); $mock->doSomething(); } public function testMockedMethodIsCalledAtLeastTwice() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->atLeast(2)) ->method('doSomething'); $mock->doSomething(); $mock->doSomething(); } public function testMockedMethodIsCalledAtLeastTwice2() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->atLeast(2)) ->method('doSomething'); $mock->doSomething(); $mock->doSomething(); $mock->doSomething(); } public function testMockedMethodIsCalledAtMostTwice() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->atMost(2)) ->method('doSomething'); $mock->doSomething(); $mock->doSomething(); } public function testMockedMethodIsCalledAtMosttTwice2() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->atMost(2)) ->method('doSomething'); $mock->doSomething(); } public function testMockedMethodIsCalledOnce() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->once()) ->method('doSomething'); $mock->doSomething(); } public function testMockedMethodIsCalledOnceWithParameter() { $mock = $this->getMockBuilder(SomeClass::class) ->getMock(); $mock->expects($this->once()) ->method('doSomethingElse') ->with($this->equalTo('something')); $mock->doSomethingElse('something'); } public function testMockedMethodIsCalledExactly() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->exactly(2)) ->method('doSomething'); $mock->doSomething(); $mock->doSomething(); } public function testStubbedException() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->any()) ->method('doSomething') ->will($this->throwException(new \Exception())); $this->expectException(\Exception::class); $mock->doSomething(); } public function testStubbedWillThrowException() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->any()) ->method('doSomething') ->willThrowException(new \Exception()); $this->expectException(\Exception::class); $mock->doSomething(); } public function testStubbedReturnValue() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->any()) ->method('doSomething') ->will($this->returnValue('something')); $this->assertEquals('something', $mock->doSomething()); $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $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->getMockBuilder(AnInterface::class) ->getMock(); $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->getMockBuilder(AnInterface::class) ->getMock(); $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->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->any()) ->method('doSomething') ->will($this->returnArgument(1)); $this->assertEquals('b', $mock->doSomething('a', 'b')); $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->any()) ->method('doSomething') ->willReturnArgument(1); $this->assertEquals('b', $mock->doSomething('a', 'b')); } public function testFunctionCallback() { $mock = $this->getMockBuilder(SomeClass::class) ->setMethods(['doSomething']) ->getMock(); $mock->expects($this->once()) ->method('doSomething') ->will($this->returnCallback('functionCallback')); $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); $mock = $this->getMockBuilder(SomeClass::class) ->setMethods(['doSomething']) ->getMock(); $mock->expects($this->once()) ->method('doSomething') ->willReturnCallback('functionCallback'); $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); } public function testStubbedReturnSelf() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->any()) ->method('doSomething') ->will($this->returnSelf()); $this->assertEquals($mock, $mock->doSomething()); $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock->expects($this->any()) ->method('doSomething') ->willReturnSelf(); $this->assertEquals($mock, $mock->doSomething()); } public function testStubbedReturnOnConsecutiveCalls() { $mock = $this->getMockBuilder(AnInterface::class) ->getMock(); $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->getMockBuilder(AnInterface::class) ->getMock(); $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->getMockBuilder(SomeClass::class) ->setMethods(['doSomething']) ->getMock(); $mock->expects($this->once()) ->method('doSomething') ->will($this->returnCallback(['MethodCallback', 'staticCallback'])); $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); } public function testPublicMethodCallback() { $mock = $this->getMockBuilder(SomeClass::class) ->setMethods(['doSomething']) ->getMock(); $mock->expects($this->once()) ->method('doSomething') ->will($this->returnCallback([new MethodCallback, 'nonStaticCallback'])); $this->assertEquals('pass', $mock->doSomething('foo', 'bar')); } public function testMockClassOnlyGeneratedOnce() { $mock1 = $this->getMockBuilder(AnInterface::class) ->getMock(); $mock2 = $this->getMockBuilder(AnInterface::class) ->getMock(); $this->assertEquals(get_class($mock1), get_class($mock2)); } public function testMockClassDifferentForPartialMocks() { $mock1 = $this->getMockBuilder(PartialMockTestClass::class) ->getMock(); $mock2 = $this->getMockBuilder(PartialMockTestClass::class) ->setMethods(['doSomething']) ->getMock(); $mock3 = $this->getMockBuilder(PartialMockTestClass::class) ->setMethods(['doSomething']) ->getMock(); $mock4 = $this->getMockBuilder(PartialMockTestClass::class) ->setMethods(['doAnotherThing']) ->getMock(); $mock5 = $this->getMockBuilder(PartialMockTestClass::class) ->setMethods(['doAnotherThing']) ->getMock(); $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->getMockBuilder(PartialMockTestClass::class) ->getMock(); $mock2 = $this->getMockBuilder(PartialMockTestClass::class) ->setMockClassName('MyMockClassNameForPartialMockTestClass1') ->getMock(); $mock3 = $this->getMockBuilder(PartialMockTestClass::class) ->getMock(); $mock4 = $this->getMockBuilder(PartialMockTestClass::class) ->setMethods(['doSomething']) ->setMockClassName('AnotherMockClassNameForPartialMockTestClass') ->getMock(); $mock5 = $this->getMockBuilder(PartialMockTestClass::class) ->setMockClassName('MyMockClassNameForPartialMockTestClass2') ->getMock(); $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)); } public function testGetMockWithFixedClassNameCanProduceTheSameMockTwice() { $mock = $this->getMockBuilder(stdClass::class)->setMockClassName('FixedName')->getMock(); $mock = $this->getMockBuilder(stdClass::class)->setMockClassName('FixedName')->getMock(); $this->assertInstanceOf(stdClass::class, $mock); } public function testOriginalConstructorSettingConsidered() { $mock1 = $this->getMockBuilder(PartialMockTestClass::class) ->getMock(); $mock2 = $this->getMockBuilder(PartialMockTestClass::class) ->disableOriginalConstructor() ->getMock(); $this->assertTrue($mock1->constructorCalled); $this->assertFalse($mock2->constructorCalled); } public function testOriginalCloneSettingConsidered() { $mock1 = $this->getMockBuilder(PartialMockTestClass::class) ->getMock(); $mock2 = $this->getMockBuilder(PartialMockTestClass::class) ->disableOriginalClone() ->getMock(); $this->assertNotEquals(get_class($mock1), get_class($mock2)); } public function testGetMockForAbstractClass() { $mock = $this->getMockBuilder(AbstractMockTestClass::class) ->getMock(); $mock->expects($this->never()) ->method('doSomething'); } /** * @dataProvider traversableProvider */ public function testGetMockForTraversable($type) { $mock = $this->getMockBuilder($type) ->getMock(); $this->assertInstanceOf(Traversable::class, $mock); } public function testMultipleInterfacesCanBeMockedInSingleObject() { $mock = $this->getMockBuilder([AnInterface::class, AnotherInterface::class]) ->getMock(); $this->assertInstanceOf(AnInterface::class, $mock); $this->assertInstanceOf(AnotherInterface::class, $mock); } public function testGetMockForTrait() { $mock = $this->getMockForTrait(AbstractTrait::class); $mock->expects($this->never()) ->method('doSomething'); $parent = get_parent_class($mock); $traits = class_uses($parent, false); $this->assertContains(AbstractTrait::class, $traits); } public function testClonedMockObjectShouldStillEqualTheOriginal() { $a = $this->getMockBuilder(stdClass::class) ->getMock(); $b = clone $a; $this->assertEquals($a, $b); } public function testMockObjectsConstructedIndepentantlyShouldBeEqual() { $a = $this->getMockBuilder(stdClass::class) ->getMock(); $b = $this->getMockBuilder(stdClass::class) ->getMock(); $this->assertEquals($a, $b); } public function testMockObjectsConstructedIndepentantlyShouldNotBeTheSame() { $a = $this->getMockBuilder(stdClass::class) ->getMock(); $b = $this->getMockBuilder(stdClass::class) ->getMock(); $this->assertNotSame($a, $b); } public function testClonedMockObjectCanBeUsedInPlaceOfOriginalOne() { $x = $this->getMockBuilder(stdClass::class) ->getMock(); $y = clone $x; $mock = $this->getMockBuilder(stdClass::class) ->setMethods(['foo']) ->getMock(); $mock->expects($this->once()) ->method('foo') ->with($this->equalTo($x)); $mock->foo($y); } public function testClonedMockObjectIsNotIdenticalToOriginalOne() { $x = $this->getMockBuilder(stdClass::class) ->getMock(); $y = clone $x; $mock = $this->getMockBuilder(stdClass::class) ->setMethods(['foo']) ->getMock(); $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->getMockBuilder(SomeClass::class) ->setMethods(['right', 'wrong']) ->getMock(); $mock->expects($this->once()) ->method('right'); $mock->wrong(); try { $mock->__phpunit_verify(); $this->fail('Expected exception'); } catch (ExpectationFailedException $e) { $this->assertSame( 'Expectation failed for method name is equal to "right" when invoked 1 time(s).' . PHP_EOL . 'Method was expected to be called 1 times, actually called 0 times.' . PHP_EOL, $e->getMessage() ); } $this->resetMockObjects(); } public function testVerificationOfMethodNameFailsWithParameters() { $mock = $this->getMockBuilder(SomeClass::class) ->setMethods(['right', 'wrong']) ->getMock(); $mock->expects($this->once()) ->method('right'); $mock->wrong(); try { $mock->__phpunit_verify(); $this->fail('Expected exception'); } catch (ExpectationFailedException $e) { $this->assertSame( 'Expectation failed for method name is equal to "right" when invoked 1 time(s).' . PHP_EOL . 'Method was expected to be called 1 times, actually called 0 times.' . PHP_EOL, $e->getMessage() ); } $this->resetMockObjects(); } public function testVerificationOfMethodNameFailsWithWrongParameters() { $mock = $this->getMockBuilder(SomeClass::class) ->setMethods(['right', 'wrong']) ->getMock(); $mock->expects($this->once()) ->method('right') ->with(['first', 'second']); try { $mock->right(['second']); } catch (ExpectationFailedException $e) { $this->assertSame( 'Expectation failed for method name is equal to "right" when invoked 1 time(s)' . PHP_EOL . 'Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.' . PHP_EOL . 'Failed asserting that two arrays are equal.', $e->getMessage() ); } try { $mock->__phpunit_verify(); // CHECKOUT THIS MORE CAREFULLY // $this->fail('Expected exception'); } catch (ExpectationFailedException $e) { $this->assertSame( 'Expectation failed for method name is equal to "right" when invoked 1 time(s).' . PHP_EOL . 'Parameter 0 for invocation SomeClass::right(Array (...)) does not match expected value.' . PHP_EOL . 'Failed asserting that two arrays are equal.' . PHP_EOL . '--- Expected' . PHP_EOL . '+++ Actual' . PHP_EOL . '@@ @@' . PHP_EOL . ' Array (' . PHP_EOL . '- 0 => \'first\'' . PHP_EOL . '- 1 => \'second\'' . PHP_EOL . '+ 0 => \'second\'' . PHP_EOL, $e->getMessage() ); } $this->resetMockObjects(); } public function testVerificationOfNeverFailsWithEmptyParameters() { $mock = $this->getMockBuilder(SomeClass::class) ->setMethods(['right', 'wrong']) ->getMock(); $mock->expects($this->never()) ->method('right') ->with(); try { $mock->right(); $this->fail('Expected exception'); } catch (ExpectationFailedException $e) { $this->assertSame( 'SomeClass::right() was not expected to be called.', $e->getMessage() ); } $this->resetMockObjects(); } public function testVerificationOfNeverFailsWithAnyParameters() { $mock = $this->getMockBuilder(SomeClass::class) ->setMethods(['right', 'wrong']) ->getMock(); $mock->expects($this->never()) ->method('right') ->withAnyParameters(); try { $mock->right(); $this->fail('Expected exception'); } catch (ExpectationFailedException $e) { $this->assertSame( 'SomeClass::right() was not expected to be called.', $e->getMessage() ); } $this->resetMockObjects(); } public function testWithAnythingInsteadOfWithAnyParameters() { $mock = $this->getMockBuilder(SomeClass::class) ->setMethods(['right', 'wrong']) ->getMock(); $mock->expects($this->once()) ->method('right') ->with($this->anything()); try { $mock->right(); $this->fail('Expected exception'); } catch (ExpectationFailedException $e) { $this->assertSame( 'Expectation failed for method name is equal to "right" when invoked 1 time(s)' . PHP_EOL . 'Parameter count for invocation SomeClass::right() is too low.' . PHP_EOL . '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); } /** * @see 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'])); $this->assertNull($foo->bar($a, $b, $c)); } /** * @see 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::class), $b, $c) ->will($this->returnCallback([$foo, 'callback'])); $this->assertNull($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() { $a = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl'); $b = $this->getMockFromWsdl(__DIR__ . '/_fixture/GoogleSearch.wsdl'); $this->assertStringStartsWith('Mock_GoogleSearch_', get_class($a)); $this->assertEquals(get_class($a), get_class($b)); } /** * @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/156 * @ticket 156 */ public function testInterfaceWithStaticMethodCanBeStubbed() { $this->assertInstanceOf( InterfaceWithStaticMethod::class, $this->getMockBuilder(InterfaceWithStaticMethod::class)->getMock() ); } public function testInvokingStubbedStaticMethodRaisesException() { $mock = $this->getMockBuilder(ClassWithStaticMethod::class)->getMock(); $this->expectException(\PHPUnit\Framework\MockObject\BadMethodCallException::class); $mock->staticMethod(); } /** * @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/171 * @ticket 171 */ public function testStubForClassThatImplementsSerializableCanBeCreatedWithoutInvokingTheConstructor() { $this->assertInstanceOf( ClassThatImplementsSerializable::class, $this->getMockBuilder(ClassThatImplementsSerializable::class) ->disableOriginalConstructor() ->getMock() ); } public function testGetMockForClassWithSelfTypeHint() { $this->assertInstanceOf( ClassWithSelfTypeHint::class, $this->getMockBuilder(ClassWithSelfTypeHint::class)->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->getMockBuilder(StringableClass::class)->getMock(); $this->assertInternalType('string', (string) $mock); } public function testStringableClassCanBeMocked() { $mock = $this->getMockBuilder(StringableClass::class)->getMock(); $mock->method('__toString')->willReturn('foo'); $this->assertSame('foo', (string) $mock); } public function traversableProvider() { return [ ['Traversable'], ['\Traversable'], ['TraversableMockTestInterface'], [['Traversable']], [['Iterator','Traversable']], [['\Iterator','\Traversable']] ]; } public function testParameterCallbackConstraintOnlyEvaluatedOnce() { $mock = $this->getMockBuilder(Foo::class)->setMethods(['bar'])->getMock(); $expectedNumberOfCalls = 1; $callCount = 0; $mock->expects($this->exactly($expectedNumberOfCalls))->method('bar') ->with($this->callback(function ($argument) use (&$callCount) { return $argument === 'call_' . $callCount++; })); for ($i = 0; $i < $expectedNumberOfCalls; $i++) { $mock->bar('call_' . $i); } } public function testReturnTypesAreMockedCorrectly() { /** @var ClassWithAllPossibleReturnTypes|MockObject $stub */ $stub = $this->createMock(ClassWithAllPossibleReturnTypes::class); $this->assertNull($stub->methodWithNoReturnTypeDeclaration()); $this->assertSame('', $stub->methodWithStringReturnTypeDeclaration()); $this->assertSame(0.0, $stub->methodWithFloatReturnTypeDeclaration()); $this->assertSame(0, $stub->methodWithIntReturnTypeDeclaration()); $this->assertFalse($stub->methodWithBoolReturnTypeDeclaration()); $this->assertSame([], $stub->methodWithArrayReturnTypeDeclaration()); $this->assertInstanceOf(MockObject::class, $stub->methodWithClassReturnTypeDeclaration()); } /** * @requires PHP 7.1 */ public function testVoidReturnTypeIsMockedCorrectly() { /** @var ClassWithAllPossibleReturnTypes|MockObject $stub */ $stub = $this->createMock(ClassWithAllPossibleReturnTypes::class); $this->assertNull($stub->methodWithVoidReturnTypeDeclaration()); } /** * @requires PHP 7.2 */ public function testObjectReturnTypeIsMockedCorrectly() { /** @var ClassWithAllPossibleReturnTypes|MockObject $stub */ $stub = $this->createMock(ClassWithAllPossibleReturnTypes::class); $this->assertInstanceOf(stdClass::class, $stub->methodWithObjectReturnTypeDeclaration()); } } phpunit-mock-objects-5.0.6/tests/ProxyObjectTest.php000066400000000000000000000020741322406121100225450ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ use PHPUnit\Framework\TestCase; class ProxyObjectTest extends TestCase { public function testMockedMethodIsProxiedToOriginalMethod() { $proxy = $this->getMockBuilder(Bar::class) ->enableProxyingToOriginalMethods() ->getMock(); $proxy->expects($this->once()) ->method('doSomethingElse'); $foo = new Foo; $this->assertEquals('result', $foo->doSomething($proxy)); } public function testMockedMethodWithReferenceIsProxiedToOriginalMethod() { $proxy = $this->getMockBuilder(MethodCallbackByReference::class) ->enableProxyingToOriginalMethods() ->getMock(); $a = $b = $c = 0; $proxy->callback($a, $b, $c); $this->assertEquals(1, $b); } } phpunit-mock-objects-5.0.6/tests/_fixture/000077500000000000000000000000001322406121100205465ustar00rootroot00000000000000phpunit-mock-objects-5.0.6/tests/_fixture/AbstractMockTestClass.php000066400000000000000000000002741322406121100254650ustar00rootroot00000000000000 $value) { $this->{$key} = $value; } } } phpunit-mock-objects-5.0.6/tests/_fixture/ClassWithAllPossibleReturnTypes.php000066400000000000000000000022061322406121100275370ustar00rootroot00000000000000doSomethingElse(); } } phpunit-mock-objects-5.0.6/tests/_fixture/FunctionCallback.php000066400000000000000000000002041322406121100244550ustar00rootroot00000000000000 phpunit-mock-objects-5.0.6/tests/_fixture/InterfaceWithSemiReservedMethodName.php000066400000000000000000000001251322406121100302710ustar00rootroot00000000000000constructorArgs = [$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-5.0.6/tests/_fixture/PartialMockTestClass.php000066400000000000000000000004051322406121100253120ustar00rootroot00000000000000constructorCalled = true; } public function doSomething() { } public function doAnotherThing() { } } phpunit-mock-objects-5.0.6/tests/_fixture/SingletonClass.php000066400000000000000000000005151322406121100242100ustar00rootroot00000000000000