예제 #1
0
 function testCanPartiallyStub()
 {
     $spy = Phockito::spy(SpyMe::class);
     Phockito::when($spy)->Foo()->return(1);
     $this->assertEquals($spy->Foo(), 1);
     $this->assertEquals($spy->Bar(), 1);
 }
 private function _setMatchingInvocationsTo($count)
 {
     $matchingInvocations = array();
     for ($i = 0; $i < $count; $i++) {
         $matchingInvocations[] = $this->_mockInvocation;
     }
     Phockito::when($this->_mockContext->getMatchingInvocations())->return($matchingInvocations);
 }
예제 #3
0
 function testSpyingCall()
 {
     $spy = Phockito::spy(OverloadedCall::class);
     $this->assertEquals($spy->Foo(), 'Foo');
     Phockito::when($spy)->Foo()->return(1);
     $this->assertEquals($spy->Foo(), 1);
     Phockito::verify($spy, 2)->Foo();
 }
예제 #4
0
 function testCanMockNamespacedClassWithGloballyResolvedTypedArgument()
 {
     $mock = Phockito::mock(HasGloballyResolvedTypedArguments::class);
     $arg = new Type();
     $this->assertNull($mock->Foo($arg));
     Phockito::when($mock->Foo($arg))->return('Bar');
     $this->assertEquals($mock->Foo($arg), 'Bar');
 }
예제 #5
0
 function testCanResetStubbedResultsForSpecificMethod()
 {
     $mock = Phockito::mock(MockMe::class);
     Phockito::when($mock)->Foo()->return(1);
     Phockito::when($mock)->Bar()->return(2);
     $this->assertEquals($mock->Foo(), 1);
     $this->assertEquals($mock->Foo(), 1);
     $this->assertEquals($mock->Bar(), 2);
     $this->assertEquals($mock->Bar(), 2);
     Phockito::reset($mock, 'Foo');
     $this->assertNull($mock->Foo());
     $this->assertEquals($mock->Bar(), 2);
 }
예제 #6
0
/**
 * When builder. Starts stubbing the method called to build the argument passed to when
 *
 * @param MockMarker|object|mixed|null $arg
 * @return WhenBuilder|Object
 */
function when($arg)
{
    return Phockito::when($arg);
}
예제 #7
0
 function testCanSpyAndOverrideUndefinedToString()
 {
     $mock = Phockito::spy(MockWithoutToString::class);
     Phockito::when($mock)->__toString()->return('NewReturnValue');
     $this->assertEquals('NewReturnValue', '' . $mock);
 }
예제 #8
0
 function testCanStubTypeHintedMethodsByPassingOnlyMockIntoWhen()
 {
     $mock = Phockito::mock(MockPassMe::class);
     Phockito::when($mock)->Baz(anything())->return('PassMe');
     $this->assertEquals($mock->Baz(new PassMe()), 'PassMe');
 }
예제 #9
0
 function testCanSpecifyReturnObjectForReferenceInterfaceImplemented()
 {
     //this call will fatal error if the derived type's method doesn't also return by ref
     //This is because it's defined like this in the interface (weird..)
     $mock = Phockito::mock(FooReturnsByReferenceImplements::class);
     $obj = new stdClass();
     Phockito::when($mock->Foo())->return($obj);
     $res =& $mock->Foo();
     $this->assertEquals($obj, $res);
 }
예제 #10
0
 /**
  * @expectedException PHPUnit_Framework_Error
  * @expectedExceptionCode E_USER_ERROR
  * @expectedExceptionMessage Can't mock non-existent class NotAClass
  */
 function testBridgingInvalidTypeThrowsException()
 {
     $mock = Phockito::mock(HamcrestMe::class);
     Phockito::when($mock->Foo(HamcrestTypeBridge::argOfTypeThat('NotAClass', anInstanceOf('NotAClass'))))->return('PassMe');
 }