diff --git a/composer.json b/composer.json index c3a3767..8088333 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } }, "require": { - "php": "^7.2", - "phpunit/phpunit": "^8.5" + "php": "^7.3", + "phpunit/phpunit": "^8.5|^9.0" } } diff --git a/src/EasyMock.php b/src/EasyMock.php index 27c5b52..8e02dfe 100644 --- a/src/EasyMock.php +++ b/src/EasyMock.php @@ -22,10 +22,8 @@ trait EasyMock * * @param string|MockObject $classname The class to mock. Can also be an existing mock to mock new methods. * @param array $methods Array of values to return, indexed by the method name. - * - * @return MockObject */ - protected function easyMock($classname, array $methods = array()): MockObject + protected function easyMock($classname, array $methods = []): MockObject { $mock = $classname instanceof MockObject ? $classname : $this->createMock($classname); @@ -45,10 +43,8 @@ protected function easyMock($classname, array $methods = array()): MockObject * * @param string|MockObject $classname The class to mock. Can also be an existing mock to mock new methods. * @param array $methods Array of values to return, indexed by the method name. - * - * @return MockObject */ - protected function easySpy($classname, array $methods = array()): MockObject + protected function easySpy($classname, array $methods = []): MockObject { $mock = $classname instanceof MockObject ? $classname : $this->createMock($classname); @@ -59,9 +55,7 @@ protected function easySpy($classname, array $methods = array()): MockObject return $mock; } - abstract protected function createMock($originalClassName): MockObject; - - private function mockMethod(MockObject $mock, $method, InvocationOrder $invocation, $return): void + private function mockMethod(MockObject $mock, string $method, InvocationOrder $invocation, $return): void { $methodAssertion = $mock->expects($invocation)->method($method); diff --git a/tests/EasyMockTest.php b/tests/EasyMockTest.php index b0ed11e..3c9fc7d 100644 --- a/tests/EasyMockTest.php +++ b/tests/EasyMockTest.php @@ -25,7 +25,7 @@ public function should_mock_objects(): void /** @var ClassFixture $mock */ $mock = $this->easyMock(ClassFixture::class); - $this->assertNull($mock->foo()); + self::assertNull($mock->foo()); } /** @@ -36,7 +36,7 @@ public function should_skip_the_constructor(): void /** @var ClassWithConstructor $mock */ $mock = $this->easyMock(ClassWithConstructor::class); - $this->assertFalse($mock->constructorCalled); + self::assertFalse($mock->constructorCalled); } /** @@ -47,7 +47,7 @@ public function should_mock_interfaces(): void /** @var InterfaceFixture $mock */ $mock = $this->easyMock(InterfaceFixture::class); - $this->assertNull($mock->foo()); + self::assertNull($mock->foo()); } /** @@ -58,7 +58,7 @@ public function not_mocked_methods_should_return_null(): void /** @var ClassFixture $mock */ $mock = $this->easyMock(ClassFixture::class); - $this->assertNull($mock->foo()); + self::assertNull($mock->foo()); } /** @@ -71,7 +71,7 @@ public function should_mock_existing_method_with_a_value(): void 'foo' => 'bar', )); - $this->assertSame('bar', $mock->foo()); + self::assertSame('bar', $mock->foo()); } /** @@ -86,7 +86,7 @@ public function should_mock_existing_method_with_a_callback(): void }, )); - $this->assertSame('bar', $mock->foo()); + self::assertSame('bar', $mock->foo()); } /** @@ -116,7 +116,7 @@ public function should_mock_new_methods_on_existing_mock(): void 'foo' => 'bar', )); - $this->assertSame('bar', $mock->foo()); + self::assertSame('bar', $mock->foo()); } /** @@ -134,8 +134,8 @@ public function should_allow_to_spy_method_calls(): void $property->setAccessible(true); $mockObjects = $property->getValue($this); - $this->assertCount(1, $mockObjects); - $this->assertSame($mock, $mockObjects[0]); + self::assertCount(1, $mockObjects); + self::assertSame($mock, $mockObjects[0]); // Cannot use @expectedException because PHPUnit has specific behavior for this try {