diff --git a/src/Framework/Exception/IncompatibleReturnValueException.php b/src/Framework/Exception/IncompatibleReturnValueException.php new file mode 100644 index 00000000000..9e1c2147cc9 --- /dev/null +++ b/src/Framework/Exception/IncompatibleReturnValueException.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Framework; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class IncompatibleReturnValueException extends Exception +{ +} diff --git a/src/Framework/MockObject/Builder/InvocationMocker.php b/src/Framework/MockObject/Builder/InvocationMocker.php index 9186c26faa6..d3b568688e2 100644 --- a/src/Framework/MockObject/Builder/InvocationMocker.php +++ b/src/Framework/MockObject/Builder/InvocationMocker.php @@ -10,6 +10,8 @@ namespace PHPUnit\Framework\MockObject\Builder; use PHPUnit\Framework\Constraint\Constraint; +use PHPUnit\Framework\IncompatibleReturnValueException; +use PHPUnit\Framework\MockObject\ConfigurableMethod; use PHPUnit\Framework\MockObject\Matcher; use PHPUnit\Framework\MockObject\Matcher\Invocation; use PHPUnit\Framework\MockObject\RuntimeException; @@ -32,11 +34,11 @@ final class InvocationMocker implements MethodNameMatch private $matcher; /** - * @var string[] + * @var ConfigurableMethod[] */ private $configurableMethods; - public function __construct(MatcherCollection $collection, Invocation $invocationMatcher, array $configurableMethods) + public function __construct(MatcherCollection $collection, Invocation $invocationMatcher, ConfigurableMethod... $configurableMethods) { $this->collection = $collection; $this->matcher = new Matcher($invocationMatcher); @@ -68,11 +70,12 @@ public function will(Stub $stub): Identity public function willReturn($value, ...$nextValues): self { if (\count($nextValues) === 0) { + $this->ensureTypeOfReturnValues([$value]); $stub = new Stub\ReturnStub($value); } else { - $stub = new Stub\ConsecutiveCalls( - \array_merge([$value], $nextValues) - ); + $values = \array_merge([$value], $nextValues); + $this->ensureTypeOfReturnValues($values); + $stub = new Stub\ConsecutiveCalls($values); } return $this->will($stub); @@ -193,7 +196,13 @@ public function method($constraint): self ); } - if (\is_string($constraint) && !\in_array(\strtolower($constraint), $this->configurableMethods, true)) { + $configurableMethodNames = array_map( + function (ConfigurableMethod $configurable) { + return strtolower($configurable->getName()); + }, + $this->configurableMethods + ); + if (\is_string($constraint) && !\in_array(\strtolower($constraint), $configurableMethodNames, true)) { 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', @@ -227,4 +236,36 @@ private function canDefineParameters(): void ); } } + + private function getConfiguredMethod(): ?ConfigurableMethod + { + $configuredMethod = null; + foreach ($this->configurableMethods as $configurableMethod) { + if ($this->matcher->getMethodNameMatcher()->matchesMethodName($configurableMethod->getName())) { + if ($configuredMethod !== null) { + return null; + } + $configuredMethod = $configurableMethod; + } + } + return $configuredMethod; + } + + private function ensureTypeOfReturnValues(array $values): void + { + $configuredMethod = $this->getConfiguredMethod(); + if ($configuredMethod === null) { + return; + } + foreach ($values as $value) { + if (!$configuredMethod->mayReturn($value)) { + throw new IncompatibleReturnValueException(sprintf( + 'Method %s may not return value of type %s', + $configuredMethod->getName(), + gettype($value) + )); + } + } + } + } diff --git a/src/Framework/MockObject/ConfigurableMethod.php b/src/Framework/MockObject/ConfigurableMethod.php new file mode 100644 index 00000000000..0bf094fcdb6 --- /dev/null +++ b/src/Framework/MockObject/ConfigurableMethod.php @@ -0,0 +1,39 @@ +name = $name; + $this->returnType = $returnType; + } + + public function getName(): string + { + return $this->name; + } + + public function mayReturn($value): bool + { + if (isNull($value) && $this->returnType->allowsNull()) { + return true; + } + return $this->returnType->isAssignable(Type::fromValue($value, false)); + } + +} diff --git a/src/Framework/MockObject/ConfigurableMethods.php b/src/Framework/MockObject/ConfigurableMethods.php new file mode 100644 index 00000000000..5eb2e5e9de3 --- /dev/null +++ b/src/Framework/MockObject/ConfigurableMethods.php @@ -0,0 +1,29 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPUnit\Framework\MockObject; + +trait ConfigurableMethods +{ + + /** + * @var ConfigurableMethods[] + */ + private static $__phpunit_configurableMethods; + + public static function __phpunit_initConfigurableMethods(\PHPUnit\Framework\MockObject\ConfigurableMethod... $configurable) + { + if (isset(static::$__phpunit_configurableMethods)) { + // TODO: improve exception + throw new \Exception('nogo!'); + } + static::$__phpunit_configurableMethods = $configurable; + } +} diff --git a/src/Framework/MockObject/Generator.php b/src/Framework/MockObject/Generator.php index 20fee252bb1..cf9d53e6afb 100644 --- a/src/Framework/MockObject/Generator.php +++ b/src/Framework/MockObject/Generator.php @@ -167,8 +167,7 @@ function ($type) { ); return $this->getObject( - $mock['code'], - $mock['mockClassName'], + $mock, $type, $callOriginalConstructor, $callAutoload, @@ -263,10 +262,8 @@ public function getMockForTrait(string $traitName, array $arguments = [], string ] ); - $this->evalClass( - $classTemplate->render(), - $className['className'] - ); + $mockClass = new MockTrait($classTemplate->render(), $className['className']); + $mockClass->bringIntoExistence(); return $this->getMockForAbstractClass($className['className'], $arguments, $mockClassName, $callOriginalConstructor, $callOriginalClone, $callAutoload, $mockedMethods, $cloneArguments); } @@ -303,15 +300,10 @@ public function getObjectForTrait(string $traitName, string $traitClassName = '' ] ); - return $this->getObject($classTemplate->render(), $className['className']); + return $this->getObject(new MockTrait($classTemplate->render(), $className['className'])); } - /** - * @param array|string $type - * - * @throws RuntimeException - */ - public function generate($type, array $methods = null, string $mockClassName = '', bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = true, bool $callOriginalMethods = false): array + public function generate($type, array $methods = null, string $mockClassName = '', bool $callOriginalClone = true, bool $callAutoload = true, bool $cloneArguments = true, bool $callOriginalMethods = false): MockClass { if (\is_array($type)) { \sort($type); @@ -522,14 +514,9 @@ private function getInterfaceOwnMethods(string $interfaceName): array return $methods; } - /** - * @param array|string $type - * - * @throws RuntimeException - */ - private function getObject(string $code, string $className, $type = '', bool $callOriginalConstructor = false, bool $callAutoload = false, array $arguments = [], bool $callOriginalMethods = false, object $proxyTarget = null, bool $returnValueGeneration = true) + private function getObject(MockBrick $mockClass, $type = '', bool $callOriginalConstructor = false, bool $callAutoload = false, array $arguments = [], bool $callOriginalMethods = false, object $proxyTarget = null, bool $returnValueGeneration = true) { - $this->evalClass($code, $className); + $className = $mockClass->bringIntoExistence(); if ($callOriginalConstructor && \is_string($type) && @@ -586,20 +573,12 @@ private function getObject(string $code, string $className, $type = '', bool $ca return $object; } - private function evalClass(string $code, string $className): void - { - if (!\class_exists($className, false)) { - eval($code); - } - } - /** * @param array|string $type - * @param null|array $explicitMethods * * @throws RuntimeException */ - private function generateMock($type, $explicitMethods, string $mockClassName, bool $callOriginalClone, bool $callAutoload, bool $cloneArguments, bool $callOriginalMethods): array + private function generateMock($type, ?array $explicitMethods, string $mockClassName, bool $callOriginalClone, bool $callAutoload, bool $cloneArguments, bool $callOriginalMethods): MockClass { $classTemplate = $this->getTemplate('mocked_class.tpl'); @@ -821,7 +800,7 @@ private function generateMock($type, $explicitMethods, string $mockClassName, bo foreach ($mockMethods->asArray() as $mockMethod) { $mockedMethods .= $mockMethod->generateCode(); - $configurable[] = \strtolower($mockMethod->getName()); + $configurable[] = new ConfigurableMethod($mockMethod->getName(), $mockMethod->getReturnType()); } $method = ''; @@ -843,22 +822,14 @@ private function generateMock($type, $explicitMethods, string $mockClassName, bo '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'], - ]; + return new MockClass( + $classTemplate->render(), + $mockClassName['className'], + $configurable + ); } /** diff --git a/src/Framework/MockObject/Generator/mocked_class.tpl.dist b/src/Framework/MockObject/Generator/mocked_class.tpl.dist index cff1dbfc8a1..3628b685b24 100644 --- a/src/Framework/MockObject/Generator/mocked_class.tpl.dist +++ b/src/Framework/MockObject/Generator/mocked_class.tpl.dist @@ -1,8 +1,11 @@ +declare(strict_types=1); + {prologue}{class_declaration} { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = {configurable}; private $__phpunit_returnValueGeneration = true; {clone}{mocked_methods} @@ -24,7 +27,7 @@ public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/src/Framework/MockObject/Generator/mocked_method.tpl.dist b/src/Framework/MockObject/Generator/mocked_method.tpl.dist index cff0cffcbf3..5e69c792d13 100644 --- a/src/Framework/MockObject/Generator/mocked_method.tpl.dist +++ b/src/Framework/MockObject/Generator/mocked_method.tpl.dist @@ -1,5 +1,5 @@ - {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} + {modifier} function {reference}{method_name}({arguments_decl}){return_declaration} {{deprecation} $__phpunit_arguments = [{arguments_call}]; $__phpunit_count = func_num_args(); @@ -14,7 +14,7 @@ $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments} + '{class_name}', '{method_name}', $__phpunit_arguments, '{return_declaration}', $this, {clone_arguments} ) ); diff --git a/src/Framework/MockObject/Generator/mocked_method_void.tpl.dist b/src/Framework/MockObject/Generator/mocked_method_void.tpl.dist index fe267f4cd3f..ecef25e2449 100644 --- a/src/Framework/MockObject/Generator/mocked_method_void.tpl.dist +++ b/src/Framework/MockObject/Generator/mocked_method_void.tpl.dist @@ -1,5 +1,5 @@ - {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} + {modifier} function {reference}{method_name}({arguments_decl}){return_declaration} {{deprecation} $__phpunit_arguments = [{arguments_call}]; $__phpunit_count = func_num_args(); @@ -14,7 +14,7 @@ $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments} + '{class_name}', '{method_name}', $__phpunit_arguments, '{return_declaration}', $this, {clone_arguments} ) ); } diff --git a/src/Framework/MockObject/Generator/mocked_static_method.tpl.dist b/src/Framework/MockObject/Generator/mocked_static_method.tpl.dist index 56b561b65f2..5e5cf23cddd 100644 --- a/src/Framework/MockObject/Generator/mocked_static_method.tpl.dist +++ b/src/Framework/MockObject/Generator/mocked_static_method.tpl.dist @@ -1,5 +1,5 @@ - {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} + {modifier} function {reference}{method_name}({arguments_decl}){return_declaration} { throw new \PHPUnit\Framework\MockObject\BadMethodCallException('Static method "{method_name}" cannot be invoked on mock object'); } diff --git a/src/Framework/MockObject/Generator/proxied_method.tpl.dist b/src/Framework/MockObject/Generator/proxied_method.tpl.dist index ca94a5f1598..59fc6dd93ce 100644 --- a/src/Framework/MockObject/Generator/proxied_method.tpl.dist +++ b/src/Framework/MockObject/Generator/proxied_method.tpl.dist @@ -1,5 +1,5 @@ - {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} + {modifier} function {reference}{method_name}({arguments_decl}){return_declaration} { $__phpunit_arguments = [{arguments_call}]; $__phpunit_count = func_num_args(); @@ -14,7 +14,7 @@ $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments}, true + '{class_name}', '{method_name}', $__phpunit_arguments, '{return_declaration}', $this, {clone_arguments}, true ) ); diff --git a/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist b/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist index 6208319b541..099e83815c7 100644 --- a/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist +++ b/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist @@ -1,5 +1,5 @@ - {modifier} function {reference}{method_name}({arguments_decl}){return_delim}{return_type} + {modifier} function {reference}{method_name}({arguments_decl}){return_declaration} { $__phpunit_arguments = [{arguments_call}]; $__phpunit_count = func_num_args(); @@ -14,7 +14,7 @@ $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments}, true + '{class_name}', '{method_name}', $__phpunit_arguments, '{return_declaration}', $this, {clone_arguments}, true ) ); diff --git a/src/Framework/MockObject/Generator/trait_class.tpl.dist b/src/Framework/MockObject/Generator/trait_class.tpl.dist index 4143b0f66af..a8fe470fdc4 100644 --- a/src/Framework/MockObject/Generator/trait_class.tpl.dist +++ b/src/Framework/MockObject/Generator/trait_class.tpl.dist @@ -1,3 +1,5 @@ +declare(strict_types=1); + {prologue}class {class_name} { use {trait_name}; diff --git a/src/Framework/MockObject/Generator/wsdl_class.tpl.dist b/src/Framework/MockObject/Generator/wsdl_class.tpl.dist index cc69fd341cc..b3100b41417 100644 --- a/src/Framework/MockObject/Generator/wsdl_class.tpl.dist +++ b/src/Framework/MockObject/Generator/wsdl_class.tpl.dist @@ -1,3 +1,5 @@ +declare(strict_types=1); + {namespace}class {class_name} extends \SoapClient { public function __construct($wsdl, array $options) diff --git a/src/Framework/MockObject/Invocation.php b/src/Framework/MockObject/Invocation.php index 9224c10190f..dada8047526 100644 --- a/src/Framework/MockObject/Invocation.php +++ b/src/Framework/MockObject/Invocation.php @@ -61,6 +61,8 @@ public function __construct(string $className, string $methodName, array $parame $this->object = $object; $this->proxiedCall = $proxiedCall; + $returnType = ltrim($returnType, ': '); + if (\strtolower($methodName) === '__tostring') { $returnType = 'string'; } diff --git a/src/Framework/MockObject/InvocationMocker.php b/src/Framework/MockObject/InvocationMocker.php index c56372d3e1c..b623bd3e15e 100644 --- a/src/Framework/MockObject/InvocationMocker.php +++ b/src/Framework/MockObject/InvocationMocker.php @@ -93,7 +93,7 @@ public function expects(MatcherInvocation $matcher): BuilderInvocationMocker return new BuilderInvocationMocker( $this, $matcher, - $this->configurableMethods + ...$this->configurableMethods ); } diff --git a/src/Framework/MockObject/Matcher/MethodName.php b/src/Framework/MockObject/Matcher/MethodName.php index 5855ee2ea20..cfb55357530 100644 --- a/src/Framework/MockObject/Matcher/MethodName.php +++ b/src/Framework/MockObject/Matcher/MethodName.php @@ -62,4 +62,8 @@ public function matches(BaseInvocation $invocation): bool { return $this->constraint->evaluate($invocation->getMethodName(), '', true); } + + public function matchesMethodName(string $methodName) : bool { + return $this->constraint->evaluate($methodName, '', true); + } } diff --git a/src/Framework/MockObject/MockBrick.php b/src/Framework/MockObject/MockBrick.php new file mode 100644 index 00000000000..2869e2f62f2 --- /dev/null +++ b/src/Framework/MockObject/MockBrick.php @@ -0,0 +1,8 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPUnit\Framework\MockObject; + +class MockClass implements MockBrick +{ + + /** + * @var string + */ + private $classCode; + + /** + * @var string + */ + private $mockName; + + /** + * @var ConfigurableMethod[] + */ + private $configurableMethods; + + public function __construct(string $classCode, string $mockName, array $configurableMethods) + { + $this->classCode = $classCode; + $this->mockName = $mockName; + $this->configurableMethods = $configurableMethods; + } + + public function getClassCode(): string + { + return $this->classCode; + } + + private function getMockName(): string + { + return $this->mockName; + } + + public function bringIntoExistence(): string + { + if (!\class_exists($this->getMockName(), false)) { + eval($this->getClassCode()); + call_user_func(array($this->getMockName(), '__phpunit_initConfigurableMethods'), ...$this->configurableMethods); + } + return $this->getMockName(); + } + +} diff --git a/src/Framework/MockObject/MockMethod.php b/src/Framework/MockObject/MockMethod.php index 793cbe8d2ff..7e2a66663c6 100644 --- a/src/Framework/MockObject/MockMethod.php +++ b/src/Framework/MockObject/MockMethod.php @@ -7,6 +7,7 @@ * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ + namespace PHPUnit\Framework\MockObject; /** @@ -50,7 +51,7 @@ final class MockMethod private $argumentsForCall; /** - * @var string + * @var Type */ private $returnType; @@ -84,6 +85,8 @@ final class MockMethod */ public static function fromReflection(\ReflectionMethod $method, bool $callOriginalMethod, bool $cloneArguments): self { + $className = $method->getDeclaringClass()->getName(); + if ($method->isPrivate()) { $modifier = 'private'; } elseif ($method->isProtected()) { @@ -102,12 +105,6 @@ public static function fromReflection(\ReflectionMethod $method, bool $callOrigi $reference = ''; } - if ($method->hasReturnType()) { - $returnType = (string) $method->getReturnType(); - } else { - $returnType = ''; - } - $docComment = $method->getDocComment(); if (\is_string($docComment) && @@ -118,13 +115,13 @@ public static function fromReflection(\ReflectionMethod $method, bool $callOrigi } return new self( - $method->getDeclaringClass()->getName(), + $className, $method->getName(), $cloneArguments, $modifier, self::getMethodParameters($method), self::getMethodParameters($method, true), - $returnType, + self::deriveReturnType($method), $reference, $callOriginalMethod, $method->isStatic(), @@ -142,7 +139,7 @@ public static function fromName(string $fullClassName, string $methodName, bool 'public', '', '', - '', + new UnknownType(), '', false, false, @@ -151,20 +148,20 @@ public static function fromName(string $fullClassName, string $methodName, bool ); } - public function __construct(string $className, string $methodName, bool $cloneArguments, string $modifier, string $argumentsForDeclaration, string $argumentsForCall, string $returnType, string $reference, bool $callOriginalMethod, bool $static, ?string $deprecation, bool $allowsReturnNull) + public function __construct(string $className, string $methodName, bool $cloneArguments, string $modifier, string $argumentsForDeclaration, string $argumentsForCall, Type $returnType, string $reference, bool $callOriginalMethod, bool $static, ?string $deprecation, bool $allowsReturnNull) { - $this->className = $className; - $this->methodName = $methodName; - $this->cloneArguments = $cloneArguments; - $this->modifier = $modifier; + $this->className = $className; + $this->methodName = $methodName; + $this->cloneArguments = $cloneArguments; + $this->modifier = $modifier; $this->argumentsForDeclaration = $argumentsForDeclaration; - $this->argumentsForCall = $argumentsForCall; - $this->returnType = $returnType; - $this->reference = $reference; - $this->callOriginalMethod = $callOriginalMethod; - $this->static = $static; - $this->deprecation = $deprecation; - $this->allowsReturnNull = $allowsReturnNull; + $this->argumentsForCall = $argumentsForCall; + $this->returnType = $returnType; + $this->reference = $reference; + $this->callOriginalMethod = $callOriginalMethod; + $this->static = $static; + $this->deprecation = $deprecation; + $this->allowsReturnNull = $allowsReturnNull; } public function getName(): string @@ -179,7 +176,7 @@ public function generateCode(): string { if ($this->static) { $templateFile = 'mocked_static_method.tpl'; - } elseif ($this->returnType === 'void') { + } elseif ($this->returnType->getReturnTypeDeclaration() === ': void') { $templateFile = \sprintf( '%s_method_void.tpl', $this->callOriginalMethod ? 'proxied' : 'mocked' @@ -191,43 +188,10 @@ public function generateCode(): string ); } - $returnType = $this->returnType; - - // @see https://bugs.php.net/bug.php?id=70722 - if ($returnType === 'self') { - $returnType = $this->className; - } - - // @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/406 - if ($returnType === 'parent') { - try { - $parentClass = (new \ReflectionClass($this->className))->getParentClass(); - } catch (\ReflectionException $e) { - throw new RuntimeException( - $e->getMessage(), - (int) $e->getCode(), - $e - ); - } - - if ($parentClass === false) { - throw new RuntimeException( - \sprintf( - 'Cannot mock %s::%s because "parent" return type declaration is used but %s does not have a parent class', - $this->className, - $this->methodName, - $this->className - ) - ); - } - - $returnType = $parentClass->getName(); - } - $deprecation = $this->deprecation; if (null !== $this->deprecation) { - $deprecation = "The $this->className::$this->methodName method is deprecated ($this->deprecation)."; + $deprecation = "The $this->className::$this->methodName method is deprecated ($this->deprecation)."; $deprecationTemplate = $this->getTemplate('deprecation.tpl'); $deprecationTemplate->setVar([ @@ -241,17 +205,16 @@ public function generateCode(): string $template->setVar( [ - 'arguments_decl' => $this->argumentsForDeclaration, - 'arguments_call' => $this->argumentsForCall, - 'return_delim' => $returnType ? ': ' : '', - 'return_type' => $this->allowsReturnNull ? '?' . $returnType : $returnType, + 'arguments_decl' => $this->argumentsForDeclaration, + 'arguments_call' => $this->argumentsForCall, + 'return_declaration' => $this->returnType->getReturnTypeDeclaration(), 'arguments_count' => !empty($this->argumentsForCall) ? \substr_count($this->argumentsForCall, ',') + 1 : 0, - 'class_name' => $this->className, - 'method_name' => $this->methodName, - 'modifier' => $this->modifier, - 'reference' => $this->reference, + 'class_name' => $this->className, + 'method_name' => $this->methodName, + 'modifier' => $this->modifier, + 'reference' => $this->reference, 'clone_arguments' => $this->cloneArguments ? 'true' : 'false', - 'deprecation' => $deprecation, + 'deprecation' => $deprecation, ] ); @@ -296,9 +259,9 @@ private static function getMethodParameters(\ReflectionMethod $method, bool $for $name = '...' . $name; } - $nullable = ''; - $default = ''; - $reference = ''; + $nullable = ''; + $default = ''; + $reference = ''; $typeDeclaration = ''; if (!$forCall) { @@ -306,7 +269,7 @@ private static function getMethodParameters(\ReflectionMethod $method, bool $for $nullable = '?'; } - if ($parameter->hasType() && (string) $parameter->getType() !== 'self') { + if ($parameter->hasType() && (string)$parameter->getType() !== 'self') { $typeDeclaration = $parameter->getType() . ' '; } else { try { @@ -336,7 +299,7 @@ private static function getMethodParameters(\ReflectionMethod $method, bool $for } catch (\ReflectionException $e) { throw new RuntimeException( $e->getMessage(), - (int) $e->getCode(), + (int)$e->getCode(), $e ); } @@ -347,13 +310,13 @@ private static function getMethodParameters(\ReflectionMethod $method, bool $for } catch (\ReflectionException $e) { throw new RuntimeException( $e->getMessage(), - (int) $e->getCode(), + (int)$e->getCode(), $e ); } } elseif (!\defined($value)) { $rootValue = \preg_replace('/^.*\\\\/', '', $value); - $value = \defined($rootValue) ? $rootValue : $value; + $value = \defined($rootValue) ? $rootValue : $value; } $default = ' = ' . $value; @@ -372,4 +335,43 @@ private static function getMethodParameters(\ReflectionMethod $method, bool $for return \implode(', ', $parameters); } + + private static function deriveReturnType(\ReflectionMethod $method): ?Type + { + $returnType = $method->getReturnType(); + + if ($returnType === null) { + return new UnknownType(); + } + + // @see https://bugs.php.net/bug.php?id=70722 + if ($returnType->getName() === 'self') { + return ObjectType::fromName($method->getDeclaringClass()->getName(), $returnType->allowsNull()); + } + + // @see https://github.com/sebastianbergmann/phpunit-mock-objects/issues/406 + if ($returnType->getName() === 'parent') { + $parentClass = $method->getDeclaringClass()->getParentClass(); + + if ($parentClass === false) { + throw new RuntimeException( + \sprintf( + 'Cannot mock %s::%s because "parent" return type declaration is used but %s does not have a parent class', + $method->getDeclaringClass()->getName(), + $method->getName(), + $method->getDeclaringClass()->getName() + ) + ); + } + + return ObjectType::fromName($parentClass->getName(), $returnType->allowsNull()); + } + + return Type::fromName($returnType->getName(), $returnType->allowsNull()); + } + + public function getReturnType(): Type + { + return $this->returnType; + } } diff --git a/src/Framework/MockObject/MockTrait.php b/src/Framework/MockObject/MockTrait.php new file mode 100644 index 00000000000..6634ce33787 --- /dev/null +++ b/src/Framework/MockObject/MockTrait.php @@ -0,0 +1,50 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPUnit\Framework\MockObject; + +class MockTrait implements MockBrick +{ + + /** + * @var string + */ + private $classCode; + + /** + * @var string + */ + private $mockName; + + public function __construct(string $classCode, string $mockName) + { + $this->classCode = $classCode; + $this->mockName = $mockName; + } + + public function getClassCode(): string + { + return $this->classCode; + } + + public function getMockName(): string + { + return $this->mockName; + } + + public function bringIntoExistence(): string + { + if (!\class_exists($this->getMockName(), false)) { + eval($this->getClassCode()); + } + return $this->getMockName(); + } + +} diff --git a/src/Framework/MockObject/ObjectType.php b/src/Framework/MockObject/ObjectType.php new file mode 100644 index 00000000000..0bf40b863db --- /dev/null +++ b/src/Framework/MockObject/ObjectType.php @@ -0,0 +1,52 @@ +className = $className; + $this->allowsNull = $nullable; + } + + public function isAssignable(Type $other): bool + { + if ($this->allowsNull && isNull($other)) { + return true; + } + if ($other instanceof self) { + if ($this->className->getQualifiedName() === $other->className->getQualifiedName()) { + return true; + } + + if (is_subclass_of($other->className->getQualifiedName(), $this->className->getQualifiedName(), true)) { + return true; + } + } + return false; + } + + public function getReturnTypeDeclaration(): string + { + return ': ' . ($this->allowsNull ? '?' : '') . $this->className->getQualifiedName(); + } + + public function allowsNull(): bool + { + return $this->allowsNull; + } +} diff --git a/src/Framework/MockObject/SimpleType.php b/src/Framework/MockObject/SimpleType.php new file mode 100644 index 00000000000..5c0cecc6bde --- /dev/null +++ b/src/Framework/MockObject/SimpleType.php @@ -0,0 +1,64 @@ +name = $this->normalize($name); + $this->allowsNull = $nullable; + } + + public function isAssignable(Type $other): bool + { + if ($this->allowsNull && isNull($other)) { + return true; + } + if ($other instanceof self) { + return $this->name === $other->name; + } + return false; + } + + public function getReturnTypeDeclaration(): string + { + return ': ' . ($this->allowsNull ? '?' : '') . $this->name; + } + + public function allowsNull(): bool + { + return $this->allowsNull; + } + + private function normalize(string $name): string + { + $name = mb_strtolower($name); + switch ($name) { + case 'boolean': + return 'bool'; + case 'real': + case 'double': + return 'float'; + case 'integer': + return 'int'; + case '[]': + return 'array'; + default: + return $name; + } + } +} diff --git a/src/Framework/MockObject/Type.php b/src/Framework/MockObject/Type.php new file mode 100644 index 00000000000..398cd5c69a8 --- /dev/null +++ b/src/Framework/MockObject/Type.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Framework\MockObject; + + +abstract class Type +{ + + public static function fromValue($value, bool $allowsNull): Type + { + $type = gettype($value); + switch ($type) { + case 'object': + return self::fromName(get_class($value), $allowsNull); + default: + return new SimpleType($type, $allowsNull); + } + } + + public static function fromName(?string $typeName, bool $allowsNull): Type + { + switch (mb_strtolower($typeName)) { + case null: + case 'unknown type': + return new UnknownType(); + case 'object': + case 'boolean': + case 'bool': + case 'integer': + case 'int': + case 'real': + case 'double': + case 'float': + case 'string': + case 'array': + case 'resource': + case 'resource (closed)': + return new SimpleType($typeName, $allowsNull); + default: + return new ObjectType(TypeName::fromQualifiedName($typeName), $allowsNull); + } + } + + abstract public function isAssignable(Type $other): bool; + + abstract public function getReturnTypeDeclaration(): string; + + abstract public function allowsNull(): bool; + +} diff --git a/src/Framework/MockObject/TypeName.php b/src/Framework/MockObject/TypeName.php new file mode 100644 index 00000000000..b5377d923f6 --- /dev/null +++ b/src/Framework/MockObject/TypeName.php @@ -0,0 +1,79 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Framework\MockObject; + +/** + * @internal This class is not covered by the backward compatibility promise for PHPUnit + */ +final class TypeName +{ + /** + * @var ?string + */ + private $namespaceName; + + /** + * @var string + */ + private $simpleName; + + public static function fromQualifiedName(string $fullClassName): self + { + if ($fullClassName[0] === '\\') { + $fullClassName = \substr($fullClassName, 1); + } + + $classNameParts = \explode('\\', $fullClassName); + + $simpleName = \array_pop($classNameParts); + $namespaceName = \implode('\\', $classNameParts); + + return new self($namespaceName, $simpleName); + } + + public static function fromReflection(\ReflectionClass $type): self + { + return new self( + $type->getNamespaceName(), + $type->getShortName() + ); + } + + public function __construct(?string $namespaceName, string $simpleName) + { + if ($namespaceName === '') { + $namespaceName = null; + } + $this->namespaceName = $namespaceName; + $this->simpleName = $simpleName; + } + + public function getNamespaceName(): ?string + { + return $this->namespaceName; + } + + public function getSimpleName(): string + { + return $this->simpleName; + } + + public function getQualifiedName(): string + { + return $this->isNamespaced() + ? $this->namespaceName . '\\' . $this->simpleName + : $this->simpleName; + } + + public function isNamespaced(): bool + { + return $this->namespaceName !== null; + } +} diff --git a/src/Framework/MockObject/UnknownType.php b/src/Framework/MockObject/UnknownType.php new file mode 100644 index 00000000000..108dcf7eed2 --- /dev/null +++ b/src/Framework/MockObject/UnknownType.php @@ -0,0 +1,23 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Framework\MockObject; + +class ChildClass extends ParentClass +{ +} diff --git a/tests/_files/mock-object/ClassAUsingConfigurableMethods.php b/tests/_files/mock-object/ClassAUsingConfigurableMethods.php new file mode 100644 index 00000000000..2adf0ab144d --- /dev/null +++ b/tests/_files/mock-object/ClassAUsingConfigurableMethods.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPUnit\Framework\MockObject; + +class ClassAUsingConfigurableMethods { + use ConfigurableMethods; + + public static function getConfigurableMethods() { + return static::$__phpunit_configurableMethods; + } +} diff --git a/tests/_files/mock-object/ClassBUsingConfigurableMethods.php b/tests/_files/mock-object/ClassBUsingConfigurableMethods.php new file mode 100644 index 00000000000..a9a4b1ad6bc --- /dev/null +++ b/tests/_files/mock-object/ClassBUsingConfigurableMethods.php @@ -0,0 +1,22 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPUnit\Framework\MockObject; + +class ClassBUsingConfigurableMethods +{ + use ConfigurableMethods; + + public static function getConfigurableMethods() + { + return static::$__phpunit_configurableMethods; + } + +} diff --git a/tests/_files/mock-object/ClassWithoutParentButParentReturnType.php b/tests/_files/mock-object/ClassWithoutParentButParentReturnType.php new file mode 100644 index 00000000000..bc1b7426648 --- /dev/null +++ b/tests/_files/mock-object/ClassWithoutParentButParentReturnType.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace PHPUnit\Framework\MockObject; + +class ClassWithoutParentButParentReturnType { + + + public function foo(): parent + { + } + +} diff --git a/tests/_files/mock-object/ParentClass.php b/tests/_files/mock-object/ParentClass.php new file mode 100644 index 00000000000..62a4f9bd129 --- /dev/null +++ b/tests/_files/mock-object/ParentClass.php @@ -0,0 +1,17 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace PHPUnit\Framework\MockObject; + +class ParentClass +{ + public function foo(): void + { + } +} diff --git a/tests/_files/namespace/someNamespaceA/NamespacedClass.php b/tests/_files/namespace/someNamespaceA/NamespacedClass.php new file mode 100644 index 00000000000..889fdd7592f --- /dev/null +++ b/tests/_files/namespace/someNamespaceA/NamespacedClass.php @@ -0,0 +1,7 @@ +generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['speak']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -113,7 +116,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt b/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt index be9f2a4cf18..e7af58896be 100644 --- a/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt +++ b/tests/end-to-end/mock-objects/generator/3154_namespaced_constant_resolving.phpt @@ -35,13 +35,16 @@ $mock = $generator->generate( true ); -print $mock['code']; ---EXPECT-- +print $mock->getClassCode(); +--EXPECTF-- +declare(strict_types=1); + class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['a']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -64,7 +67,7 @@ class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Is\Namespaced\Issue3154', 'a', $__phpunit_arguments, 'string', $this, true + 'Is\Namespaced\Issue3154', 'a', $__phpunit_arguments, ': string', $this, true ) ); @@ -97,7 +100,7 @@ class Issue3154Mock extends Is\Namespaced\Issue3154 implements PHPUnit\Framework public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/3530.phpt b/tests/end-to-end/mock-objects/generator/3530.phpt index 588a654d7c3..c279aba77c0 100644 --- a/tests/end-to-end/mock-objects/generator/3530.phpt +++ b/tests/end-to-end/mock-objects/generator/3530.phpt @@ -14,6 +14,8 @@ print $generator->generateClassFromWsdl( 'Test' ); --EXPECTF-- +declare(strict_types=1); + class Test extends \SoapClient { public function __construct($wsdl, array $options) diff --git a/tests/end-to-end/mock-objects/generator/397.phpt b/tests/end-to-end/mock-objects/generator/397.phpt index 39dc64507de..badcda28f3f 100644 --- a/tests/end-to-end/mock-objects/generator/397.phpt +++ b/tests/end-to-end/mock-objects/generator/397.phpt @@ -21,13 +21,16 @@ $mock = $generator->generate( true ); -print $mock['code']; ---EXPECT-- +print $mock->getClassCode(); +--EXPECTF-- +declare(strict_types=1); + class MockC extends C implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['m']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -50,7 +53,7 @@ class MockC extends C implements PHPUnit\Framework\MockObject\MockObject $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'C', 'm', $__phpunit_arguments, 'C', $this, true + 'C', 'm', $__phpunit_arguments, ': C', $this, true ) ); @@ -83,7 +86,7 @@ class MockC extends C implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/abstract_class.phpt b/tests/end-to-end/mock-objects/generator/abstract_class.phpt index 727e4cb026e..083949d9a12 100644 --- a/tests/end-to-end/mock-objects/generator/abstract_class.phpt +++ b/tests/end-to-end/mock-objects/generator/abstract_class.phpt @@ -25,14 +25,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['one', 'two', 'three']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -132,7 +135,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class.phpt b/tests/end-to-end/mock-objects/generator/class.phpt index b013bbcb6fc..f290198331f 100644 --- a/tests/end-to-end/mock-objects/generator/class.phpt +++ b/tests/end-to-end/mock-objects/generator/class.phpt @@ -25,14 +25,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar', 'baz']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -110,7 +113,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_call_parent_clone.phpt b/tests/end-to-end/mock-objects/generator/class_call_parent_clone.phpt index 1dbd21eb36a..99f6a86d2d2 100644 --- a/tests/end-to-end/mock-objects/generator/class_call_parent_clone.phpt +++ b/tests/end-to-end/mock-objects/generator/class_call_parent_clone.phpt @@ -20,14 +20,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -62,7 +65,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/class_call_parent_constructor.phpt index 8f0d647e585..1b17186e0d1 100644 --- a/tests/end-to-end/mock-objects/generator/class_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/class_call_parent_constructor.phpt @@ -20,14 +20,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -61,7 +64,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_dont_call_parent_clone.phpt b/tests/end-to-end/mock-objects/generator/class_dont_call_parent_clone.phpt index 51e95b51324..8c543a604f3 100644 --- a/tests/end-to-end/mock-objects/generator/class_dont_call_parent_clone.phpt +++ b/tests/end-to-end/mock-objects/generator/class_dont_call_parent_clone.phpt @@ -20,14 +20,17 @@ $mock = $generator->generate( false ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -61,7 +64,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_dont_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/class_dont_call_parent_constructor.phpt index 8f0d647e585..1b17186e0d1 100644 --- a/tests/end-to-end/mock-objects/generator/class_dont_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/class_dont_call_parent_constructor.phpt @@ -20,14 +20,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -61,7 +64,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_implementing_interface_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/class_implementing_interface_call_parent_constructor.phpt index 8aae9076e9c..91ad5323f67 100644 --- a/tests/end-to-end/mock-objects/generator/class_implementing_interface_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/class_implementing_interface_call_parent_constructor.phpt @@ -25,14 +25,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -66,7 +69,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_implementing_interface_dont_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/class_implementing_interface_dont_call_parent_constructor.phpt index 8aae9076e9c..91ad5323f67 100644 --- a/tests/end-to-end/mock-objects/generator/class_implementing_interface_dont_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/class_implementing_interface_dont_call_parent_constructor.phpt @@ -25,14 +25,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -66,7 +69,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_nonexistent_method.phpt b/tests/end-to-end/mock-objects/generator/class_nonexistent_method.phpt index ae6ad6068c6..9a8a709d4e6 100644 --- a/tests/end-to-end/mock-objects/generator/class_nonexistent_method.phpt +++ b/tests/end-to-end/mock-objects/generator/class_nonexistent_method.phpt @@ -21,14 +21,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -84,7 +87,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_partial.phpt b/tests/end-to-end/mock-objects/generator/class_partial.phpt index 5b139da871f..b7279c554fb 100644 --- a/tests/end-to-end/mock-objects/generator/class_partial.phpt +++ b/tests/end-to-end/mock-objects/generator/class_partial.phpt @@ -25,14 +25,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -88,7 +91,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_with_deprecated_method.phpt b/tests/end-to-end/mock-objects/generator/class_with_deprecated_method.phpt index b0a5401fcea..982c98139c7 100644 --- a/tests/end-to-end/mock-objects/generator/class_with_deprecated_method.phpt +++ b/tests/end-to-end/mock-objects/generator/class_with_deprecated_method.phpt @@ -25,14 +25,17 @@ $mock = $generator->generate( TRUE ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends ClassWithDeprecatedMethod implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['deprecatedmethod']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -90,7 +93,7 @@ class MockFoo extends ClassWithDeprecatedMethod implements PHPUnit\Framework\Moc public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_with_final_method.phpt b/tests/end-to-end/mock-objects/generator/class_with_final_method.phpt index f382a37a188..76c5aff252d 100644 --- a/tests/end-to-end/mock-objects/generator/class_with_final_method.phpt +++ b/tests/end-to-end/mock-objects/generator/class_with_final_method.phpt @@ -21,14 +21,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends ClassWithFinalMethod implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -62,7 +65,7 @@ class MockFoo extends ClassWithFinalMethod implements PHPUnit\Framework\MockObje public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_with_method_named_method.phpt b/tests/end-to-end/mock-objects/generator/class_with_method_named_method.phpt index d06e709ff62..257f9df769c 100644 --- a/tests/end-to-end/mock-objects/generator/class_with_method_named_method.phpt +++ b/tests/end-to-end/mock-objects/generator/class_with_method_named_method.phpt @@ -21,14 +21,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['method']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -76,7 +79,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_with_method_with_nullable_typehinted_variadic_arguments.phpt b/tests/end-to-end/mock-objects/generator/class_with_method_with_nullable_typehinted_variadic_arguments.phpt index 44e0ecbb11a..38f116187fd 100644 --- a/tests/end-to-end/mock-objects/generator/class_with_method_with_nullable_typehinted_variadic_arguments.phpt +++ b/tests/end-to-end/mock-objects/generator/class_with_method_with_nullable_typehinted_variadic_arguments.phpt @@ -21,14 +21,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends ClassWithMethodWithNullableTypehintedVariadicArguments implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['methodwithnullabletypehintedvariadicarguments']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -84,7 +87,7 @@ class MockFoo extends ClassWithMethodWithNullableTypehintedVariadicArguments imp public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_with_method_with_typehinted_variadic_arguments.phpt b/tests/end-to-end/mock-objects/generator/class_with_method_with_typehinted_variadic_arguments.phpt index 246b9cbee6a..30badf4923f 100644 --- a/tests/end-to-end/mock-objects/generator/class_with_method_with_typehinted_variadic_arguments.phpt +++ b/tests/end-to-end/mock-objects/generator/class_with_method_with_typehinted_variadic_arguments.phpt @@ -21,14 +21,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends ClassWithMethodWithTypehintedVariadicArguments implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['methodwithtypehintedvariadicarguments']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -84,7 +87,7 @@ class MockFoo extends ClassWithMethodWithTypehintedVariadicArguments implements public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/class_with_method_with_variadic_arguments.phpt b/tests/end-to-end/mock-objects/generator/class_with_method_with_variadic_arguments.phpt index 282294ed1df..2137e8560cc 100644 --- a/tests/end-to-end/mock-objects/generator/class_with_method_with_variadic_arguments.phpt +++ b/tests/end-to-end/mock-objects/generator/class_with_method_with_variadic_arguments.phpt @@ -21,14 +21,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends ClassWithMethodWithVariadicArguments implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['methodwithvariadicarguments']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -84,7 +87,7 @@ class MockFoo extends ClassWithMethodWithVariadicArguments implements PHPUnit\Fr public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt b/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt index 004b17979c0..b4a995ac88b 100644 --- a/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt +++ b/tests/end-to-end/mock-objects/generator/constant_as_parameter_default_value.phpt @@ -21,14 +21,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -84,7 +87,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/interface.phpt b/tests/end-to-end/mock-objects/generator/interface.phpt index c7f0e682fe2..6f6aa79ba55 100644 --- a/tests/end-to-end/mock-objects/generator/interface.phpt +++ b/tests/end-to-end/mock-objects/generator/interface.phpt @@ -19,14 +19,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -82,7 +85,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/invocation_object_clone_object.phpt b/tests/end-to-end/mock-objects/generator/invocation_object_clone_object.phpt index 6eedbcade62..aae1d0c6fa8 100644 --- a/tests/end-to-end/mock-objects/generator/invocation_object_clone_object.phpt +++ b/tests/end-to-end/mock-objects/generator/invocation_object_clone_object.phpt @@ -26,14 +26,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar', 'baz']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -111,7 +114,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class.phpt index b8cf0f4f576..9ca854c0ffb 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class.phpt @@ -27,14 +27,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar', 'baz']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -112,7 +115,7 @@ class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_clone.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_clone.phpt index 21f886e3df5..38c87d8435e 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_clone.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_clone.phpt @@ -22,14 +22,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -64,7 +67,7 @@ class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_constructor.phpt index c725628a4ca..11269c65fbc 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_call_parent_constructor.phpt @@ -22,14 +22,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -63,7 +66,7 @@ class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_clone.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_clone.phpt index 1dc6d430bca..5d5ac232a77 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_clone.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_clone.phpt @@ -22,14 +22,17 @@ $mock = $generator->generate( false ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -63,7 +66,7 @@ class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_constructor.phpt index c725628a4ca..11269c65fbc 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_dont_call_parent_constructor.phpt @@ -22,14 +22,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -63,7 +66,7 @@ class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_call_parent_constructor.phpt index 6ddfe6ee38f..e78216d841a 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_call_parent_constructor.phpt @@ -27,14 +27,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -68,7 +71,7 @@ class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_dont_call_parent_constructor.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_dont_call_parent_constructor.phpt index 6ddfe6ee38f..e78216d841a 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_dont_call_parent_constructor.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_implementing_interface_dont_call_parent_constructor.phpt @@ -27,14 +27,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -68,7 +71,7 @@ class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_class_partial.phpt b/tests/end-to-end/mock-objects/generator/namespaced_class_partial.phpt index 6610782d2b3..0a468e1deed 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_class_partial.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_class_partial.phpt @@ -27,14 +27,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -90,7 +93,7 @@ class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/namespaced_interface.phpt b/tests/end-to-end/mock-objects/generator/namespaced_interface.phpt index 25f7c24dc0d..2a117896053 100644 --- a/tests/end-to-end/mock-objects/generator/namespaced_interface.phpt +++ b/tests/end-to-end/mock-objects/generator/namespaced_interface.phpt @@ -21,14 +21,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo implements PHPUnit\Framework\MockObject\MockObject, NS\Foo { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -84,7 +87,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, NS\Foo public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/nonexistent_class.phpt b/tests/end-to-end/mock-objects/generator/nonexistent_class.phpt index 90c5747ebf0..5b7d306bdbe 100644 --- a/tests/end-to-end/mock-objects/generator/nonexistent_class.phpt +++ b/tests/end-to-end/mock-objects/generator/nonexistent_class.phpt @@ -14,18 +14,21 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class NonExistentClass { } class MockFoo extends NonExistentClass implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -59,7 +62,7 @@ class MockFoo extends NonExistentClass implements PHPUnit\Framework\MockObject\M public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace.phpt b/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace.phpt index 8767b086f62..bdcda1b5c9d 100644 --- a/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace.phpt +++ b/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace.phpt @@ -14,9 +14,11 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + namespace NS { class Foo @@ -29,9 +31,10 @@ namespace { class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -65,7 +68,7 @@ class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace_starting_with_separator.phpt b/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace_starting_with_separator.phpt index 053a443f372..b1e900060d5 100644 --- a/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace_starting_with_separator.phpt +++ b/tests/end-to-end/mock-objects/generator/nonexistent_class_with_namespace_starting_with_separator.phpt @@ -14,9 +14,11 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + namespace NS { class Foo @@ -29,9 +31,10 @@ namespace { class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = []; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -65,7 +68,7 @@ class MockFoo extends NS\Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/nullable_types.phpt b/tests/end-to-end/mock-objects/generator/nullable_types.phpt index e056427c7fa..fab59814f32 100644 --- a/tests/end-to-end/mock-objects/generator/nullable_types.phpt +++ b/tests/end-to-end/mock-objects/generator/nullable_types.phpt @@ -21,14 +21,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -84,7 +87,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/proxy.phpt b/tests/end-to-end/mock-objects/generator/proxy.phpt index dba9e413693..fcd74553cb8 100644 --- a/tests/end-to-end/mock-objects/generator/proxy.phpt +++ b/tests/end-to-end/mock-objects/generator/proxy.phpt @@ -21,14 +21,17 @@ $mock = $generator->generate( 'Foo', [], 'ProxyFoo', true, true, true, true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar', 'baz']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -106,7 +109,7 @@ class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_closure.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_closure.phpt index e39913ceec8..667b581c37a 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_closure.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_closure.phpt @@ -19,14 +19,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -49,7 +52,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, 'Closure', $this, true + 'Foo', 'bar', $__phpunit_arguments, ': Closure', $this, true ) ); @@ -82,7 +85,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_final.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_final.phpt index 36fbcdc1cf9..98beefe062d 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_final.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_final.phpt @@ -26,14 +26,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -56,7 +59,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, 'FinalClass', $this, true + 'Foo', 'bar', $__phpunit_arguments, ': FinalClass', $this, true ) ); @@ -89,7 +92,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_generator.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_generator.phpt index c36f7cda802..2f4a6c55def 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_generator.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_generator.phpt @@ -19,14 +19,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -49,7 +52,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, 'Generator', $this, true + 'Foo', 'bar', $__phpunit_arguments, ': Generator', $this, true ) ); @@ -82,7 +85,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_nullable.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_nullable.phpt index f3afc25799f..beb408143ef 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_nullable.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_nullable.phpt @@ -19,14 +19,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -49,7 +52,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, '?string', $this, true + 'Foo', 'bar', $__phpunit_arguments, ': ?string', $this, true ) ); @@ -82,7 +85,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_object_method.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_object_method.phpt index 5bfe3e2b93a..fe002b51f5a 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_object_method.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_object_method.phpt @@ -22,14 +22,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -52,7 +55,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, 'Bar', $this, true + 'Foo', 'bar', $__phpunit_arguments, ': Bar', $this, true ) ); @@ -85,7 +88,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_parent.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_parent.phpt index d3d881e3647..c1c25ffcca4 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_parent.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_parent.phpt @@ -26,13 +26,16 @@ $mock = $generator->generate( true ); -print $mock['code']; ---EXPECT-- +print $mock->getClassCode(); +--EXPECTF-- +declare(strict_types=1); + class MockBar extends Bar implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['baz']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -55,7 +58,7 @@ class MockBar extends Bar implements PHPUnit\Framework\MockObject\MockObject $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Bar', 'baz', $__phpunit_arguments, 'Foo', $this, true + 'Bar', 'baz', $__phpunit_arguments, ': Foo', $this, true ) ); @@ -88,7 +91,7 @@ class MockBar extends Bar implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_self.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_self.phpt index 12c4742bfe4..f2a23837dab 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_self.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_self.phpt @@ -19,14 +19,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -49,7 +52,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, 'Foo', $this, true + 'Foo', 'bar', $__phpunit_arguments, ': Foo', $this, true ) ); @@ -82,7 +85,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_static_method.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_static_method.phpt index c8aa3d15743..50c194d0139 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_static_method.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_static_method.phpt @@ -22,14 +22,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -68,7 +71,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/return_type_declarations_void.phpt b/tests/end-to-end/mock-objects/generator/return_type_declarations_void.phpt index b452155544b..4f169d68c62 100644 --- a/tests/end-to-end/mock-objects/generator/return_type_declarations_void.phpt +++ b/tests/end-to-end/mock-objects/generator/return_type_declarations_void.phpt @@ -19,14 +19,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -49,7 +52,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, 'void', $this, true + 'Foo', 'bar', $__phpunit_arguments, ': void', $this, true ) ); } @@ -80,7 +83,7 @@ class MockFoo implements PHPUnit\Framework\MockObject\MockObject, Foo public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/scalar_type_declarations.phpt b/tests/end-to-end/mock-objects/generator/scalar_type_declarations.phpt index 6ab06c0f668..a7b8855203b 100644 --- a/tests/end-to-end/mock-objects/generator/scalar_type_declarations.phpt +++ b/tests/end-to-end/mock-objects/generator/scalar_type_declarations.phpt @@ -21,14 +21,17 @@ $mock = $generator->generate( true ); -print $mock['code']; +print $mock->getClassCode(); ?> ---EXPECT-- +--EXPECTF-- +declare(strict_types=1); + class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject { + use \PHPUnit\Framework\MockObject\ConfigurableMethods; + private $__phpunit_invocationMocker; private $__phpunit_originalObject; - private $__phpunit_configurable = ['bar']; private $__phpunit_returnValueGeneration = true; public function __clone() @@ -84,7 +87,7 @@ class MockFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject public function __phpunit_getInvocationMocker(): \PHPUnit\Framework\MockObject\InvocationMocker { if ($this->__phpunit_invocationMocker === null) { - $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker($this->__phpunit_configurable, $this->__phpunit_returnValueGeneration); + $this->__phpunit_invocationMocker = new \PHPUnit\Framework\MockObject\InvocationMocker(static::$__phpunit_configurableMethods, $this->__phpunit_returnValueGeneration); } return $this->__phpunit_invocationMocker; diff --git a/tests/end-to-end/mock-objects/generator/wsdl_class.phpt b/tests/end-to-end/mock-objects/generator/wsdl_class.phpt index c3166a84c07..566a1976500 100644 --- a/tests/end-to-end/mock-objects/generator/wsdl_class.phpt +++ b/tests/end-to-end/mock-objects/generator/wsdl_class.phpt @@ -16,6 +16,8 @@ print $generator->generateClassFromWsdl( ); ?> --EXPECTF-- +declare(strict_types=1); + class GoogleSearch extends \SoapClient { public function __construct($wsdl, array $options) diff --git a/tests/end-to-end/mock-objects/generator/wsdl_class_namespace.phpt b/tests/end-to-end/mock-objects/generator/wsdl_class_namespace.phpt index 919cd5df7a1..89a2cf383e8 100644 --- a/tests/end-to-end/mock-objects/generator/wsdl_class_namespace.phpt +++ b/tests/end-to-end/mock-objects/generator/wsdl_class_namespace.phpt @@ -15,6 +15,8 @@ print $generator->generateClassFromWsdl( ); ?> --EXPECTF-- +declare(strict_types=1); + namespace My\Space; class GoogleSearch extends \SoapClient diff --git a/tests/end-to-end/mock-objects/generator/wsdl_class_partial.phpt b/tests/end-to-end/mock-objects/generator/wsdl_class_partial.phpt index 335296f8a58..59b31be9c2d 100644 --- a/tests/end-to-end/mock-objects/generator/wsdl_class_partial.phpt +++ b/tests/end-to-end/mock-objects/generator/wsdl_class_partial.phpt @@ -17,6 +17,8 @@ print $generator->generateClassFromWsdl( ); ?> --EXPECTF-- +declare(strict_types=1); + class GoogleSearch extends \SoapClient { public function __construct($wsdl, array $options) diff --git a/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt b/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt index 142d6335cdb..f6e71c19675 100644 --- a/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt +++ b/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt @@ -20,7 +20,7 @@ $code = $mockMethod->generateCode(); print $code; ?> ---EXPECT-- +--EXPECTF-- public function bar(): void { @@ -37,7 +37,7 @@ print $code; $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, 'void', $this, false, true + 'Foo', 'bar', $__phpunit_arguments, ': void', $this, false, true ) ); diff --git a/tests/end-to-end/mock-objects/mock-method/return_by_reference_with_return_type.phpt b/tests/end-to-end/mock-objects/mock-method/return_by_reference_with_return_type.phpt index 327b0b12253..cb027a170d6 100644 --- a/tests/end-to-end/mock-objects/mock-method/return_by_reference_with_return_type.phpt +++ b/tests/end-to-end/mock-objects/mock-method/return_by_reference_with_return_type.phpt @@ -20,7 +20,7 @@ $code = $mockMethod->generateCode(); print $code; ?> ---EXPECT-- +--EXPECTF-- public function &bar(): string { @@ -37,7 +37,7 @@ public function &bar(): string $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, 'string', $this, false + 'Foo', 'bar', $__phpunit_arguments, ': string', $this, false ) ); diff --git a/tests/end-to-end/mock-objects/mock-method/return_type.phpt b/tests/end-to-end/mock-objects/mock-method/return_type.phpt index 63e4b730cb7..b9547a0c916 100644 --- a/tests/end-to-end/mock-objects/mock-method/return_type.phpt +++ b/tests/end-to-end/mock-objects/mock-method/return_type.phpt @@ -20,7 +20,7 @@ $code = $mockMethod->generateCode(); print $code; ?> ---EXPECT-- +--EXPECTF-- public function bar(): string { @@ -37,7 +37,7 @@ public function bar(): string $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, 'string', $this, false + 'Foo', 'bar', $__phpunit_arguments, ': string', $this, false ) ); diff --git a/tests/end-to-end/mock-objects/mock-method/return_type_parent.phpt b/tests/end-to-end/mock-objects/mock-method/return_type_parent.phpt index e6ab4920a90..3cc7b5b0282 100644 --- a/tests/end-to-end/mock-objects/mock-method/return_type_parent.phpt +++ b/tests/end-to-end/mock-objects/mock-method/return_type_parent.phpt @@ -24,7 +24,7 @@ $code = $mockMethod->generateCode(); print $code; ?> ---EXPECT-- +--EXPECTF-- public function bar(): Baz { @@ -41,7 +41,7 @@ public function bar(): Baz $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, 'Baz', $this, false + 'Foo', 'bar', $__phpunit_arguments, ': Baz', $this, false ) ); diff --git a/tests/end-to-end/mock-objects/mock-method/return_type_self.phpt b/tests/end-to-end/mock-objects/mock-method/return_type_self.phpt index 4cf21b85d06..e3d5ee6733c 100644 --- a/tests/end-to-end/mock-objects/mock-method/return_type_self.phpt +++ b/tests/end-to-end/mock-objects/mock-method/return_type_self.phpt @@ -20,7 +20,7 @@ $code = $mockMethod->generateCode(); print $code; ?> ---EXPECT-- +--EXPECTF-- public function bar(): Foo { @@ -37,7 +37,7 @@ public function bar(): Foo $__phpunit_result = $this->__phpunit_getInvocationMocker()->invoke( new \PHPUnit\Framework\MockObject\Invocation( - 'Foo', 'bar', $__phpunit_arguments, 'Foo', $this, false + 'Foo', 'bar', $__phpunit_arguments, ': Foo', $this, false ) ); diff --git a/tests/end-to-end/regression/GitHub/2366/Issue2366Test.php b/tests/end-to-end/regression/GitHub/2366/Issue2366Test.php index 057df1bfbe9..303053c3fd2 100644 --- a/tests/end-to-end/regression/GitHub/2366/Issue2366Test.php +++ b/tests/end-to-end/regression/GitHub/2366/Issue2366Test.php @@ -24,14 +24,14 @@ class Issue2366Test extends TestCase */ public function testOne($o): void { - $this->assertEquals(1, $o->foo()); + $this->assertEquals(true, $o->foo()); } public function provider() { $o = $this->createMock(Issue2366::class); - $o->method('foo')->willReturn(1); + $o->method('foo')->willReturn(true); return [ [$o], diff --git a/tests/unit/Framework/MockObject/Builder/InvocationMockerTest.php b/tests/unit/Framework/MockObject/Builder/InvocationMockerTest.php index 36a3b63512e..9c2d4dc57f5 100644 --- a/tests/unit/Framework/MockObject/Builder/InvocationMockerTest.php +++ b/tests/unit/Framework/MockObject/Builder/InvocationMockerTest.php @@ -1,4 +1,5 @@ getMockBuilder(stdClass::class) - ->setMethods(['foo']) - ->getMock(); + ->setMethods(['foo']) + ->getMock(); $mock->expects($this->any()) - ->method('foo') - ->willReturn(1); + ->method('foo') + ->willReturn(1); $this->assertEquals(1, $mock->foo()); } @@ -32,12 +34,12 @@ public function testWillReturnWithOneValue(): void public function testWillReturnWithMultipleValues(): void { $mock = $this->getMockBuilder(stdClass::class) - ->setMethods(['foo']) - ->getMock(); + ->setMethods(['foo']) + ->getMock(); $mock->expects($this->any()) - ->method('foo') - ->willReturn(1, 2, 3); + ->method('foo') + ->willReturn(1, 2, 3); $this->assertEquals(1, $mock->foo()); $this->assertEquals(2, $mock->foo()); @@ -47,12 +49,12 @@ public function testWillReturnWithMultipleValues(): void public function testWillReturnOnConsecutiveCalls(): void { $mock = $this->getMockBuilder(stdClass::class) - ->setMethods(['foo']) - ->getMock(); + ->setMethods(['foo']) + ->getMock(); $mock->expects($this->any()) - ->method('foo') - ->willReturnOnConsecutiveCalls(1, 2, 3); + ->method('foo') + ->willReturnOnConsecutiveCalls(1, 2, 3); $this->assertEquals(1, $mock->foo()); $this->assertEquals(2, $mock->foo()); @@ -62,12 +64,12 @@ public function testWillReturnOnConsecutiveCalls(): void public function testWillReturnByReference(): void { $mock = $this->getMockBuilder(stdClass::class) - ->setMethods(['foo']) - ->getMock(); + ->setMethods(['foo']) + ->getMock(); $mock->expects($this->any()) - ->method('foo') - ->willReturnReference($value); + ->method('foo') + ->willReturnReference($value); $this->assertNull($mock->foo()); $value = 'foo'; @@ -80,13 +82,49 @@ public function testWillFailWhenTryingToPerformExpectationUnconfigurableMethod() { /** @var MatcherCollection|\PHPUnit\Framework\MockObject\MockObject $matcherCollection */ $matcherCollection = $this->createMock(MatcherCollection::class); - $invocationMocker = new \PHPUnit\Framework\MockObject\Builder\InvocationMocker( + $invocationMocker = new \PHPUnit\Framework\MockObject\Builder\InvocationMocker( $matcherCollection, - $this->any(), - [] + $this->any() ); $this->expectException(RuntimeException::class); $invocationMocker->method('someMethod'); } + + public function testWillReturnFailsWhenTryingToReturnSingleIncompatibleValue(): void + { + $mock = $this->getMockBuilder(ClassWithAllPossibleReturnTypes::class) + ->getMock(); + + $invocationMocker = $mock->method('methodWithBoolReturnTypeDeclaration'); + + $this->expectException(IncompatibleReturnValueException::class); + $this->expectExceptionMessage('Method methodWithBoolReturnTypeDeclaration may not return value of type integer'); + $invocationMocker->willReturn(1); + } + + public function testWillReturnFailsWhenTryingToReturnIncompatibleValueByConstraint(): void + { + $mock = $this->getMockBuilder(ClassWithAllPossibleReturnTypes::class) + ->getMock(); + + $invocationMocker = $mock->method(new \PHPUnit\Framework\Constraint\IsEqual('methodWithBoolReturnTypeDeclaration')); + + $this->expectException(IncompatibleReturnValueException::class); + $this->expectExceptionMessage('Method methodWithBoolReturnTypeDeclaration may not return value of type integer'); + $invocationMocker->willReturn(1); + } + + public function testWillReturnFailsWhenTryingToReturnAtLeastOneIncompatibleValue(): void + { + $mock = $this->getMockBuilder(ClassWithAllPossibleReturnTypes::class) + ->getMock(); + + $invocationMocker = $mock->method('methodWithBoolReturnTypeDeclaration'); + + $this->expectException(IncompatibleReturnValueException::class); + $this->expectExceptionMessage('Method methodWithBoolReturnTypeDeclaration may not return value of type integer'); + $invocationMocker->willReturn(true, 1); + } + } diff --git a/tests/unit/Framework/MockObject/ConfigurableMethodTest.php b/tests/unit/Framework/MockObject/ConfigurableMethodTest.php new file mode 100644 index 00000000000..dcfc4e63fb0 --- /dev/null +++ b/tests/unit/Framework/MockObject/ConfigurableMethodTest.php @@ -0,0 +1,28 @@ +createMock(Type::class); + $assignableType->method('isAssignable') + ->willReturn(true); + $configurable = new ConfigurableMethod('foo', $assignableType); + $this->assertTrue($configurable->mayReturn('everything-is-valid')); + } + + public function testMethodMayNotReturnUnassignableValue() + { + $unassignableType = $this->createMock(Type::class); + $unassignableType->method('isAssignable') + ->willReturn(false); + $configurable = new ConfigurableMethod('foo', $unassignableType); + $this->assertFalse($configurable->mayReturn('everything-is-invalid')); + } + +} diff --git a/tests/unit/Framework/MockObject/ConfigurableMethodsTest.php b/tests/unit/Framework/MockObject/ConfigurableMethodsTest.php new file mode 100644 index 00000000000..efe82196a0e --- /dev/null +++ b/tests/unit/Framework/MockObject/ConfigurableMethodsTest.php @@ -0,0 +1,20 @@ +assertSame($configurableMethodsA, ClassAUsingConfigurableMethods::getConfigurableMethods()); + $this->assertSame($configurableMethodsB, ClassBUsingConfigurableMethods::getConfigurableMethods()); + } + +} diff --git a/tests/unit/Framework/MockObject/MockMethodTest.php b/tests/unit/Framework/MockObject/MockMethodTest.php index 51ee79c2d19..73661a786bf 100644 --- a/tests/unit/Framework/MockObject/MockMethodTest.php +++ b/tests/unit/Framework/MockObject/MockMethodTest.php @@ -25,7 +25,7 @@ public function testGetNameReturnsMethodName(): void '', '', '', - '', + new UnknownType(), '', false, false, @@ -37,21 +37,9 @@ public function testGetNameReturnsMethodName(): void public function testFailWhenReturnTypeIsParentButThereIsNoParentClass(): void { - $method = new MockMethod( - \stdClass::class, - 'methodName', - false, - '', - '', - '', - 'parent', - '', - false, - false, - null, - false - ); + $class = new \ReflectionClass(ClassWithoutParentButParentReturnType::class); + $this->expectException(\RuntimeException::class); - $method->generateCode(); + MockMethod::fromReflection($class->getMethod('foo'), false, false); } } diff --git a/tests/unit/Framework/MockObject/ObjectTypeTest.php b/tests/unit/Framework/MockObject/ObjectTypeTest.php new file mode 100644 index 00000000000..01e960f8bf7 --- /dev/null +++ b/tests/unit/Framework/MockObject/ObjectTypeTest.php @@ -0,0 +1,84 @@ +childClass = new ObjectType( + TypeName::fromQualifiedName(ChildClass::class), + false + ); + $this->parentClass = new ObjectType( + TypeName::fromQualifiedName(ParentClass::class), + false + ); + } + + public function testParentIsNotAssignableToChild(): void + { + $this->assertFalse($this->childClass->isAssignable($this->parentClass)); + } + + public function testChildIsAssignableToParent(): void + { + $this->assertTrue($this->parentClass->isAssignable($this->childClass)); + } + + public function testClassIsAssignableToSelf(): void + { + $this->assertTrue($this->parentClass->isAssignable($this->parentClass)); + } + + public function testSimpleTypeIsNotAssignableToClass(): void + { + $this->assertFalse($this->parentClass->isAssignable(new SimpleType('int', false))); + } + + public function testClassFromOneNamespaceIsNotAssignableToClassInOtherNamespace() + { + $classFromNamespaceA = new ObjectType( + TypeName::fromQualifiedName(\someNamespaceA\NamespacedClass::class), + false + ); + $classFromNamespaceB = new ObjectType( + TypeName::fromQualifiedName(\someNamespaceB\NamespacedClass::class), + false + ); + $this->assertFalse($classFromNamespaceA->isAssignable($classFromNamespaceB)); + } + + public function testNullIsAssignableToNullableType() + { + $someClass = new ObjectType( + TypeName::fromQualifiedName(ParentClass::class), + true + ); + $this->assertTrue($someClass->isAssignable(Type::fromValue(null, true))); + } + + public function testNullIsNotAssignableToNotNullableType() + { + $someClass = new ObjectType( + TypeName::fromQualifiedName(ParentClass::class), + false + ); + $this->assertFalse($someClass->isAssignable(Type::fromValue(null, true))); + } + + +} diff --git a/tests/unit/Framework/MockObject/TypeNameTest.php b/tests/unit/Framework/MockObject/TypeNameTest.php new file mode 100644 index 00000000000..d9df038f0de --- /dev/null +++ b/tests/unit/Framework/MockObject/TypeNameTest.php @@ -0,0 +1,56 @@ + + * + * 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; + +class TypeNameTest extends TestCase +{ + public function testFromReflection(): void + { + $class = new \ReflectionClass(TypeName::class); + $typeName = TypeName::fromReflection($class); + + $this->assertTrue($typeName->isNamespaced()); + $this->assertEquals('PHPUnit\\Framework\\MockObject', $typeName->getNamespaceName()); + $this->assertEquals(TypeName::class, $typeName->getQualifiedName()); + $this->assertEquals('TypeName', $typeName->getSimpleName()); + } + + public function testFromQualifiedName(): void + { + $typeName = TypeName::fromQualifiedName('PHPUnit\\Framework\\MockObject\\TypeName'); + + $this->assertTrue($typeName->isNamespaced()); + $this->assertEquals('PHPUnit\\Framework\\MockObject', $typeName->getNamespaceName()); + $this->assertEquals('PHPUnit\\Framework\\MockObject\\TypeName', $typeName->getQualifiedName()); + $this->assertEquals('TypeName', $typeName->getSimpleName()); + } + + public function testFromQualifiedNameWithLeadingSeparator(): void + { + $typeName = TypeName::fromQualifiedName('\\Foo\\Bar'); + + $this->assertTrue($typeName->isNamespaced()); + $this->assertEquals('Foo', $typeName->getNamespaceName()); + $this->assertEquals('Foo\\Bar', $typeName->getQualifiedName()); + $this->assertEquals('Bar', $typeName->getSimpleName()); + } + + public function testFromQualifiedNameWithoutNamespace(): void + { + $typeName = TypeName::fromQualifiedName('Bar'); + + $this->assertFalse($typeName->isNamespaced()); + $this->assertNull($typeName->getNamespaceName()); + $this->assertEquals('Bar', $typeName->getQualifiedName()); + $this->assertEquals('Bar', $typeName->getSimpleName()); + } +}