Skip to content

Commit

Permalink
Fix #4 Compatibility with PHPUnit 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mnapoli committed Jun 4, 2016
1 parent 77d949e commit aa0fa90
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/EasyMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function easyMock($classname, array $methods = array())
if ($classname instanceof MockObject) {
$mock = $classname;
} else {
$mock = $this->createMock($classname);
$mock = $this->doCreateMock($classname);
}

foreach ($methods as $method => $return) {
Expand Down Expand Up @@ -58,7 +58,7 @@ protected function easySpy($classname, array $methods = array())
if ($classname instanceof MockObject) {
$mock = $classname;
} else {
$mock = $this->createMock($classname);
$mock = $this->doCreateMock($classname);
}

foreach ($methods as $method => $return) {
Expand Down Expand Up @@ -86,8 +86,14 @@ private function mockMethod(MockObject $mock, $method, InvocationMatcher $invoca
* @param string $classname
* @return MockObject
*/
private function createMock($classname)
private function doCreateMock($classname)
{
// PHPUnit 5.4 method
if (method_exists($this, 'createMock')) {
return $this->createMock($classname);
}

// Fallback on the deprecated method
return $this->getMock(
$classname,
array(),
Expand Down
11 changes: 11 additions & 0 deletions tests/EasyMockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use EasyMock\EasyMock;
use EasyMock\Test\Fixture\ClassFixture;
use EasyMock\Test\Fixture\ClassWithConstructor;
use EasyMock\Test\Fixture\CustomException;
use EasyMock\Test\Fixture\InterfaceFixture;

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

/**
* @test
*/
public function should_skip_the_constructor()
{
/** @var ClassWithConstructor $mock */
$mock = $this->easyMock('EasyMock\Test\Fixture\ClassWithConstructor');
$this->assertFalse($mock->constructorCalled);
}

/**
* @test
*/
Expand Down
13 changes: 13 additions & 0 deletions tests/Fixture/ClassWithConstructor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace EasyMock\Test\Fixture;

class ClassWithConstructor
{
public $constructorCalled = false;

public function __construct()
{
$this->constructorCalled = true;
}
}

0 comments on commit aa0fa90

Please sign in to comment.