Skip to content

Instantly share code, notes, and snippets.

@xzure
Last active June 7, 2018 11:04
Show Gist options
  • Save xzure/36902f3aa8686885046942449c4c3012 to your computer and use it in GitHub Desktop.
Save xzure/36902f3aa8686885046942449c4c3012 to your computer and use it in GitHub Desktop.
<?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