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')));
 }
Ejemplo n.º 2
0
 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');
 }
Ejemplo n.º 3
0
 public function proxyToGivenUriTest(AcceptanceTester $I)
 {
     $expectation = PhiremockClient::on(A::getRequest()->andUrl(Is::equalTo('/potato'))->andHeader('X-Potato', Is::sameStringAs('bAnaNa'))->andScenarioState('PotatoScenario', 'Scenario.START'))->proxyTo('https://es.wikipedia.org/wiki/Proxy');
     $this->phiremock->createExpectation($expectation);
     $guzzle = new GuzzleHttp\Client();
     $originalBody = $guzzle->get('https://es.wikipedia.org/wiki/Proxy')->getBody();
     $I->haveHttpHeader('X-Potato', 'banana');
     $I->sendGet('/potato');
     $I->seeResponseEquals($originalBody);
 }
Ejemplo n.º 4
0
 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');
 }