Completed
Push — master ( 7700d1...23cd67 )
by Mahmoud
03:21
created

TestCaseTrait::overrideSubDomain()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 4
nop 2
1
<?php
2
3
namespace App\Port\Test\PHPUnit\Traits;
4
5
use App;
6
use Artisan;
7
use Dingo\Api\Http\Response as DingoAPIResponse;
8
9
/**
10
 * Class TestCaseTrait
11
 *
12
 * Contains only functions needed by the main Test Case.
13
 *
14
 * @author  Mahmoud Zalt  <[email protected]>
15
 */
16
trait TestCaseTrait
17
{
18
19
    /**
20
     * Migrate the database.
21
     */
22
    public function migrateDatabase()
23
    {
24
        Artisan::call('migrate');
25
    }
26
27
    /**
28
     * override default URL subDomain in case you want to change it for some tests
29
     *
30
     * @param      $subDomain
31
     * @param null $url
32
     */
33
    public function overrideSubDomain($subDomain, $url = null)
34
    {
35
        $url = ($url) ? : $this->baseUrl;
0 ignored issues
show
Bug introduced by
The property baseUrl does not exist. Did you maybe forget to declare it?

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;
Loading history...
36
37
        $info = parse_url($url);
38
39
        $array = explode('.', $info['host']);
40
41
        $withoutDomain = (array_key_exists(count($array) - 2,
42
                $array) ? $array[count($array) - 2] : '') . '.' . $array[count($array) - 1];
43
44
        $newSubDomain = $info['scheme'] . '://' . $subDomain . '.' . $withoutDomain;
45
46
        $this->baseUrl = $newSubDomain;
47
    }
48
49
}
50