Skip to content

Commit

Permalink
Support PHPUnit 9
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Aug 1, 2020
1 parent 11b7547 commit 1a58fdd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
},
"require": {
"php": "^7.2",
"phpunit/phpunit": "^8.5"
"php": "^7.3",
"phpunit/phpunit": "^8.5|^9.0"
}
}
12 changes: 3 additions & 9 deletions src/EasyMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
18 changes: 9 additions & 9 deletions tests/EasyMockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -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());
}

/**
Expand All @@ -86,7 +86,7 @@ public function should_mock_existing_method_with_a_callback(): void
},
));

$this->assertSame('bar', $mock->foo());
self::assertSame('bar', $mock->foo());
}

/**
Expand Down Expand Up @@ -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());
}

/**
Expand All @@ -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 {
Expand Down

0 comments on commit 1a58fdd

Please sign in to comment.