Example #1
0
 protected function getResponseWithStatusCode(Response $responseConfig, ResponseInterface $httpResponse)
 {
     if ($responseConfig->getStatusCode()) {
         $httpResponse = $httpResponse->withStatus($responseConfig->getStatusCode());
     }
     return $httpResponse;
 }
 private function getResponseWithBody(Response $responseConfig, ResponseInterface $httpResponse)
 {
     if ($responseConfig->getBody()) {
         $httpResponse = $httpResponse->withBody(new StringStream($responseConfig->getBody()));
     }
     return $httpResponse;
 }
 public function creationFailWhenEmptyRequestTest(AcceptanceTester $I)
 {
     $I->wantTo('See if creation fails when request is empty');
     $response = new Response();
     $response->setStatusCode(201);
     $expectation = new Expectation();
     $expectation->setResponse($response);
     $I->haveHttpHeader('Content-Type', 'application/json');
     $I->sendPOST('/__phiremock/expectations', $expectation);
     $I->seeResponseCodeIs('500');
     $I->seeResponseIsJson();
     $I->seeResponseEquals('{"result" : "ERROR", "details" : {"request":"Field request, was set with invalid value: NULL"}}');
 }
Example #4
0
 public function failWhenInvalidValueSpecifiedTest(AcceptanceTester $I)
 {
     $I->wantTo('create an expectation that checks url using matches');
     $request = new Request();
     $request->setUrl(new Condition('isEqualTo', null));
     $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->seeResponseCodeIs(500);
     $I->seeResponseIsJson();
     $I->seeResponseEquals('{"result" : "ERROR", "details" : ["Condition value can not be null"]}');
 }
 public function createExpectationWithStatusCodeTest(AcceptanceTester $I)
 {
     $I->wantTo('create a specificationwith a valid status code');
     $request = new Request();
     $request->setUrl(new Condition('isEqualTo', '/the/request/url'));
     $response = new Response();
     $response->setStatusCode(401);
     $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":{"isEqualTo":"\\/the\\/request\\/url"},"body":null,"headers":null},' . '"response":{"statusCode":401,"body":null,"headers":null,"delayMillis":null},' . '"proxyTo":null,"priority":0}]');
 }
 public function createSpecificationWithMoreThanOneHeaderInResponseTest(AcceptanceTester $I)
 {
     $I->wantTo('create an specification with several headers in response');
     $request = new Request();
     $request->setUrl(new Condition('isEqualTo', '/the/request/url'));
     $response = new Response();
     $response->setHeaders(['Location' => '/potato.php', 'Cache-Control' => 'private, max-age=0, no-cache', 'Pragma' => 'no-cache']);
     $specification = new Expectation();
     $specification->setRequest($request)->setResponse($response);
     $I->haveHttpHeader('Content-Type', 'application/json');
     $I->sendPOST('/__phiremock/expectations', $specification);
     $I->sendGET('/__phiremock/expectations');
     $I->seeResponseCodeIs(200);
     $I->seeResponseIsJson();
     $I->seeResponseEquals('[{"scenarioName":null,"scenarioStateIs":null,"newScenarioState":null,' . '"request":{"method":null,"url":{"isEqualTo":"\\/the\\/request\\/url"},"body":null,"headers":null},' . '"response":{"statusCode":200,"body":null,"headers":{' . '"Location":"\\/potato.php","Cache-Control":"private, max-age=0, no-cache",' . '"Pragma":"no-cache"},"delayMillis":null},' . '"proxyTo":null,"priority":0}]');
 }
 public function mockRequestWithDelayTest(AcceptanceTester $I)
 {
     $I->wantTo('mock a request with delay');
     $request = new Request();
     $request->setUrl(new Condition('isEqualTo', '/the/request/url'))->setMethod('GET');
     $response = new Response();
     $response->setDelayMillis(2000);
     $expectation = new Expectation();
     $expectation->setRequest($request)->setResponse($response);
     $I->haveHttpHeader('Content-Type', 'application/json');
     $I->sendPOST('/__phiremock/expectations', $expectation);
     $I->seeResponseCodeIs(201);
     $start = microtime(true);
     $I->sendGET('/the/request/url');
     $I->seeResponseCodeIs(200);
     $I->assertGreaterThan(2000, (microtime(true) - $start) * 1000);
 }
 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');
 }
Example #9
0
 public function responseExpectedWhenRequestBodyCaseInsensitiveEqualsTest(AcceptanceTester $I)
 {
     $I->wantTo('see if mocking based in request body case insensitive equality works');
     $request = new Request();
     $request->setBody(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->sendPOST('/dontcare', 'potato');
     $I->seeResponseCodeIs(200);
     $I->seeResponseEquals('Found');
 }
Example #10
0
 public function countExecutionsTest(AcceptanceTester $I)
 {
     $I->sendDELETE('/__phiremock/executions');
     $expectation = new Expectation();
     $request = new Request();
     $request->setMethod('get');
     $request->setUrl(new Condition('isEqualTo', '/potato'));
     $response = new Response();
     $response->setStatusCode(201);
     $response->setBody('Tomato!');
     $expectation->setRequest($request)->setResponse($response);
     $this->phiremock->createExpectation($expectation);
     $I->sendGET('/potato');
     $I->seeResponseCodeIs(201);
     $I->seeResponseEquals('Tomato!');
     $I->sendGET('/potato');
     $count = $this->phiremock->countExecutions(A::getRequest()->andUrl(Is::equalTo('/potato')));
     $I->assertEquals(2, $count);
 }
 public function failWhenInvalidMethodSpecifiedTest(AcceptanceTester $I)
 {
     $I->wantTo('create a specification that checks url using matches');
     $request = new Request();
     $request->setMethod('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->seeResponseCodeIs(500);
     $I->seeResponseIsJson();
     $I->seeResponseEquals('{"result" : "ERROR", "details" : {"request":"method: Field method, was set with invalid value: \'potato\'"}}');
 }
 protected function responseIsInvalid(Response $response)
 {
     return empty($response->getStatusCode());
 }