diff --git a/library/Mockery/Generator/DefinedTargetClass.php b/library/Mockery/Generator/DefinedTargetClass.php index 0539b3564..f2a3f3271 100644 --- a/library/Mockery/Generator/DefinedTargetClass.php +++ b/library/Mockery/Generator/DefinedTargetClass.php @@ -33,8 +33,8 @@ class DefinedTargetClass implements TargetClassInterface private $rfc; /** - * @param ReflectionClass $rfc - * @param class-string|null $alias + * @param ReflectionClass $rfc + * @param class-string|null $alias */ public function __construct(ReflectionClass $rfc, $alias = null) { @@ -51,7 +51,7 @@ public function __toString() } /** - * @param class-string $name + * @param class-string $name * @param class-string|null $alias * @return self */ diff --git a/library/Mockery/Generator/MockConfiguration.php b/library/Mockery/Generator/MockConfiguration.php index 6cf6a489f..1849c3e2f 100644 --- a/library/Mockery/Generator/MockConfiguration.php +++ b/library/Mockery/Generator/MockConfiguration.php @@ -11,7 +11,7 @@ namespace Mockery\Generator; use Mockery\Exception; -use ReflectionMethod; +use Serializable; use function array_filter; use function array_keys; use function array_map; @@ -33,8 +33,6 @@ use function strpos; use function strtolower; use function trait_exists; -use Serializable; -use Mockery\Generator\TargetClassInterface; /** * This class describes the configuration of mocks and hides away some of the @@ -47,7 +45,7 @@ class MockConfiguration * * @var list */ - protected $allMethods; + protected $allMethods = []; /** * Methods that should specifically not be mocked @@ -81,6 +79,8 @@ class MockConfiguration /** * Param overrides + * + * @var array */ protected $parameterOverrides = []; @@ -134,14 +134,14 @@ class MockConfiguration protected $whiteListedMethods = []; /** - * @param array $targets - * @param array $blackListedMethods - * @param array $whiteListedMethods - * @param string|null $name - * @param bool $instanceMock - * @param array $parameterOverrides - * @param bool $mockOriginalDestructor - * @param array|scalar> $constantsMap + * @param array $targets + * @param array $blackListedMethods + * @param array $whiteListedMethods + * @param string|null $name + * @param bool $instanceMock + * @param array $parameterOverrides + * @param bool $mockOriginalDestructor + * @param array|scalar> $constantsMap */ public function __construct( array $targets = [], @@ -172,9 +172,6 @@ public function generateName() { $nameBuilder = new MockNameBuilder(); - /** - * @var object|null $targetObject - */ $targetObject = $this->getTargetObject(); if ($targetObject !== null) { $className = get_class($targetObject); @@ -309,7 +306,9 @@ public function getName() return $this->name; } - /** @return string */ + /** + * @return string + */ public function getNamespaceName() { $parts = explode('\\', $this->getName()); diff --git a/library/Mockery/Generator/Parameter.php b/library/Mockery/Generator/Parameter.php index bbc77c93f..442a713c2 100644 --- a/library/Mockery/Generator/Parameter.php +++ b/library/Mockery/Generator/Parameter.php @@ -15,7 +15,6 @@ use ReflectionParameter; use function class_exists; - /** * @mixin ReflectionParameter */ diff --git a/library/Mockery/Generator/StringManipulation/Pass/InterfacePass.php b/library/Mockery/Generator/StringManipulation/Pass/InterfacePass.php index a038753e3..4eabcb08b 100644 --- a/library/Mockery/Generator/StringManipulation/Pass/InterfacePass.php +++ b/library/Mockery/Generator/StringManipulation/Pass/InterfacePass.php @@ -32,7 +32,7 @@ public function apply($code, MockConfiguration $config) } } - $interfaces = array_reduce((array) $config->getTargetInterfaces(), static function ($code, $i) { + $interfaces = array_reduce($config->getTargetInterfaces(), static function ($code, $i) { return $code . ', \\' . ltrim($i->getName(), '\\'); }, ''); diff --git a/library/Mockery/Generator/StringManipulationGenerator.php b/library/Mockery/Generator/StringManipulationGenerator.php index cb562e943..5cb142172 100644 --- a/library/Mockery/Generator/StringManipulationGenerator.php +++ b/library/Mockery/Generator/StringManipulationGenerator.php @@ -30,14 +30,14 @@ class StringManipulationGenerator implements Generator { /** - * @var string + * @var list */ - private $code; + protected $passes = []; /** - * @var list + * @var string */ - protected $passes = []; + private $code; /** * @param list $passes @@ -50,7 +50,7 @@ public function __construct(array $passes) } /** - * @param Pass $pass + * @param Pass $pass * @return void */ public function addPass(Pass $pass) diff --git a/library/Mockery/Generator/TargetClassInterface.php b/library/Mockery/Generator/TargetClassInterface.php index 842cb9c82..730ae1b5f 100644 --- a/library/Mockery/Generator/TargetClassInterface.php +++ b/library/Mockery/Generator/TargetClassInterface.php @@ -10,10 +10,6 @@ namespace Mockery\Generator; -use ReflectionMethod; -use Mockery\Generator\TargetClassInterface; -use Mockery\Generator\Method; - interface TargetClassInterface { /** diff --git a/library/Mockery/Generator/UndefinedTargetClass.php b/library/Mockery/Generator/UndefinedTargetClass.php index fb378b954..ea7220255 100644 --- a/library/Mockery/Generator/UndefinedTargetClass.php +++ b/library/Mockery/Generator/UndefinedTargetClass.php @@ -10,12 +10,10 @@ namespace Mockery\Generator; -use ReflectionMethod; use function array_pop; use function explode; use function implode; use function ltrim; -use Mockery\Generator\TargetClassInterface; class UndefinedTargetClass implements TargetClassInterface { diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 25ec02b92..4dddc06f0 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -112,7 +112,11 @@ $args $args + $name + + $name + null @@ -347,28 +351,34 @@ $constructorArgs + $interfaces $mock + $type + + $match === false array_keys($arg) !== range(0, count($arg) - 1) - $keys + $arg $mocks[$index] + + $arg + - _mocks]]> - _mocks[$reference] ?? null]]> rememberMock($mock)]]> - |int,LegacyMockInterface&MockInterface&TMock>]]> - + + _mocks[$reference] ?? null]]> + $config @@ -386,11 +396,13 @@ $className $className - $config $def $name $name + + $keys + $arg[self::BLOCKS] @@ -400,7 +412,6 @@ $blocks $className - $config $def $exception $exceptions[] @@ -419,9 +430,6 @@ mockery_init new $internalMockName() once - setActualOrder - setExpectedOrder - setMethodName shouldReceive shouldReceive @@ -435,6 +443,9 @@ $exceptions ]]> + + + $arg $arg @@ -445,6 +456,9 @@ $parts[1] + + mockery_thrownExceptions + instanceMock mockery_allocateOrder @@ -455,6 +469,10 @@ int + + _mocks]]> + _mocks]]> + is_object($arg) @@ -463,37 +481,6 @@ $constructorArgs !== null - - mockery_thrownExceptions - - - - - bool - - - throw $exception; - - - setActualCount - setExpectedCount - setExpectedCountComparative - setMethodName - - - - - bool - - - throw $exception; - - - setActualCount - setExpectedCount - setExpectedCountComparative - setMethodName - @@ -511,29 +498,13 @@ - - bool - - - throw $exception; - - - setActualCount - setExpectedCount - setExpectedCountComparative - setMethodName - _expectation->getExceptionMessage()]]> - - $dismissed - dismiss - dismissed BadMethodCallException @@ -545,117 +516,30 @@ - - $comp - $count - $count - $name - - - $actual - $expected - $expectedComparative - $method - $mockObject - - - getActualCount - getExpectedCount - getExpectedCountComparative - getMethodName - getMock - getMockName - setActualCount - setExpectedCount - setExpectedCountComparative - setMethodName - setMock - - - mockery_getName - - - $comp - getActualCount getExpectedCount getExpectedCountComparative getMethodName getMockName - setActualCount - setExpectedCount - setExpectedCountComparative - setMethodName - - $count - $count - $name - - - $actual - $expected - $method - $mockObject - - - getActualOrder - getExpectedOrder - getMethodName - getMock - getMockName - setActualOrder - setExpectedOrder - setMethodName - setMock - - - mockery_getName - getActualOrder getExpectedOrder getMethodName getMockName - setActualOrder - setExpectedOrder - setMethodName - - $count - $name - - - $actual - $method - $mockObject - - - getActualArguments - getMethodName - getMock - getMockName - setActualArguments - setMethodName - setMock - - - mockery_getName - getActualArguments getMethodName getMockName - setActualArguments - setMethodName @@ -849,8 +733,6 @@ throw $exception; - setActualArguments - setMethodName verifyCall @@ -900,85 +782,42 @@ - - $cache - - - generate - - - cache[$hash]]]> - - - cache[$hash]]]> - - - $definition - + + string + + + cache]]> + + + cache[$hash] = $this->generator->generate($config)]]> + - - $name - - - $interface - $method - - - $alias - $alias - - - $name - $rfc - + + getName(); + }, + $this->rfc->getAttributes() + ) + ) + )]]> + - $interface - $method rfc->getAttributes()]]> - rfc->getInterfaces()]]> - rfc->getMethods()]]> - - $child - $child - $parent - - - getName - getNamespaceName - getShortName - implementsInterface - inNamespace - isAbstract - isFinal - - - getAttributes - getInterfaces - getMethods - getNamespaceName - getParentClass - getShortName - implementsInterface - inNamespace - isAbstract - isFinal - isInternal - isInternal - getName()]]> - - name]]> - rfc->getNamespaceName()]]> - rfc->getShortName()]]> - rfc->implementsInterface($interface)]]> - rfc->inNamespace()]]> - rfc->isAbstract()]]> - rfc->isFinal()]]> - + + $interface + + + ]]> + @@ -986,70 +825,52 @@ - - $args - $method - + + __call + - - $method - $method - $method - - - $className - $instanceMock - $interfaces - $mockOriginalDestructor - $name - $object + $target - $targetClassName - $targetTraitName - + $target + $targetInterface + $targetTrait + $targets + targetClassName]]> + + + + + + $targets + + + targetTraits]]> + targetTraits)]]> + + + allMethods = $methods]]> + targetInterfaces]]> + targetInterfaces = array_unique($this->targetInterfaces)]]> + targetTraits]]> + targetTraits]]> + isAbstract()) { + return true; + } + + return in_array(strtolower($method->getName()), $whitelist, true); + })]]> + - $allMethods $blackListedMethods $constantsMap - $instanceMock - $mockOriginalDestructor - $name - $parameterOverrides - $targetClass - $targetClassName - $targetInterfaceNames - $targetInterfaces - $targetObject - $targetTraitNames - $targetTraits - $whiteListedMethods addTarget addTargetInterfaceName addTargetTraitName addTargets - generateName - getAllMethods - getBlackListedMethods - getConstantsMap - getMethodsToMock - getName - getNamespaceName - getParameterOverrides - getShortName - getTargetClass - getTargetClassName - getTargetInterfaces - getTargetObject - getTargetTraits - getWhiteListedMethods - isInstanceMock - isMockOriginalDestructor - rename - requiresCallStaticTypeHintRemoval - requiresCallTypeHintRemoval setTargetClassName setTargetObject @@ -1064,419 +885,167 @@ $alias - getMethods()]]> - $className - getName()]]> - getName()]]> - $methods - $methods - $methods - $methods - $target - $target - $target - $targetInterface - $targetInterface - $targetTrait + $alias blackListedMethods]]> constantsMap]]> - getBlackListedMethods()]]> - getBlackListedMethods()]]> - getName()]]> - getName()]]> - getTargetObject()]]> - getWhiteListedMethods()]]> - getWhiteListedMethods()]]> - parameterOverrides]]> - targetClassName]]> - targetClassName]]> - targetInterfaceNames]]> - targetInterfaces]]> - targetTraitNames]]> - targetTraits]]> - whiteListedMethods]]> - - $interface - $interface - $interface - $interface - - - $methods[$key] - $params[1] - $params[1] - $target[0] - getBlackListedMethods()]]> - getWhiteListedMethods()]]> - - - $classes[] - targetInterfaceNames[]]]> - targetInterfaces[]]]> - targetInterfaces[]]]> - targetInterfaces[]]]> - targetInterfaces[]]]> - targetInterfaces[]]]> - targetTraitNames[]]]> - targetTraits[]]]> - - - $methods[$key] - $alias - $class - $className - $classes - $classes[] - $interface - $key - $method - $method - $method - $method - $methods - $methods[] - $names[] - $params - $params - $targetInterface - $targetTrait - $targets[] - $targets[] - $trait + + >]]> + ]]> + addPart build - getMethods - getMethods - getName - getName - getName - getName - getName - getName - getName - getName - getName - getParameters - getParameters - hasInternalAncestor - implementsInterface - isAbstract - isAbstract - isArray - isArray - isFinal - - $target - + + blackListedMethods]]> + constantsMap]]> + + + ]]> + ]]> + ]]> + ]]> + + + getName()]]> + getName()]]> + + + getMethods + + + $params[1] + getParameterOverrides + + $methods + - $blackListedMethod - $instanceMock - $mockDestructor - $name - $target - $targets $whiteListedMethod - - $blackListedMethods - $constantsMap - $instanceMock - $mockOriginalDestructor - $name - $parameterOverrides - $php7SemiReservedKeywords - $targets - $whiteListedMethods - - addBlackListedMethod - addBlackListedMethods - addTarget - addTargets - addWhiteListedMethod - addWhiteListedMethods - getMockConfiguration - setBlackListedMethods - setConstantsMap setInstanceMock setMockOriginalDestructor setName - setParameterOverrides - setWhiteListedMethods - - blackListedMethods]]> - blackListedMethods]]> + constantsMap]]> parameterOverrides]]> - php7SemiReservedKeywords]]> targets]]> whiteListedMethods]]> - - - blackListedMethods[]]]> - targets[]]]> - whiteListedMethods[]]]> - + $method - $method - $target addWhiteListedMethods setBlackListedMethods setWhiteListedMethods + + $name + + + blackListedMethods, $this->php7SemiReservedKeywords)]]> + + + (bool) $instanceMock + (bool) $mockDestructor + - - $code - - - $code - $config - - - getClassName - getCode - getConfig - - - - - - getName - + + string + + + config->getName()]]> + getConfig - - $parts - - - $part - - - $mockCounter - $parts - addPart - build - - $part - - - parts[]]]> - - - $part - static::$mockCounter - - - static::$mockCounter - + + false + class_exists($typeHint) ? DefinedTargetClass::factory($typeHint, false) : null null|ReflectionClass - - $method - $typeHint + __call getClass getTypeHintAsString - isArray - - - $method - - - static function ($method) { - - - $code - - - apply - - - $code - getMethodsToMock()]]> - - - getName - - - - - $code - - - apply - - - $code - $code - - - - - $code - - - apply - - - $code - - - $class - - - getAttributes - - - - - $code - - - apply - - - $code - $namespace - - - $className - $namespace - - - $className - - $className - - $code - - - apply - - - $code - getName()]]> - - - $target - - - getName - isFinal - - - $code - - - apply - - - $cm - $code - $code - $constant - $name - - - $cm[$name] - - - $cm[$name] - - $cm - $constant - $name $value - - substr_replace($code, $constantsCode, $offset) - + + $cm[$name] + + + $name + $class $code - $code appendToClass - apply $class $class + + string + $code + + appendToClass($code, static::INSTANCE_MOCK_CODE)]]> + $lastBrace - - apply - $name - - $code - - - apply - - $code - getName()]]> getName()]]> - - $i - getName - getName $code @@ -1504,15 +1073,9 @@ renderTypeHint - getTargetClass()]]> - $interface $method - getName()]]> - getName()]]> - getName()]]> - $interface $method $name @@ -1523,14 +1086,6 @@ $matches[0] - - getName - getName - getName - getName - getName - isStatic - @@ -1543,14 +1098,12 @@ $class $code - $code $config $config $method appendToClass - apply renderMethodBody renderParams renderReturnType @@ -1560,13 +1113,9 @@ $class $class getName()]]> - getName()]]> - getName()]]> - $method getParameters()]]> getName()]]]> getName())][$method->getName()]]]> - __toString()]]> $param @@ -1580,46 +1129,39 @@ getName()]]]> getName()]]]> - getName())][$method->getName()]]]> - getName())][$method->getName()]]]> - $class $class $code $defaultValue - $method $overrides $overrides $paramDef + + string + getDeclaringClass getName getName getName - getName - getName - getName getParameterOverrides getParameterOverrides getParameters getReturnType - isInternal - isProtected - isPublic - isStatic isStatic - returnsReference $code - getName()]]> $paramDef renderMethodBody($method, $config)]]> renderParams($method, $config)]]> renderReturnType($method)]]> + + $code + $lastBrace @@ -1629,151 +1171,53 @@ - - __toString - getDeclaringClass - getDefaultValue - getName - getName - isDefaultValueAvailable - isDefaultValueConstant - isOptional - isPassedByReference - - - - - $code - - - apply - - - apply - - - $code - $methods - - apply - - $code methods[$method->getName()]]]> methods[$method->getName()]]]> - - methods[$method->getName()]]]> - methods[$method->getName()]]]> - - - $method - $target - - - getMethods - getName - getName - isFinal - - - apply - - - - - $code - - - apply - - - $code - - - $target - - - apply - $class $code - $code appendToClass - apply $class $class - - $target - - - hasInternalAncestor - implementsInterface - + + string + $code + + appendToClass( + $code, + PHP_VERSION_ID < 80100 ? self::DUMMY_METHOD_DEFINITION_LEGACY : self::DUMMY_METHOD_DEFINITION + )]]> + $lastBrace - - apply - - - - - $trait - - - $code - - - apply - - - $code - getName()]]> - $traits - - - $traits - - - getName - - - addPass - generate - - - $namedConfig - - + $className - $code - $namedConfig - $pass - - - apply - + + + new MockDefinition($namedConfig, $code) + addPass @@ -1798,27 +1242,15 @@ - getAttributes getShortName - hasInternalAncestor - implementsInterface inNamespace isAbstract - - $name - - - $name - - - getName - - - name]]> - + + $interface + @@ -1874,9 +1306,6 @@ - - shouldAllowMockingMethod - byDefault makePartial @@ -1897,28 +1326,8 @@ shouldNotHaveBeenCalled shouldNotHaveReceived - - null|array|Closure - null|array|Closure - - - - - getClassName()]]> - - - getCode()]]> - - - $path - - - getClassName()]]> - getCode()]]> - $path - RequireLoader diff --git a/psalm.xml.dist b/psalm.xml.dist index 0975e6470..0f6be81e9 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -20,11 +20,13 @@ - - + + + + diff --git a/tests/Unit/Mockery/MockWithClosureAsLastArgumentTest.php b/tests/Unit/Mockery/MockWithClosureAsLastArgumentTest.php index c7830707b..73f66590f 100644 --- a/tests/Unit/Mockery/MockWithClosureAsLastArgumentTest.php +++ b/tests/Unit/Mockery/MockWithClosureAsLastArgumentTest.php @@ -15,7 +15,7 @@ public function testIfClosureIsPassedAsLastArgumentToMockItIsCalledWithMockObjec { $mock = Mockery::mock( TestInterface::class, - static function (LegacyMockInterface|MockInterface $mock): void { + static function (LegacyMockInterface $mock): void { $mock->expects('blm')->andReturn('#BlackLivesMatter'); } );