when() 정적인 공개 메소드

When builder. Starts stubbing the method called to build the argument passed to when
static public when ( $arg = null ) : Phockito_WhenBuilder
리턴 Phockito_WhenBuilder
 /**
  * Setup a mock service using Phockito::spy() to mock a basic version of `isAPIAvaiable`
  * @param boolean $available Can change this to account for when API is unavailable
  * @return __phockito_FlickrService_Spy
  */
 public function getMockService($available = true)
 {
     // setup mock
     $spy = Phockito::spy('FlickrService');
     Phockito::when($spy)->isAPIAvailable()->return($available);
     return $spy;
 }
예제 #2
0
 public function testGreetNameReturnsWorldWhenGeneratorIsBlank()
 {
     Phockito::when($this->nameGenerator)->generate()->return("");
     $actual = $this->testObj->greet();
     $expected = "Hello, World";
     Test::assertEqual($expected, $actual);
 }
 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');
 }
예제 #4
0
 /** Test stubbing **/
 function testCanPartiallyStub()
 {
     $spy = Phockito::spy('PhockitoSpiesTest_MockMe');
     Phockito::when($spy)->Foo()->return(1);
     $this->assertEquals($spy->Foo(), 1);
     $this->assertEquals($spy->Bar(), 1);
 }
예제 #5
0
 /**
  * @expectedException RuntimeException
  */
 public function testPostPactFailure()
 {
     $http = Phockito::spy('Pact\\HttpClient');
     Phockito::when($http)->execute()->return(false);
     $mockServiceRequests = new MockServiceRequests($http);
     $pactDetails = ['consumer' => ['name' => 'c'], 'provider' => ['name' => 'p']];
     $mockServiceRequests->postPact($pactDetails, 'http://127.0.0.1');
 }
 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());
 }
 function testSpyingCall()
 {
     $spy = Phockito::spy('PhockitoOverloadedCallTest_OverloadedCall');
     $this->assertEquals($spy->Foo(), 'Foo');
     Phockito::when($spy)->Foo()->return(1);
     $this->assertEquals($spy->Foo(), 1);
     Phockito::verify($spy, 2)->Foo();
 }
예제 #8
0
 function testCanResetStubbedResultsForSpecificMethod()
 {
     $mock = Phockito::mock('PhockitoResetTest_MockMe');
     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);
 }
 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');
 }
예제 #10
0
 /**
  * Test sending a ThreeDSecure Verify Enrolled request and receiving a ThreeDSecure Verify Enrolled response.
  *
  * @expectedException com\realexpayments\remote\sdk\RealexException
  */
 public function testSendThreeDSecureInvalidResponseHash()
 {
     //get sample response XML
     $path = SampleXmlValidationUtils::THREE_D_SECURE_VERIFY_ENROLLED_RESPONSE_XML_PATH;
     $prefix = __DIR__ . '/../../resources';
     $xml = file_get_contents($prefix . $path);
     $fromXMLResponse = new ThreeDSecureResponse();
     $fromXMLResponse = $fromXMLResponse->fromXml($xml);
     // add invalid hash
     $fromXMLResponse->setHash("invalid hash");
     //mock HttpResponse
     /** @var HttpResponse $httpResponseMock */
     $httpResponseMock = Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpResponse");
     \Phockito::when($httpResponseMock->getBody())->return($fromXMLResponse->toXML());
     \Phockito::when($httpResponseMock->getResponseCode())->return(200);
     // create empty request
     $request = new ThreeDSecureRequest();
     $httpConfiguration = new HttpConfiguration();
     $httpConfiguration->addOnlyAllowHttps(false)->addEndpoint("https://epage.payandshop.com/epage-remote.cgi");
     // mock HttpClient instance
     $httpClientMock = Phockito::mock("com\\realexpayments\\remote\\sdk\\http\\HttpClient");
     \Phockito::when($httpClientMock->execute(\Hamcrest_Core_IsAnything::anything(), \Hamcrest_Core_IsAnything::anything()))->return($httpResponseMock);
     // execute and send on client
     $realexClient = new RealexClient(SampleXmlValidationUtils::SECRET, $httpConfiguration, $httpClientMock);
     $realexClient->send($request);
     $this->fail("RealexException should have been thrown before this point.");
 }
 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');
 }
예제 #12
0
 public function mockController()
 {
     $this->controller = Phockito::spy('Kleinbottle\\tests\\fixtures\\controller');
     Phockito::when($this->router)->loadController('controller')->return($this->controller);
     $this->router->captureOutput();
 }
 function testCanSpyAndOverrideUndefinedToString()
 {
     $mock = Phockito::spy('PhockitoTostringTest_MockWithoutToString');
     Phockito::when($mock)->__toString()->return('NewReturnValue');
     $this->assertEquals('NewReturnValue', '' . $mock);
 }
예제 #14
0
 public function mockController()
 {
     $this->controller = Phockito::spy('Kleinbottle\\tests\\fixtures\\json');
     Phockito::when($this->router)->loadController('json')->return($this->controller);
 }
 function testCanStubTypeHintedMethodsByPassingOnlyMockIntoWhen()
 {
     $mock = Phockito::mock('PhockitoHamcrestTest_MockMe');
     Phockito::when($mock)->Baz(anything())->return('PassMe');
     $this->assertEquals($mock->Baz(new PhockitoHamcrestTest_PassMe()), 'PassMe');
 }
 /**
  * @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');
 }
예제 #17
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('PhockitoTest_FooReturnsByReference_Implements');
     $obj = new stdClass();
     Phockito::when($mock->Foo())->return($obj);
     $res =& $mock->Foo();
     $this->assertEquals($obj, $res);
 }
예제 #18
0
 /**
  * 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());
     }
 }
 protected function getServiceSpy()
 {
     $serviceSpy = Phockito::spy('Solr3Service');
     Phockito::when($serviceSpy)->_sendRawPost()->return($this->getFakeRawSolrResponse());
     return $serviceSpy;
 }