If you create a Spy without a mock function, it will use the existing function. Example: namespace foo; use phpmock\spy\Spy; function bar($min, $max) { return rand($min, $max) + 3; } $spy = new Spy(__NAMESPACE__, "rand"); $spy->enable(); $result = bar(1, 2); assert ([1, 2] == $spy->getInvocations()[0]->getArguments()); assert ($result == $spy->getInvocations()[0]->getReturn() + 3);
Author: Markus Malkusch (markus@malkusch.de)
Inheritance: extends phpmock\Mock
Example #1
0
 /**
  * Tests the default function.
  *
  * @test
  */
 public function testDefaultFunction()
 {
     eval("function testDefaultFunction() { return 123; }");
     $spy = new Spy(__NAMESPACE__, "testDefaultFunction");
     $spy->enable();
     $result = testDefaultFunction();
     $this->assertEquals(123, $result);
 }
Example #2
0
 /**
  * Test the invocation of a none exception call.
  *
  * @test
  */
 public function testNoException()
 {
     eval("function testNoException() { }");
     $spy = new Spy(__NAMESPACE__, "testNoException");
     $spy->enable();
     testNoException();
     $invocation = $spy->getInvocations()[0];
     $this->assertFalse($invocation->isExceptionThrown());
     $this->assertNull($invocation->getException());
 }