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); }
public function shouldCreateAnExpectationTestWithFluentInterface(AcceptanceTester $I) { $expectation = PhiremockClient::on(A::postRequest()->andUrl(Is::equalTo('/potato'))->andHeader('X-Potato', Is::sameStringAs('bAnaNa'))->andScenarioState('PotatoScenario', 'Scenario.START')->andBody(Is::equalTo('{"key": "This is the body"}')))->then(Respond::withStatusCode(202)->andBody('Tomato!')->andDelayInMillis(2500)->andHeader('X-Tomato', 'Potato-received')->andSetScenarioStateTo('visited')); $this->phiremock->createExpectation($expectation); $expectation = PhiremockClient::on(A::postRequest()->andUrl(Is::equalTo('/potato'))->andHeader('X-Potato', Is::sameStringAs('bAnaNa'))->andScenarioState('PotatoScenario', 'visited')->andBody(Is::matching('/.*"key".*/')))->then(Respond::withStatusCode(207)->andBody('Coconut!')->andDelayInMillis(1000)->andHeader('X-Tomato', 'Potato-received-again')->andSetScenarioStateTo('Scenario.START')); $this->phiremock->createExpectation($expectation); $I->haveHttpHeader('X-Potato', 'banana'); $start = microtime(true); $I->sendPOST('/potato', '{"key": "This is the body"}'); $I->assertGreaterThan(2500, (microtime(true) - $start) * 1000); $I->seeResponseCodeIs(202); $I->seeResponseEquals('Tomato!'); $I->seeHttpHeader('X-Tomato', 'Potato-received'); $I->haveHttpHeader('X-Potato', 'banana'); $start = microtime(true); $I->sendPOST('/potato', '{"key": "This is the body"}'); $I->assertGreaterThan(1000, (microtime(true) - $start) * 1000); $I->seeResponseCodeIs(207); $I->seeResponseEquals('Coconut!'); $I->seeHttpHeader('X-Tomato', 'Potato-received-again'); }