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')));
 }
Beispiel #2
0
 public function createAnExpectationWithRegexReplacementFromUrl(AcceptanceTester $I)
 {
     $expectation = PhiremockClient::on(A::getRequest()->andUrl(Is::matching('/&test=(\\d+)/')))->then(Respond::withStatusCode(200)->andBody('the number is ${url.1}'));
     $this->phiremock->createExpectation($expectation);
     $I->sendGET('/potato', ['param1' => 123, 'test' => 456]);
     $I->seeResponseCodeIs('200');
     $I->seeResponseContains('the number is 456');
 }
Beispiel #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);
 }
Beispiel #4
0
 public function countExecutionsWhenNoExpectationIsSet(AcceptanceTester $I)
 {
     $I->sendDELETE('/__phiremock/executions');
     $I->sendGET('/potato');
     $I->seeResponseCodeIs(404);
     $I->sendGET('/potato');
     $count = $this->phiremock->countExecutions(A::getRequest()->andUrl(Is::equalTo('/potato')));
     $I->assertEquals(2, $count);
     $count = $this->phiremock->countExecutions(A::getRequest()->andUrl(Is::matching('~potato~')));
     $I->assertEquals(2, $count);
 }