Last active
February 9, 2016 07:55
-
-
Save clarkeash/b52aa68869a9bbda46c5 to your computer and use it in GitHub Desktop.
Laravel TestCase Improved
This file contains hidden or 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 | |
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']); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Now you can add
before
andafter
methods, which will auto inject their dependencies, and you wont have to callparent::setUp()
all the time like you currently have to.