Completed
Push — master ( 5c46bf...f77784 )
by Mahmoud
03:22
created

TestCase::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace App\Port\Test\PHPUnit\Abstracts;
4
5
use Faker\Generator;
6
use Illuminate\Contracts\Console\Kernel as LaravelPort;
7
use Illuminate\Foundation\Testing\TestCase as LaravelTestCase;
8
use App\Port\Test\PHPUnit\Traits\TestingTrait;
9
10
/**
11
 * Class TestCase.
12
 *
13
 * @author  Mahmoud Zalt <[email protected]>
14
 */
15
abstract class TestCase extends LaravelTestCase
16
{
17
    use TestingTrait;
18
19
    /**
20
     * The base URL to use while testing the application.
21
     *
22
     * @var string
23
     */
24
    protected $baseUrl;
25
26
    /**
27
     * Setup the test environment, before each test.
28
     *
29
     * @return void
30
     */
31
    public function setUp()
32
    {
33
        parent::setUp();
34
35
        // migrate the database
36
        $this->artisan('migrate');
37
38
        // seed the database
39
        $this->seed();
40
    }
41
42
    /**
43
     * Reset the test environment, after each test.
44
     */
45
    public function tearDown()
46
    {
47
        $this->artisan('migrate:reset');
48
    }
49
50
    /**
51
     * Creates the application.
52
     *
53
     * @return \Illuminate\Foundation\Application
54
     */
55
    public function createApplication()
56
    {
57
        $this->baseUrl = env('API_FULL_URL'); // this reads the value from `phpunit.xml` during testing
58
59
        // override the default subDomain of the base URL when subDomain property is defined inside a test
60
        if(property_exists($this, 'subDomain')){
61
            $this->overrideSubDomain($this->subDomain);
0 ignored issues
show
Bug introduced by
The property subDomain 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...
62
        }
63
64
        $app = require __DIR__ . '/../../../../../bootstrap/app.php';
65
66
        $app->make(LaravelPort::class)->bootstrap();
67
68
        // create instance of faker and make it available in all tests
69
        $this->faker = $app->make(Generator::class);
0 ignored issues
show
Bug introduced by
The property faker 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...
70
71
        return $app;
72
    }
73
}
74