/** Test creation of mock class for builtins **/ function testCanCreateBasicMockClassOfBuiltin() { $mock = Phockito::mock('SoapClient'); $this->assertInstanceOf('SoapClient', $mock); $this->assertNull($mock->Foo()); $this->assertNull($mock->Bar()); }
public function setUp() { parent::setUp(); Config::nest(); Injector::nest(); $this->securityWasEnabled = SecurityToken::is_enabled(); // Check dependencies if (!class_exists('Phockito')) { $this->skipTest = true; return $this->markTestSkipped("These tests need the Phockito module installed to run"); } // Reset config Config::inst()->update('SpellController', 'required_permission', 'CMS_ACCESS_CMSMain'); Config::inst()->remove('SpellController', 'locales'); Config::inst()->update('SpellController', 'locales', array('en_US', 'en_NZ', 'fr_FR')); Config::inst()->update('SpellController', 'enable_security_token', true); SecurityToken::enable(); // Setup mock for testing provider $spellChecker = Phockito::mock('SpellProvider'); Phockito::when($spellChecker)->checkWords('en_NZ', array('collor', 'colour', 'color', 'onee', 'correct'))->return(array('collor', 'color', 'onee')); Phockito::when($spellChecker)->checkWords('en_US', array('collor', 'colour', 'color', 'onee', 'correct'))->return(array('collor', 'colour', 'onee')); Phockito::when($spellChecker)->getSuggestions('en_NZ', 'collor')->return(array('collar', 'colour')); Phockito::when($spellChecker)->getSuggestions('en_US', 'collor')->return(array('collar', 'color')); Injector::inst()->registerService($spellChecker, 'SpellProvider'); }
function testCanMockAndOverrideUndefinedToString() { $mock = Phockito::mock('PhockitoTostringTest_MockWithoutToString'); $this->assertEquals('', '' . $mock); Phockito::when($mock->__toString())->return('NewReturnValue'); $this->assertEquals('NewReturnValue', '' . $mock); }
function testMockingCall() { $mock = Phockito::mock('PhockitoOverloadedCallTest_OverloadedCall'); $this->assertNull($mock->Foo()); Phockito::when($mock)->Foo()->return(1); $this->assertEquals($mock->Foo(), 1); Phockito::verify($mock, 2)->Foo(); }
function testPhockitoIntegration() { $mock = Phockito::mock('ViewableData'); Phockito::when($mock)->getField(stringValue())->return('Foo'); $this->assertEquals($mock->getField(1), null); $this->assertEquals($mock->getField('Bar'), 'Foo'); Phockito::verify($mock)->getField(integerValue()); }
protected function setUp() { $this->_metadataProvider = NorthWindMetadata::Create(); $this->_serviceConfiguration = new ServiceConfiguration($this->_metadataProvider); $this->_serviceConfiguration->setEntitySetAccessRule('*', EntitySetRights::ALL); $this->mockQueryProvider = \Phockito::mock('POData\\Providers\\Query\\IQueryProvider'); $this->providersWrapper = new ProvidersWrapper($this->_metadataProvider, $this->mockQueryProvider, $this->_serviceConfiguration, false); }
function testCanResetCallRecordForSpecificMethod() { $mock = Phockito::mock('PhockitoResetTest_MockMe'); $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(); }
public function setUp() { parent::setUp(); Injector::nest(); // Check dependencies if (!class_exists('Phockito')) { $this->skipTest = true; return $this->markTestSkipped("These tests need the Phockito module installed to run"); } // Mock link checker $checker = Phockito::mock('LinkChecker'); Phockito::when($checker)->checkLink('http://www.working.com')->return(200); Phockito::when($checker)->checkLink('http://www.broken.com/url/thing')->return(404); Phockito::when($checker)->checkLink('http://www.broken.com')->return(403); Phockito::when($checker)->checkLink('http://www.nodomain.com')->return(0); Phockito::when($checker)->checkLink('/internal/link')->return(null); Phockito::when($checker)->checkLink('[sitetree_link,id=9999]')->return(null); Phockito::when($checker)->checkLink('home')->return(null); Phockito::when($checker)->checkLink('broken-internal')->return(null); Phockito::when($checker)->checkLink('[sitetree_link,id=1]')->return(null); Phockito::when($checker)->checkLink(Hamcrest_Matchers::anything())->return(404); Injector::inst()->registerService($checker, 'LinkChecker'); }
function testCanMockNamespacedClassWithGloballyResolvedTypedArgument() { $mock = Phockito::mock('\\org\\phockito\\tests\\PhockitoNamespaceTest_HasGloballyResolvedTypedArguments'); $arg = new \org\phockito\tests\bar\PhockitoNamespaceTest_Type(); $this->assertNull($mock->Foo($arg)); Phockito::when($mock->Foo($arg))->return('Bar'); $this->assertEquals($mock->Foo($arg), 'Bar'); }
function testCanStubTypeHintedMethodsByPassingOnlyMockIntoWhen() { $mock = Phockito::mock('PhockitoHamcrestTest_MockMe'); Phockito::when($mock)->Baz(anything())->return('PassMe'); $this->assertEquals($mock->Baz(new PhockitoHamcrestTest_PassMe()), 'PassMe'); }
/** * @return Solr3Service */ protected function getServiceMock() { return Phockito::mock('Solr3Service'); }
protected function setUp() { $this->mockQueryProvider = \Phockito::mock('POData\\Providers\\Query\\IQueryProvider'); }
/** * @expectedException PHPUnit_Framework_Error * @expectedExceptionCode E_USER_ERROR * @expectedExceptionMessage Can't mock non-existent class NotAClass */ function testBridgingInvalidTypeThrowsException() { $mock = Phockito::mock('PhockitoHamcrestTypeBridgeTest_MockMe'); Phockito::when($mock->Foo(HamcrestTypeBridge::argOfTypeThat('NotAClass', anInstanceOf('NotAClass'))))->return('PassMe'); }
public function setUp() { Phockito::include_hamcrest(); $this->nameGenerator = Phockito::mock('NameGenerator'); $this->testObj = new Greeter($this->nameGenerator); }
/** * @expectedException PHPUnit_Framework_Error * @expectedExceptionCode E_USER_ERROR */ function testCannotMockFinalClass() { Phockito::mock('PhockitoTest_Final'); }
public function testProcessUnknownAbstractExpressionType() { //Currently the expression parser just ignores expression types it doesn't know //TODO: maybe this should throw instead?? $unknownExpression = \Phockito::mock('POData\\UriProcessor\\QueryProcessor\\ExpressionParser\\Expressions\\AbstractExpression'); $expressionProcessor = new ExpressionProcessor(new PHPExpressionProvider('$lt')); $actual = $expressionProcessor->processExpression($unknownExpression); $this->assertNull($actual); }
/** * Test sending a message, expecting an exception due to failure response. * */ public function testSendMessageFailure404() { // Dummy and Mock required objects $statusCode = 404; $this->setExpectedException("com\\realexpayments\\remote\\sdk\\RealexException", "Exception communicating with Realex"); try { $endpoint = 'https://some-test-endpoint'; $onlyAllowHttps = true; $xml = "<element>test response xml</element>"; $httpResponse = new HttpResponse(); $httpResponse->setResponseCode($statusCode); $httpResponse->setBody($xml); /** @var HttpConfiguration $configurationMock */ $configurationMock = \Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpConfiguration"); \Phockito::when($configurationMock->getEndPoint())->return($endpoint); \Phockito::when($configurationMock->isOnlyAllowHttps())->return($onlyAllowHttps); /** @var HttpClient $httpClientMock */ $httpClientMock = \Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpClient"); /** @var HttpRequest $anything */ \Phockito::when($httpClientMock->execute(\Hamcrest_Core_IsAnything::anything(), \Hamcrest_Core_IsAnything::anything()))->return($httpResponse); // execute the method $response = HttpUtils::sendMessage($xml, $httpClientMock, $configurationMock); } catch (RealexException $e) { throw $e; } catch (Exception $e) { $this->fail("Unexpected exception:" . $e->getMessage()); } }
/** * Creates a special mock of $type which wraps the given $matcher. * * @param string $type Name of the class to subtype * @param Hamcrest_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, Hamcrest_Matcher $matcher) { $mockOfType = Phockito::mock($type); $mockOfType->__phockito_matcher = $matcher; return $mockOfType; }