for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Port\Test\PHPUnit\Abstracts;
use Faker\Generator;
use Illuminate\Contracts\Console\Kernel as LaravelPort;
use Illuminate\Foundation\Testing\TestCase as LaravelTestCase;
use App\Port\Test\PHPUnit\Traits\TestingTrait;
/**
* Class TestCase.
*
* @author Mahmoud Zalt <[email protected]>
*/
abstract class TestCase extends LaravelTestCase
{
use TestingTrait;
* The base URL to use while testing the application.
* @var string
protected $baseUrl;
* Setup the test environment, before each test.
* @return void
public function setUp()
parent::setUp();
// migrate the database
$this->artisan('migrate');
// seed the database
$this->seed();
}
* Reset the test environment, after each test.
public function tearDown()
$this->artisan('migrate:reset');
* Creates the application.
* @return \Illuminate\Foundation\Application
public function createApplication()
$this->baseUrl = env('API_FULL_URL'); // this reads the value from `phpunit.xml` during testing
// override the default subDomain of the base URL when subDomain property is defined inside a test
if(property_exists($this, 'subDomain')){
$this->overrideSubDomain($this->subDomain);
subDomain
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$app = require __DIR__ . '/../../../../../bootstrap/app.php';
$app->make(LaravelPort::class)->bootstrap();
// create instance of faker and make it available in all tests
$this->faker = $app->make(Generator::class);
faker
return $app;
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: