2
2
3
3
namespace phpmock \phpunit ;
4
4
5
- use Mockery ;
5
+ use \ PHPUnit_Framework_MockObject_Builder_InvocationMocker as InvocationMocker ;
6
6
use phpmock \integration \MockDelegateFunctionBuilder ;
7
7
8
8
/**
11
11
* @author Markus Malkusch <markus@malkusch.de>
12
12
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
13
13
* @license http://www.wtfpl.net/txt/copying/ WTFPL
14
- * @see MockObjectProxyTest
14
+ * @see MockObjectProxy
15
+ * @requires PHPUnit 4.5.0
15
16
*/
16
17
class MockObjectProxyTest extends \PHPUnit_Framework_TestCase
17
18
{
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
+ }
18
42
19
43
/**
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
21
52
*/
22
- public function tearDown ()
53
+ public function testHasMatcher ()
23
54
{
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 );
25
63
}
26
64
27
65
/**
@@ -35,11 +73,11 @@ public function tearDown()
35
73
*/
36
74
public function testProxiedMethods ($ method , array $ arguments = [], $ expected = "foo " )
37
75
{
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 ();
40
79
41
- $ mock ->shouldReceive ($ method )
42
- ->once ()->withArgs ($ arguments )->andReturn ($ expected );
80
+ $ proxy = new MockObjectProxy ($ mock );
43
81
44
82
$ result = call_user_func_array ([$ proxy , $ method ], $ arguments );
45
83
$ this ->assertEquals ($ expected , $ result );
@@ -52,21 +90,10 @@ public function testProxiedMethods($method, array $arguments = [], $expected = "
52
90
*/
53
91
public function provideTestProxiedMethods ()
54
92
{
55
- $ expects = Mockery::mock ("PHPUnit_Framework_MockObject_Builder_InvocationMocker " );
56
- $ expects ->shouldReceive ("method " )
57
- ->withArgs ([MockDelegateFunctionBuilder::METHOD ])
58
- ->andReturn ($ expects );
59
-
60
93
return [
61
94
["__phpunit_getInvocationMocker " ],
62
95
["__phpunit_setOriginalObject " , ["bar " ]],
63
96
["__phpunit_verify " ],
64
- ["__phpunit_hasMatchers " ],
65
- [
66
- "expects " ,
67
- [Mockery::mock ("PHPUnit_Framework_MockObject_Matcher_Invocation " )],
68
- $ expects
69
- ],
70
97
];
71
98
}
72
99
}
0 commit comments