public function creationWithOnlyValidHeadersConditionTest(AcceptanceTester $I) { $I->wantTo('create an expectation that only checks headers'); $request = new Request(); $request->setHeaders(['Accept' => new Condition('matches', 'potato')]); $response = new Response(); $response->setStatusCode(201); $expectation = new Expectation(); $expectation->setRequest($request)->setResponse($response); $I->haveHttpHeader('Content-Type', 'application/json'); $I->sendPOST('/__phiremock/expectations', $expectation); $I->sendGET('/__phiremock/expectations'); $I->seeResponseCodeIs('200'); $I->seeResponseIsJson(); $I->seeResponseEquals('[{"scenarioName":null,"scenarioStateIs":null,"newScenarioState":null,' . '"request":{"method":null,"url":null,"body":null,"headers":{"Accept":{"matches":"potato"}}},' . '"response":{"statusCode":201,"body":null,"headers":null,"delayMillis":null},' . '"proxyTo":null,"priority":0}]'); }
public function responseExpectedWhenSeveralHeadersMatchesTest(AcceptanceTester $I) { $I->wantTo('see if mocking based in several request headers works'); $request = new Request(); $request->setHeaders(['Content-type' => new Condition('isEqualTo', 'application/x-www-form-urlencoded'), 'X-Potato' => new Condition('matches', '/.*tomato.*/'), 'X-Tomato' => new Condition('isSameString', 'PoTaTo')]); $response = new Response(); $response->setBody('Found'); $expectation = new Expectation(); $expectation->setRequest($request)->setResponse($response); $I->haveHttpHeader('Content-Type', 'application/json'); $I->sendPOST('/__phiremock/expectations', $expectation); $I->seeResponseCodeIs(201); $I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded'); $I->sendGET('/dontcare'); $I->seeResponseCodeIs(404); $I->haveHttpHeader('Content-Type', 'application/x-www-form-urlencoded'); $I->haveHttpHeader('X-potato', 'a-tomato-0'); $I->haveHttpHeader('X-tomato', 'potato'); $I->sendGET('/dontcare'); $I->seeResponseEquals('Found'); }