Testbench Component is a simple package that is supposed to help you write tests for your Laravel package, especially when there is routing involved.
Laravel | Testbench |
---|---|
4.0.x | 2.0.x |
4.1.x | 2.1.x |
4.2.x | 2.2.x |
5.0.x | 3.0.x@dev |
To install through composer, simply put the following in your composer.json
file:
{
"require-dev": {
"orchestra/testbench": "3.0.*"
}
}
To use Testbench Component, all you need to do is extend Orchestra\Testbench\TestCase
instead of PHPUnit_Framework_TestCase
. The fixture app
booted by Orchestra\Testbench\TestCase
is predefined to follow the base application skeleton of Laravel 5.
<?php
class TestCase extends Orchestra\Testbench\TestCase {}
To load your package service provider, override the getPackageProviders
.
protected function getPackageProviders($app)
{
return ['Acme\AcmeServiceProvider'];
}
To load your package alias, override the getPackageAliases
.
protected function getPackageAliases($app)
{
return [
'Acme' => 'Acme\Facade'
];
}
Since Orchestral\Testbench\TestCase
overrides Laravel's Illuminate\Foundation\Testing\TestCase
, if you need your own setUp()
implementation, do not forget to call parent::setUp()
:
public function setUp()
{
parent::setUp();
// Your code here
}
To see a working example of testbench including how to set your configuration, check the file:
Fatal error: Class 'Illuminate\Foundation\Testing\TestCase' not found in /laravel/workbench/foo/bar/vendor/orchestra/testbench/src/Orchestra/Testbench/TestCase.php
Due to the requirement to include laravel/framework
when you install orchestra/testbench
, please remove any Illuminate dependencies to avoid a failed installation.