Files
ticketbeast/tests/TestCase.php
2017-08-16 14:30:52 -04:00

70 lines
2.0 KiB
PHP

<?php
namespace Tests;
use Exception;
use App\Exceptions\Handler;
use PHPUnit\Framework\Assert;
use Illuminate\Foundation\Testing\TestResponse;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
abstract class TestCase extends \Illuminate\Foundation\Testing\TestCase
{
use CreatesApplication;
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
protected function setUp()
{
parent::setUp();
TestResponse::macro('data', function ($key) {
return $this->original->getData()[$key];
});
TestResponse::macro('assertViewIs', function ($name) {
Assert::assertEquals($name, $this->original->name());
});
EloquentCollection::macro('assertContains', function ($value) {
Assert::assertTrue($this->contains($value), "Failed asserting that the collection contains the specified value.");
});
EloquentCollection::macro('assertNotContains', function ($value) {
Assert::assertFalse($this->contains($value), "Failed asserting that the collection does not contain the specified value.");
});
EloquentCollection::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));
});
});
}
protected function disableExceptionHandling()
{
$this->app->instance(ExceptionHandler::class, new class extends Handler {
public function __construct() {}
public function report(Exception $e) {}
public function render($request, Exception $e) {
throw $e;
}
});
}
protected function from($url)
{
session()->setPreviousUrl(url($url));
return $this;
}
}