for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace App\Ship\Parents\Tests\PhpUnit;
use Artisan;
/**
* Class TestCaseTrait
*
* @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 null $url
public function overrideSubDomain($url = null)
// `subDomain` is a property defined in your class.
if (!property_exists($this, 'subDomain')) {
return;
$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'] . '://' . $this->subDomain . '.' . $withoutDomain;
subDomain
return $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: