Skip to content

Instantly share code, notes, and snippets.

@clarkeash
Last active February 9, 2016 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clarkeash/b52aa68869a9bbda46c5 to your computer and use it in GitHub Desktop.
Save clarkeash/b52aa68869a9bbda46c5 to your computer and use it in GitHub Desktop.
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

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