for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Port\Test\PHPUnit\Traits;
use App;
use Artisan;
use Dingo\Api\Http\Response as DingoAPIResponse;
/**
* Class TestCaseTrait
*
* Contains only functions needed by the main Test Case.
* @author Mahmoud Zalt <[email protected]>
*/
trait TestCaseTrait
{
* Migrate the database.
public function migrateDatabase()
Artisan::call('migrate');
}
* override default URL subDomain in case you want to change it for some tests
* @param $subDomain
* @param null $url
public function overrideSubDomain($subDomain, $url = null)
$url = ($url) ? : $this->baseUrl;
baseUrl
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;
$info = parse_url($url);
$array = explode('.', $info['host']);
$withoutDomain = (array_key_exists(count($array) - 2,
$array) ? $array[count($array) - 2] : '') . '.' . $array[count($array) - 1];
$newSubDomain = $info['scheme'] . '://' . $subDomain . '.' . $withoutDomain;
$this->baseUrl = $newSubDomain;
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: