Created
March 21, 2019 00:57
-
-
Save reinink/1b2cd63f17951e40a1d9cac2b1777f16 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
| use PHPUnit\Framework\Assert; | |
| use Illuminate\Database\Eloquent\Collection; | |
| use Illuminate\Foundation\Testing\TestResponse; | |
| TestResponse::macro('data', function ($key) { | |
| return $this->original->getData()[$key]; | |
| }); | |
| TestResponse::macro('assertUnauthorized', function () { | |
| $this->assertStatus(403); | |
| return $this; | |
| }); | |
| TestResponse::macro('assertNotFound', function () { | |
| $this->assertStatus(404); | |
| return $this; | |
| }); | |
| TestResponse::macro('assertValidationErrors', function () { | |
| $this->assertStatus(422); | |
| return $this; | |
| }); | |
| TestResponse::macro('assertViewContains', function ($key, $value) { | |
| $this->data($key)->assertContains($value); | |
| return $this; | |
| }); | |
| TestResponse::macro('assertViewNotContains', function ($key, $value) { | |
| $this->data($key)->assertNotContains($value); | |
| return $this; | |
| }); | |
| TestResponse::macro('assertViewData', function ($callback) { | |
| Assert::assertTrue($callback((object) $this->original->getData())); | |
| return $this; | |
| }); | |
| Collection::macro('assertContains', function ($value) { | |
| Assert::assertTrue($this->contains($value), 'Failed asserting that the collection contains the specified value.'); | |
| return $this; | |
| }); | |
| Collection::macro('assertNotContains', function ($value) { | |
| Assert::assertFalse($this->contains($value), 'Failed asserting that the collection does not contain the specified value.'); | |
| return $this; | |
| }); | |
| Collection::macro('assertEquals', function ($items) { | |
| Assert::assertEquals(count($this), count($items)); | |
| $this->zip($items)->each(function ($pair) { | |
| list($a, $b) = $pair; | |
| Assert::assertTrue($a->is($b)); | |
| }); | |
| return $this; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment