Skip to content

Instantly share code, notes, and snippets.

@clarkeash
Last active Feb 9, 2016
Embed
What would you like to do?
Laravel TestCase Improved
<?php
class TestCase extends Illuminate\Foundation\Testing\TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
public function setUp()
{
parent::setUp();
if(method_exists($this, 'before')) {
$this->app->call([$this, 'before']);
}
}
public function tearDown()
{
parent::tearDown();
if(method_exists($this, 'after')) {
$this->app->call([$this, 'after']);
}
}
}
@clarkeash
Copy link
Author

clarkeash commented Feb 9, 2016

Now you can add before and after methods, which will auto inject their dependencies, and you wont have to call parent::setUp() all the time like you currently have to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment