Skip to content

Commit aa0fa90

Browse files
committed
Fix #4 Compatibility with PHPUnit 5.4
1 parent 77d949e commit aa0fa90

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/EasyMock.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function easyMock($classname, array $methods = array())
3030
if ($classname instanceof MockObject) {
3131
$mock = $classname;
3232
} else {
33-
$mock = $this->createMock($classname);
33+
$mock = $this->doCreateMock($classname);
3434
}
3535

3636
foreach ($methods as $method => $return) {
@@ -58,7 +58,7 @@ protected function easySpy($classname, array $methods = array())
5858
if ($classname instanceof MockObject) {
5959
$mock = $classname;
6060
} else {
61-
$mock = $this->createMock($classname);
61+
$mock = $this->doCreateMock($classname);
6262
}
6363

6464
foreach ($methods as $method => $return) {
@@ -86,8 +86,14 @@ private function mockMethod(MockObject $mock, $method, InvocationMatcher $invoca
8686
* @param string $classname
8787
* @return MockObject
8888
*/
89-
private function createMock($classname)
89+
private function doCreateMock($classname)
9090
{
91+
// PHPUnit 5.4 method
92+
if (method_exists($this, 'createMock')) {
93+
return $this->createMock($classname);
94+
}
95+
96+
// Fallback on the deprecated method
9197
return $this->getMock(
9298
$classname,
9399
array(),

tests/EasyMockTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use EasyMock\EasyMock;
66
use EasyMock\Test\Fixture\ClassFixture;
7+
use EasyMock\Test\Fixture\ClassWithConstructor;
78
use EasyMock\Test\Fixture\CustomException;
89
use EasyMock\Test\Fixture\InterfaceFixture;
910

@@ -26,6 +27,16 @@ public function should_mock_objects()
2627
$this->assertNull($mock->foo());
2728
}
2829

30+
/**
31+
* @test
32+
*/
33+
public function should_skip_the_constructor()
34+
{
35+
/** @var ClassWithConstructor $mock */
36+
$mock = $this->easyMock('EasyMock\Test\Fixture\ClassWithConstructor');
37+
$this->assertFalse($mock->constructorCalled);
38+
}
39+
2940
/**
3041
* @test
3142
*/
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace EasyMock\Test\Fixture;
4+
5+
class ClassWithConstructor
6+
{
7+
public $constructorCalled = false;
8+
9+
public function __construct()
10+
{
11+
$this->constructorCalled = true;
12+
}
13+
}

0 commit comments

Comments
 (0)