Skip to content

Commit 1a58fdd

Browse files
committed
Support PHPUnit 9
1 parent 11b7547 commit 1a58fdd

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
},
1818
"require": {
19-
"php": "^7.2",
20-
"phpunit/phpunit": "^8.5"
19+
"php": "^7.3",
20+
"phpunit/phpunit": "^8.5|^9.0"
2121
}
2222
}

src/EasyMock.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ trait EasyMock
2222
*
2323
* @param string|MockObject $classname The class to mock. Can also be an existing mock to mock new methods.
2424
* @param array $methods Array of values to return, indexed by the method name.
25-
*
26-
* @return MockObject
2725
*/
28-
protected function easyMock($classname, array $methods = array()): MockObject
26+
protected function easyMock($classname, array $methods = []): MockObject
2927
{
3028
$mock = $classname instanceof MockObject ? $classname : $this->createMock($classname);
3129

@@ -45,10 +43,8 @@ protected function easyMock($classname, array $methods = array()): MockObject
4543
*
4644
* @param string|MockObject $classname The class to mock. Can also be an existing mock to mock new methods.
4745
* @param array $methods Array of values to return, indexed by the method name.
48-
*
49-
* @return MockObject
5046
*/
51-
protected function easySpy($classname, array $methods = array()): MockObject
47+
protected function easySpy($classname, array $methods = []): MockObject
5248
{
5349
$mock = $classname instanceof MockObject ? $classname : $this->createMock($classname);
5450

@@ -59,9 +55,7 @@ protected function easySpy($classname, array $methods = array()): MockObject
5955
return $mock;
6056
}
6157

62-
abstract protected function createMock($originalClassName): MockObject;
63-
64-
private function mockMethod(MockObject $mock, $method, InvocationOrder $invocation, $return): void
58+
private function mockMethod(MockObject $mock, string $method, InvocationOrder $invocation, $return): void
6559
{
6660
$methodAssertion = $mock->expects($invocation)->method($method);
6761

tests/EasyMockTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function should_mock_objects(): void
2525
/** @var ClassFixture $mock */
2626
$mock = $this->easyMock(ClassFixture::class);
2727

28-
$this->assertNull($mock->foo());
28+
self::assertNull($mock->foo());
2929
}
3030

3131
/**
@@ -36,7 +36,7 @@ public function should_skip_the_constructor(): void
3636
/** @var ClassWithConstructor $mock */
3737
$mock = $this->easyMock(ClassWithConstructor::class);
3838

39-
$this->assertFalse($mock->constructorCalled);
39+
self::assertFalse($mock->constructorCalled);
4040
}
4141

4242
/**
@@ -47,7 +47,7 @@ public function should_mock_interfaces(): void
4747
/** @var InterfaceFixture $mock */
4848
$mock = $this->easyMock(InterfaceFixture::class);
4949

50-
$this->assertNull($mock->foo());
50+
self::assertNull($mock->foo());
5151
}
5252

5353
/**
@@ -58,7 +58,7 @@ public function not_mocked_methods_should_return_null(): void
5858
/** @var ClassFixture $mock */
5959
$mock = $this->easyMock(ClassFixture::class);
6060

61-
$this->assertNull($mock->foo());
61+
self::assertNull($mock->foo());
6262
}
6363

6464
/**
@@ -71,7 +71,7 @@ public function should_mock_existing_method_with_a_value(): void
7171
'foo' => 'bar',
7272
));
7373

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

7777
/**
@@ -86,7 +86,7 @@ public function should_mock_existing_method_with_a_callback(): void
8686
},
8787
));
8888

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

9292
/**
@@ -116,7 +116,7 @@ public function should_mock_new_methods_on_existing_mock(): void
116116
'foo' => 'bar',
117117
));
118118

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

122122
/**
@@ -134,8 +134,8 @@ public function should_allow_to_spy_method_calls(): void
134134
$property->setAccessible(true);
135135
$mockObjects = $property->getValue($this);
136136

137-
$this->assertCount(1, $mockObjects);
138-
$this->assertSame($mock, $mockObjects[0]);
137+
self::assertCount(1, $mockObjects);
138+
self::assertSame($mock, $mockObjects[0]);
139139

140140
// Cannot use @expectedException because PHPUnit has specific behavior for this
141141
try {

0 commit comments

Comments
 (0)