Last active
June 7, 2018 11:04
-
-
Save xzure/36902f3aa8686885046942449c4c3012 to your computer and use it in GitHub Desktop.
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 PHPUnit\Framework\Assert; | |
use Illuminate\Foundation\Testing\TestResponse; | |
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; | |
use Illuminate\Database\Eloquent\Collection as EloquentCollection; | |
abstract class TestCase extends BaseTestCase | |
{ | |
use CreatesApplication; | |
protected function setUp() | |
{ | |
parent::setUp(); | |
$this->withoutExceptionHandling(); | |
/** | |
* Return data attributes passed from the controller to the view | |
*/ | |
TestResponse::macro('data', function($key) { | |
if (array_key_exists($key, $this->original->getData())) { | |
return $this->original->getData()[$key]; | |
} | |
return null; | |
}); | |
/** | |
* Compare Eloquent collections | |
*/ | |
EloquentCollection::macro('assertEquals', function ($items) { | |
Assert::assertCount($items->count(), $this); | |
$this->zip($items)->each(function ($itemPair) { | |
Assert::assertTrue($itemPair[0]->is($itemPair[1])); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment