Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Tests\Response;
- use App\Response\ApiResponse;
- use PHPUnit\Framework\TestCase;
- class ApiResponseTest extends TestCase
- {
- private $payload = [
- 'success' => true,
- 'message' => "Congrats! Success!"
- ];
- /**
- * @covers ApiResponse::fromArray()
- */
- public function testFromArray()
- {
- $apiResponse = new ApiResponse();
- $apiResponse->fromArray($this->payload);
- $result = $apiResponse->toJson();
- $this->assertJson($result);
- $this->assertEquals($result, json_encode($this->payload));
- }
- /**
- * @covers ApiResponse::fromJson()
- */
- public function testFromJson()
- {
- $apiResponse = new ApiResponse();
- $apiResponse->fromJson(json_encode($this->payload));
- $result = $apiResponse->toJson();
- $this->assertJson($result);
- $this->assertEquals($result, json_encode($this->payload));
- }
- /**
- * @covers ApiResponse::toJson()
- */
- public function testToJson()
- {
- $apiResponse = new ApiResponse();
- $apiResponse->fromJson(json_encode($this->payload));
- $result = $apiResponse->toJson();
- $this->assertJson($result);
- $this->assertEquals($result, json_encode($this->payload));
- }
- /**
- * @covers ApiResponse::fromJson()
- */
- public function testAddProperty()
- {
- $apiResponse = new ApiResponse();
- foreach ($this->payload as $key => $value){
- $apiResponse->addProperty($key, $value);
- }
- $result = $apiResponse->toJson();
- $this->assertJson($result);
- $this->assertEquals($result, json_encode($this->payload));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement