File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,23 @@ public function should_allow_to_spy_method_calls()
114114 'foo ' => 'bar ' ,
115115 ));
116116
117- $ this ->assertEquals ('bar ' , $ mock ->foo ());
117+ // Test PHPUnit's internals to check that the spy was registered
118+ $ property = new \ReflectionProperty ('PHPUnit_Framework_TestCase ' , 'mockObjects ' );
119+ $ property ->setAccessible (true );
120+ $ mockObjects = $ property ->getValue ($ this );
121+
122+ $ this ->assertCount (1 , $ mockObjects );
123+ $ this ->assertSame ($ mock , $ mockObjects [0 ]);
124+
125+ // Cannot use @expectedException because PHPUnit has specific behavior for this
126+ try {
127+ $ mock ->__phpunit_verify ();
128+ $ this ->fail ('Exception not thrown ' );
129+ } catch (\PHPUnit_Framework_ExpectationFailedException $ e ) {
130+ $ this ->assertContains ('Expected invocation at least once but it never occured ' , $ e ->getMessage ());
131+ }
132+
133+ // Invoke the mock: the test should now pass
134+ $ mock ->foo ();
118135 }
119136}
You can’t perform that action at this time.
0 commit comments