Created
November 16, 2017 13:55
-
-
Save martinbean/13a0aa121bb49ca4df7729ee381315d9 to your computer and use it in GitHub Desktop.
TestResponse fromJsonString() macro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests\Feature; | |
use Illuminate\Foundation\Testing\TestResponse; | |
use Tests\TestCase; | |
class ExampleTest extends TestCase | |
{ | |
public function testExample() | |
{ | |
$response = TestResponse::fromJsonString( | |
file_get_contents('http://example.com/test.json') | |
); | |
$response->assertJsonFragment( | |
// | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Tests; | |
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | |
abstract class TestCase extends BaseTestCase | |
{ | |
use CreatesApplication; | |
protected function setUp() | |
{ | |
parent::setUp(); | |
TestResponse::macro('fromJsonString', function ($string) { | |
return TestResponse::fromBaseResponse( | |
(new Response)->setContent($string) | |
); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment