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

TestCaseTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A migrateDatabase() 0 4 1
A overrideSubDomain() 0 15 3
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