Includes the Hamcrest matchers. You don't have to, but if you don't you can't to nice generic stubbing and verification
static public include_hamcrest ( $include_globals = true ) |
public function setUpOnce() { if (class_exists('Phockito')) { Phockito::include_hamcrest(false); } parent::setUpOnce(); }
/** * Test sending a message, expecting a successful response. */ public function testSendMessageSuccess() { \Phockito::include_hamcrest(false); try { $endpoint = 'https://some-test-endpoint'; $onlyAllowHttps = true; $xml = "<element>test response xml</element>"; // Dummy and Mock required objects $statusCode = 200; $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); // check the response $this->assertEquals($response, $xml); } catch (Exception $e) { $this->fail("Unexpected exception:" . $e->getMessage()); } }
function setUpOnce() { parent::setUpOnce(); if (class_exists('Phockito')) { Phockito::include_hamcrest(); } }
public function setUp() { Phockito::include_hamcrest(); $this->url_root = "/routing"; $this->controller_path = 'fixtures'; $this->controller_namespace = 'Kleinbottle\\tests\\fixtures'; $this->routes = array("/test/[i:var]" => "controller", "/empty/[i:var]" => "emptycontroller", "/empty/[i:var]/things" => "emptycontroller", "/test/[i:var]/tests" => "controller", "/nested/[i:var]" => array("/child/[i:var2]" => 'controller', "/child/[i:var2]/tests" => 'controller')); $this->router = Phockito::spy('Kleinbottle\\router', $this->url_root, $this->routes, $this->controller_path, $this->controller_namespace); $this->router->loadRoutes(); }
public function setUp() { Phockito::include_hamcrest(); $this->url_root = "/routing"; $this->controller_path = 'fixtures'; $this->controller_namespace = 'Kleinbottle\\tests\\fixtures'; $this->routes = array("/test/[i:var]" => "json"); $this->router = Phockito::spy('Kleinbottle\\router', $this->url_root, $this->routes, $this->controller_path, $this->controller_namespace); $this->router->initAutoload(); $this->router->loadRoutes(); }
function setUpOnce() { Phockito::include_hamcrest(true); }
<?php // Include Phockito require_once dirname(dirname(__FILE__)) . '/Phockito.php'; Phockito::include_hamcrest(); class PhockitoHamcrestTest_MockMe { function Foo($a, $b) { throw new Exception('Base method Foo was called'); } function Bar($a) { throw new Exception('Base method Bar was called'); } function Baz(PhockitoHamcrestTest_PassMe $a) { throw new Exception('Base method Baz was called'); } } class PhockitoHamcrestTest_PassMe { } class PhockitoHamcrestTest extends PHPUnit_Framework_TestCase { /** Test stubbing **/ function testCanStubByType() { $mock = Phockito::mock('PhockitoHamcrestTest_MockMe'); Phockito::when($mock->Foo(intValue(), stringValue()))->return('int,string'); Phockito::when($mock->Foo(stringValue(), stringValue()))->return('string,string');
public function setUpOnce() { parent::setUpOnce(); Phockito::include_hamcrest(); }
public function setUp() { Phockito::include_hamcrest(); $this->nameGenerator = Phockito::mock('NameGenerator'); $this->testObj = new Greeter($this->nameGenerator); }