Completed
Branch 2.0 (f08412)
by Zhengchao
01:19
created

TestCase::migrate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of questocat/laravel-referral package.
5
 *
6
 * (c) questocat <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Tests;
13
14
use Illuminate\Filesystem\Filesystem;
15
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
16
use Tests\Stubs\UserStub;
17
18
class TestCase extends BaseTestCase
19
{
20
    use CreatesApplication;
21
22
    /**
23
     * Setup DB before each test.
24
     */
25
    public function setUp()
26
    {
27
        parent::setUp();
28
29
        $this->app['config']->set('database.default', 'sqlite');
30
        $this->app['config']->set('database.connections.sqlite.database', ':memory:');
31
        $this->app['config']->set('app.key', 'base64:jkHe+0IUIG1lp9d2LIaLjcsRZg4TIZ5Ccya2g/8ByGs=');
32
        if (empty($this->config)) {
33
            $this->config = require __DIR__.'/../config/referral.php';
0 ignored issues
show
Bug introduced by
The property config 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...
34
        }
35
        $this->app['config']->set('referral', $this->config);
36
        $this->migrate();
37
        $this->seedDatabase();
38
    }
39
40
    /**
41
     * run package database migrations.
42
     */
43
    public function migrate()
44
    {
45
        $fileSystem = new Filesystem();
46
        foreach ($fileSystem->files(__DIR__.'/../tests/database/migrations') as $file) {
47
            $fileSystem->requireOnce($file);
48
        }
49
        (new \CreateUsersTable())->up();
50
        (new \AddAffiliateIdToUsersTable())->up();
51
        (new \CreateReferralsTable())->up();
52
    }
53
54
    /**
55
     * Seed testing database.
56
     */
57
    public function seedDatabase()
58
    {
59
        UserStub::create([
0 ignored issues
show
Bug introduced by
The method create() does not exist on Tests\Stubs\UserStub. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
60
            'name' => 'questocat',
61
            'email' => '[email protected]',
62
            'password' => bcrypt('secret'),
63
        ]);
64
        UserStub::create([
0 ignored issues
show
Bug introduced by
The method create() does not exist on Tests\Stubs\UserStub. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
65
            'name' => 'zhengchaopu',
66
            'email' => '[email protected]',
67
            'password' => bcrypt('secret'),
68
        ]);
69
    }
70
}
71