function testCanCreateBasicMockClassOfBuiltin() { $mock = Phockito::mock(SoapClient::class); $this->assertInstanceOf(SoapClient::class, $mock); $this->assertNull($mock->Foo()); $this->assertNull($mock->Bar()); }
function testCanMockAndOverrideUndefinedToString() { $mock = Phockito::mock(MockWithoutToString::class); $this->assertEquals('', '' . $mock); Phockito::when($mock->__toString())->return('NewReturnValue'); $this->assertEquals('NewReturnValue', '' . $mock); }
function testMockingCall() { $mock = Phockito::mock(OverloadedCall::class); $this->assertNull($mock->Foo()); Phockito::when($mock)->Foo()->return(1); $this->assertEquals($mock->Foo(), 1); Phockito::verify($mock, 2)->Foo(); }
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'); }
function testTwoCallsVerifiedWithAtMostPassesVerificationAgainstNoMoreInteractions() { $mock = Phockito::mock(self::MOCK_CLASS); $mock->Foo(); $mock->Foo(); Phockito::verify($mock, Phockito::atMost(2))->Foo(); Phockito::verifyNoMoreInteractions($mock); }
function setUp() { $this->_mockInvocation = Phockito::mock(Invocation::class); $this->_mockInvocation->args = array('actualArg'); $this->_mockContext = Phockito::mock(VerificationContext::class); Phockito::when($this->_mockContext->getMethodToVerify())->return('Foo'); $this->_wantedArgs = array('wantedArg'); Phockito::when($this->_mockContext->getArgumentsToVerify())->return($this->_wantedArgs); }
function setUp() { $this->_mockInvocation = Phockito::mock(Invocation::class); $this->_mockInvocation->args = array('actualArg'); $this->_mockInvocation->backtrace = array(array('dummy - eval()\'d code'), array('file' => 'someFile.php', 'line' => 123, 'class' => 'SomeClass', 'type' => '->', 'function' => 'someMethod', 'args' => array())); $this->_mockContext = Phockito::mock(VerificationContext::class); Phockito::when($this->_mockContext->getMethodToVerify())->return('Foo'); $this->_wantedArgs = array('wantedArg'); Phockito::when($this->_mockContext->getArgumentsToVerify())->return($this->_wantedArgs); }
function testCanResetCallRecordForSpecificMethod() { $mock = Phockito::mock(MockMe::class); $mock->Foo(); $mock->Bar(); Phockito::verify($mock)->Foo(); Phockito::verify($mock)->Bar(); Phockito::reset($mock, 'Foo'); Phockito::verify($mock, 0)->Foo(); Phockito::verify($mock)->Bar(); }
/** * Given a class name as a string, return a new instance which acts as a mock of that class * * @param string $class - The class to mock * @return Object - A mock of that class */ function mock($class) { return Phockito::mock($class); }
function testCanStubTypeHintedMethodsByPassingOnlyMockIntoWhen() { $mock = Phockito::mock(MockPassMe::class); Phockito::when($mock)->Baz(anything())->return('PassMe'); $this->assertEquals($mock->Baz(new PassMe()), 'PassMe'); }
/** * @expectedException \PHPUnit_Framework_Error * @expectedExceptionCode E_USER_ERROR */ function testCannotMockFinalClass() { Phockito::mock(FinalClass::class); }
/** * Creates a special mock of $type which wraps the given $matcher. * * @param string $type Name of the class to subtype * @param Matcher $matcher The matcher to proxy * @return Object A special mock of type $type that wraps $matcher, circumventing type issues. */ public static function argOfTypeThat($type, Matcher $matcher) { $mockOfType = Phockito::mock($type); $mockOfType->__phockito_matcher = $matcher; return $mockOfType; }
/** * @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'); }