Skip to content

Instantly share code, notes, and snippets.

@nezarfadle
Last active July 20, 2017 10:30
Show Gist options
  • Save nezarfadle/6b3fa130788961e3895c8787a6c48dbf to your computer and use it in GitHub Desktop.
Save nezarfadle/6b3fa130788961e3895c8787a6c48dbf to your computer and use it in GitHub Desktop.
use Illuminate\Http\JsonResponse; 

class JsonEmptyResponse extends JsonResponse 
{ 
     
    public function __construct() 
    { 
         
        $data = [ 
          'data' => [] 
        ]; 
         
        parent::__construct( $data ); 

    } 
     
} 


abstract class TestCase extends BaseTestCase 
{ 
    use CreatesApplication; 
     
    public function setup() 
    { 
        
        parent::setup(); 
        
        \Illuminate\Foundation\Testing\TestResponse::macro('assertEmptyResponse', function(){ 
          $this->assertExactJson( (array) (new JsonEmptyResponse())->getData() ); 
        }); 

    } 

}

/** How to use **/

$res = $this->get('url');
$res->assertStatus( 200 )
    ->assertEmptyResponse();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment