public function tryToTest(AcceptanceTester $I) { $I->expectARequestToRemoteServiceWithAResponse(Phiremock::on(A::getRequest()->andUrl(Is::equalTo('/some/url')))->then(Respond::withStatusCode(203)->andBody('I am a response'))); $response = file_get_contents('http://localhost:18080/some/url'); $I->assertEquals('I am a response', $response); $I->seeRemoteServiceReceived(1, A::getRequest()->andUrl(Is::equalTo('/some/url'))); }
public function createAnExpectationWithRegexReplacementFromBodyAndUrl(AcceptanceTester $I) { $expectation = PhiremockClient::on(A::postRequest()->andUrl(Is::matching('/&test=(\\d+)/'))->andBody(Is::matching('/a tomato (\\d+)/')))->then(Respond::withStatusCode(200)->andBody('the numbers are ${url.1} and ${body.1}')); $this->phiremock->createExpectation($expectation); $I->sendPOST('/potato?param1=123&test=456', 'this is a tomato 3kg it weights'); $I->seeResponseCodeIs('200'); $I->seeResponseContains('the numbers are 456 and 3'); }
public function fullUrlShouldBeEvaluated(AcceptanceTester $I) { $expectation = PhiremockClient::on(A::postRequest()->andUrl(Is::equalTo('/potato/coconut/?tomato=123'))->andBody(Is::containing('This is the body')))->then(Respond::withStatusCode(202)->andBody('Tomato!')->andDelayInMillis(2500)->andHeader('X-Tomato', 'Potato-received')); $this->phiremock->createExpectation($expectation); $I->sendPOST('/potato/coconut/?tomato=123', '{"key": "This is the body"}'); $I->seeResponseCodeIs(202); $I->seeResponseEquals('Tomato!'); $I->seeHttpHeader('X-Tomato', 'Potato-received'); }