<?php require 'vendor/autoload.php'; use GuzzleHttp\Client; class Check_Json_Value extends \PHPUnit_Framework_TestCase { public $client; public $nara; protected function setUp() { $this->client = new GuzzleHttp\Client([ 'base_url' => 'http://fambox2', 'defaults' => ['exceptions' => false] ]); $response = $this->client->get('/eng/api/films/separator/poker-am/'); $data = $response->json(); $json =json_encode($data) ; $json_to_array = json_decode($json); var_dump($json_to_array); } public function test_Delete_Error() { $response = $this->client->delete('/eng/api/menus/'); $this->assertEquals(200, $response->getStatusCode()); } public function testassertArrayHasKey() { $response = $this->client->get('/eng/api/films/separator/poker-am/'); $data = $response->json(); $json =json_encode($data) ; $json_to_array = json_decode($json); $this->assertArrayHasKey("video_link", $json_to_array); $this->assertArrayHasKey("watch_later", $json_to_array); $this->assertArrayHasKey("content", $json_to_array); $this->assertEquals('5_FP.mp4', $json_to_array['video_link']); $this->assertEquals('false', $json_to_array['watch_later']); $this->assertEquals('', $json_to_array['content']); } }
- You need JSONPath, Codeception already has the implementation of everything you need. - etki
|
1 answer
For example, like this:
$response = $this->call('post', 'api/v1/category'); $this->assertResponseStatus(400); $response = $response->original; $json = json_decode($response, true); $this->assertEquals(400, $json['status']);
- Ok, in the decoded array there is no "status" element or it is generally null. How does the test say about this? - etki
- Obviously, it will return an error not matching the current with the expected. - Pavel Sotnikov
- I know this, and how will he say what exactly is broken? - etki
- If the index does not exist, it returns:
Undefined index: _status
. If the value is, for example, null:Failed asserting that null matches expected 400. Expected :400 Actual :null
- Pavel Sotnikov - Yep And where is the message about what exactly broke in the algorithm? And if there will be a tenfold nesting? - etki
|