Guest User

Untitled

a guest
Sep 21st, 2018
154
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Tests\Response;
  4.  
  5. use App\Response\ApiResponse;
  6. use PHPUnit\Framework\TestCase;
  7.  
  8. class ApiResponseTest extends TestCase
  9. {
  10.     private $payload = [
  11.         'success' => true,
  12.         'message' => "Congrats! Success!"
  13.     ];
  14.  
  15.     /**
  16.      * @covers ApiResponse::fromArray()
  17.      */
  18.     public function testFromArray()
  19.     {
  20.         $apiResponse = new ApiResponse();
  21.         $apiResponse->fromArray($this->payload);
  22.         $result = $apiResponse->toJson();
  23.  
  24.         $this->assertJson($result);
  25.         $this->assertEquals($result, json_encode($this->payload));
  26.     }
  27.  
  28.     /**
  29.      * @covers ApiResponse::fromJson()
  30.      */
  31.     public function testFromJson()
  32.     {
  33.         $apiResponse = new ApiResponse();
  34.         $apiResponse->fromJson(json_encode($this->payload));
  35.         $result = $apiResponse->toJson();
  36.  
  37.         $this->assertJson($result);
  38.         $this->assertEquals($result, json_encode($this->payload));
  39.     }
  40.  
  41.     /**
  42.      * @covers ApiResponse::toJson()
  43.      */
  44.     public function testToJson()
  45.     {
  46.         $apiResponse = new ApiResponse();
  47.         $apiResponse->fromJson(json_encode($this->payload));
  48.         $result = $apiResponse->toJson();
  49.  
  50.         $this->assertJson($result);
  51.         $this->assertEquals($result, json_encode($this->payload));
  52.  
  53.     }
  54.  
  55.     /**
  56.      * @covers ApiResponse::fromJson()
  57.      */
  58.     public function testAddProperty()
  59.     {
  60.         $apiResponse = new ApiResponse();
  61.         foreach ($this->payload as $key => $value){
  62.             $apiResponse->addProperty($key, $value);
  63.         }
  64.         $result = $apiResponse->toJson();
  65.  
  66.         $this->assertJson($result);
  67.         $this->assertEquals($result, json_encode($this->payload));
  68.     }
  69. }
RAW Paste Data