Skip to content

Commit ff6d7fd

Browse files
committed
[#3] Don't use mockery because of sebastianbergmann/global-state#8
1 parent 19c0ac8 commit ff6d7fd

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

composer.json

-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
"phpunit/phpunit": "^4.0.0 || ^5.0.0",
2222
"php-mock/php-mock-integration": "^1"
2323
},
24-
"require-dev": {
25-
"mockery/mockery": "^0.9"
26-
},
2724
"archive": {
2825
"exclude": ["/tests"]
2926
}

tests/MockObjectProxyTest.php

+47-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace phpmock\phpunit;
44

5-
use Mockery;
5+
use \PHPUnit_Framework_MockObject_Builder_InvocationMocker as InvocationMocker;
66
use phpmock\integration\MockDelegateFunctionBuilder;
77

88
/**
@@ -11,17 +11,55 @@
1111
* @author Markus Malkusch <markus@malkusch.de>
1212
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
1313
* @license http://www.wtfpl.net/txt/copying/ WTFPL
14-
* @see MockObjectProxyTest
14+
* @see MockObjectProxy
15+
* @requires PHPUnit 4.5.0
1516
*/
1617
class MockObjectProxyTest extends \PHPUnit_Framework_TestCase
1718
{
19+
20+
/**
21+
* Tests expects()
22+
*
23+
* @test
24+
*/
25+
public function testExpects()
26+
{
27+
$matcher = $this->getMock(\PHPUnit_Framework_MockObject_Matcher_Invocation::class);
28+
29+
$invocationMocker = $this->getMock(InvocationMocker::class, [], [], '', false);
30+
$invocationMocker->expects($this->once())->method("method")
31+
->with(MockDelegateFunctionBuilder::METHOD)->willReturn($invocationMocker);
32+
33+
$prophecy = $this->prophesize(\PHPUnit_Framework_MockObject_MockObject::class);
34+
$prophecy->expects($matcher)->willReturn($invocationMocker);
35+
$mock = $prophecy->reveal();
36+
37+
$proxy = new MockObjectProxy($mock);
38+
39+
$result = $proxy->expects($matcher);
40+
$this->assertEquals($invocationMocker, $result);
41+
}
1842

1943
/**
20-
* Resets Mockery mocks.
44+
* Tests delegation of __phpunit_hasMatchers().
45+
*
46+
* Before PHPUnit-5 __phpunit_hasMatchers() was not part of the contract.
47+
* But it was used within PHPUnit as it would be. Unfortunately the
48+
* mocking framework Prophecy will not allow to mock this method.
49+
*
50+
* @test
51+
* @requires PHPUnit 5
2152
*/
22-
public function tearDown()
53+
public function testHasMatcher()
2354
{
24-
Mockery::close();
55+
$prophecy = $this->prophesize(\PHPUnit_Framework_MockObject_MockObject::class);
56+
$prophecy->__phpunit_hasMatchers()->willReturn("foo");
57+
$mock = $prophecy->reveal();
58+
59+
$proxy = new MockObjectProxy($mock);
60+
61+
$result = $proxy->__phpunit_hasMatchers();
62+
$this->assertEquals("foo", $result);
2563
}
2664

2765
/**
@@ -35,11 +73,11 @@ public function tearDown()
3573
*/
3674
public function testProxiedMethods($method, array $arguments = [], $expected = "foo")
3775
{
38-
$mock = Mockery::mock("PHPUnit_Framework_MockObject_MockObject");
39-
$proxy = new MockObjectProxy($mock);
76+
$prophecy = $this->prophesize(\PHPUnit_Framework_MockObject_MockObject::class);
77+
call_user_func_array([$prophecy, $method], $arguments)->willReturn($expected);
78+
$mock = $prophecy->reveal();
4079

41-
$mock->shouldReceive($method)
42-
->once()->withArgs($arguments)->andReturn($expected);
80+
$proxy = new MockObjectProxy($mock);
4381

4482
$result = call_user_func_array([$proxy, $method], $arguments);
4583
$this->assertEquals($expected, $result);
@@ -52,21 +90,10 @@ public function testProxiedMethods($method, array $arguments = [], $expected = "
5290
*/
5391
public function provideTestProxiedMethods()
5492
{
55-
$expects = Mockery::mock("PHPUnit_Framework_MockObject_Builder_InvocationMocker");
56-
$expects->shouldReceive("method")
57-
->withArgs([MockDelegateFunctionBuilder::METHOD])
58-
->andReturn($expects);
59-
6093
return [
6194
["__phpunit_getInvocationMocker"],
6295
["__phpunit_setOriginalObject", ["bar"]],
6396
["__phpunit_verify"],
64-
["__phpunit_hasMatchers"],
65-
[
66-
"expects",
67-
[Mockery::mock("PHPUnit_Framework_MockObject_Matcher_Invocation")],
68-
$expects
69-
],
7097
];
7198
}
7299
}

0 commit comments

Comments
 (0)