Exemplo n.º 1
1
 public function testJsonTypeMatchesWithJsonPath()
 {
     $this->module->response = '{"users": [{ "name": "davert"}, {"id": 1}]}';
     $this->module->seeResponseMatchesJsonType(['name' => 'string'], '$.users[0]');
     $this->module->seeResponseMatchesJsonType(['id' => 'integer'], '$.users[1]');
     $this->module->dontSeeResponseMatchesJsonType(['id' => 'integer'], '$.users[0]');
 }
Exemplo n.º 2
0
 public function testUrlIsFull()
 {
     $this->module->sendGET('/api/v1/users');
     /** @var $request \Symfony\Component\BrowserKit\Request  **/
     $request = $this->module->client->getRequest();
     $this->assertEquals('http://localhost:8010/api/v1/users', $request->getUri());
 }
Exemplo n.º 3
0
 public function testSeeHeadersOnce()
 {
     $this->shouldFail();
     $response = new \Symfony\Component\BrowserKit\Response("", 200, array('Cache-Control' => array('no-cache', 'no-store')));
     $this->module->client->mockResponse($response);
     $this->module->sendGET('/');
     $this->module->seeHttpHeaderOnce('Cache-Control');
 }
Exemplo n.º 4
0
 public function testFileUploadWithFilesArray()
 {
     $tmpFileName = tempnam('/tmp', 'test_');
     file_put_contents($tmpFileName, 'test data');
     $files = ['file' => ['name' => 'file.txt', 'type' => 'text/plain', 'size' => 9, 'tmp_name' => $tmpFileName]];
     $this->module->sendPOST('/rest/file-upload', [], $files);
     $this->module->seeResponseContainsJson(['uploaded' => true]);
 }
Exemplo n.º 5
0
 public function testStructuredJsonPathAndXPath()
 {
     $this->module->response = '{ "store": {"book": [{ "category": "reference", "author": "Nigel Rees", "title": "Sayings of the Century", "price": 8.95 }, { "category": "fiction", "author": "Evelyn Waugh", "title": "Sword of Honour", "price": 12.99 }, { "category": "fiction", "author": "Herman Melville", "title": "Moby Dick", "isbn": "0-553-21311-3", "price": 8.99 }, { "category": "fiction", "author": "J. R. R. Tolkien", "title": "The Lord of the Rings", "isbn": "0-395-19395-8", "price": 22.99 } ], "bicycle": {"color": "red", "price": 19.95 } } }';
     $this->module->seeResponseIsJson();
     $this->module->seeResponseJsonMatchesXpath('//book/category');
     $this->module->seeResponseJsonMatchesJsonPath('$..book');
     $this->module->seeResponseJsonMatchesJsonPath('$.store.book[2].author');
 }
Exemplo n.º 6
0
 public function testApplicationJsonSubtypeIncludesObjectSerialized()
 {
     $this->module->haveHttpHeader('Content-Type', 'application/resource+json');
     $this->module->sendPOST('/', new JsonSerializedItem());
     /** @var $request \Symfony\Component\BrowserKit\Request  **/
     $request = $this->module->client->getRequest();
     $this->assertContains('application/resource+json', $request->getServer());
     $this->assertJson($request->getContent());
 }
Exemplo n.º 7
0
 /**
  * @Issue https://github.com/Codeception/Codeception/issues/1650
  */
 public function testHostHeaders()
 {
     if (version_compare(PHP_VERSION, '5.5.0', '<')) {
         $this->markTestSkipped('only for php 5.5');
     }
     $this->module->haveHttpHeader('Host', 'http://www.example.com');
     $this->module->sendGET('/rest/ping/');
     $this->module->seeResponseContains('host: http://www.example.com');
 }
 /**
  * @Issue https://github.com/Codeception/Codeception/issues/1650
  */
 public function testHostHeader()
 {
     if (getenv('dependencies') === 'lowest') {
         $this->markTestSkipped('This test can\'t pass with the lowest versions of dependencies');
     }
     $this->module->sendGET('/rest/http-host/');
     $this->module->seeResponseContains('host: "localhost:8010"');
     $this->module->haveHttpHeader('Host', 'www.example.com');
     $this->module->sendGET('/rest/http-host/');
     $this->module->seeResponseContains('host: "www.example.com"');
 }
Exemplo n.º 9
0
 function getStreetNameById($id)
 {
     $this->restModule->haveHttpHeader('Content-Type', 'application/json');
     $city = $this->getCity(4);
     $this->restModule->sendGET('/lists/streets/' . $city);
     $streets = $this->restModule->grabResponse();
     $streetName = json_decode($streets)[$id]->name;
     //$this->debugSection('Street ID', $streetName);
     file_put_contents(codecept_data_dir('streets_name.json'), $streets);
     return $streetName;
 }
Exemplo n.º 10
0
 public function testGrabDataFromJsonResponse()
 {
     $this->module->sendGET('/rest/user/');
     // simple assoc array
     $this->assertEquals('*****@*****.**', $this->module->grabDataFromJsonResponse('email'));
     // nested assoc array
     $this->assertEquals('Kyiv', $this->module->grabDataFromJsonResponse('address.city'));
     // nested index array
     $this->assertEquals('DavertMik', $this->module->grabDataFromJsonResponse('aliases.0'));
     // fail if data not found
     $this->setExpectedException('PHPUnit_Framework_AssertionFailedError', 'Response does not have required data');
     $this->module->grabDataFromJsonResponse('address.street');
 }
Exemplo n.º 11
0
 /**
  * @Issue https://github.com/Codeception/Codeception/issues/1650
  */
 public function testDoubleGet()
 {
     $cest1 = Stub::makeEmpty('\\Codeception\\TestCase\\Cest');
     $cest2 = Stub::makeEmpty('\\Codeception\\TestCase\\Cest');
     $this->module->sendGET('/rest/user/');
     $this->module->seeResponseIsJson();
     $this->module->seeResponseContains('davert');
     $this->module->seeResponseContainsJson(array('name' => 'davert'));
     $this->module->seeResponseCodeIs(200);
     $this->module->dontSeeResponseCodeIs(404);
     $this->phpBrowser->_after($cest1);
     $this->module->_after($cest1);
     $this->module->_before($cest2);
     $this->phpBrowser->_before($cest2);
     $this->module->sendGET('/rest/user/');
     $this->module->seeResponseIsJson();
     $this->module->seeResponseContains('davert');
     $this->module->seeResponseContainsJson(array('name' => 'davert'));
     $this->module->seeResponseCodeIs(200);
     $this->module->dontSeeResponseCodeIs(404);
 }
Exemplo n.º 12
0
 public function testCanInspectResultOfPhpBrowserRequest()
 {
     $this->phpBrowser->amOnPage('/rest/user/');
     $this->module->seeResponseCodeIs(200);
     $this->module->seeResponseIsJson();
 }
Exemplo n.º 13
0
 /**
  * @Issue https://github.com/Codeception/Codeception/issues/2070
  */
 public function testArrayOfZeroesInJsonResponse()
 {
     $this->module->haveHttpHeader('Content-Type', 'application/json');
     $this->module->sendGET('/rest/zeroes');
     $this->module->dontSeeResponseContainsJson(['responseCode' => 0, 'data' => [0, 0, 0]]);
 }
 public function testGrabFromCurrentUrl()
 {
     $this->module->sendGET('/rest/http-host/');
     $this->assertEquals('/rest/http-host/', $this->phpBrowser->grabFromCurrentUrl());
 }
Exemplo n.º 15
0
 public function testSeeResponseIsJsonFailsWhenResponseIsInvalidJson()
 {
     $this->shouldFail();
     $this->setStubResponse('{');
     $this->module->seeResponseIsJson();
 }