From 5d61b049d008214f67cd05f19030bd59c28efd1c Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sat, 8 Sep 2018 13:33:47 +0200 Subject: [PATCH] Fix CS/WS issues --- src/Framework/MockObject/Generator.php | 8 ++++++-- src/Framework/MockObject/MockMethod.php | 16 ++-------------- src/Framework/MockObject/MockMethodSet.php | 9 ++++++--- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/Framework/MockObject/Generator.php b/src/Framework/MockObject/Generator.php index f1c762edd2e..51988fb685e 100644 --- a/src/Framework/MockObject/Generator.php +++ b/src/Framework/MockObject/Generator.php @@ -649,7 +649,7 @@ private function generateMock($type, $explicitMethods, $mockClassName, $callOrig $isClass = false; $isInterface = false; $class = null; - $mockMethods = new MockMethodSet(); + $mockMethods = new MockMethodSet; if (\is_array($type)) { $interfaceMethods = []; @@ -676,16 +676,19 @@ private function generateMock($type, $explicitMethods, $mockClassName, $callOrig ) ); } + $methodReflection = $typeClass->getMethod($method); if ($this->canMockMethod($methodReflection)) { $mockMethods->addMethods( MockMethod::fromReflection($methodReflection, $callOriginalMethods, $cloneArguments) ); + $interfaceMethods[] = $method; } } } + unset($interfaceMethods); } @@ -744,6 +747,7 @@ private function generateMock($type, $explicitMethods, $mockClassName, $callOrig !$class->implementsInterface(Iterator::class) && !$class->implementsInterface(IteratorAggregate::class)) { $additionalInterfaces[] = Iterator::class; + $mockMethods->addMethods( ...$this->mockClassMethods(Iterator::class, $callOriginalMethods, $cloneArguments) ); @@ -801,7 +805,7 @@ private function generateMock($type, $explicitMethods, $mockClassName, $callOrig $configurable = []; /** @var MockMethod $mockMethod */ - foreach ($mockMethods->getMethods() as $mockMethod) { + foreach ($mockMethods->asArray() as $mockMethod) { $mockedMethods .= $mockMethod->generateCode(); $configurable[] = \strtolower($mockMethod->getName()); } diff --git a/src/Framework/MockObject/MockMethod.php b/src/Framework/MockObject/MockMethod.php index 0ecaddffec2..39e7ac22d52 100644 --- a/src/Framework/MockObject/MockMethod.php +++ b/src/Framework/MockObject/MockMethod.php @@ -151,20 +151,8 @@ 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, string $returnType, string $reference, bool $callOriginalMethod, bool $static, ?string $deprecation, bool $allowsReturnNull) + { $this->className = $className; $this->methodName = $methodName; $this->cloneArguments = $cloneArguments; diff --git a/src/Framework/MockObject/MockMethodSet.php b/src/Framework/MockObject/MockMethodSet.php index 4ec51316492..b81536a73c1 100644 --- a/src/Framework/MockObject/MockMethodSet.php +++ b/src/Framework/MockObject/MockMethodSet.php @@ -10,18 +10,21 @@ */ namespace PHPUnit\Framework\MockObject; -class MockMethodSet +final class MockMethodSet { + /** + * @var MockMethod[] + */ private $methods = []; - public function addMethods(MockMethod...$methods): void + public function addMethods(MockMethod ...$methods): void { foreach ($methods as $method) { $this->methods[\strtolower($method->getName())] = $method; } } - public function getMethods(): array + public function asArray(): array { return \array_values($this->methods); }