Passed
Branch proxy (abe564)
by leo
03:17
created

TestCase   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 87
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3
1
<?php
2
use Illuminate\Filesystem\ClassFinder;
3
use Illuminate\Filesystem\Filesystem;
4
5
/**
6
 * Created by PhpStorm.
7
 * User: leo108
8
 * Date: 2016/9/29
9
 * Time: 09:44
10
 */
11
class TestCase extends Illuminate\Foundation\Testing\TestCase
12
{
13
    /**
14
     * The base URL to use while testing the application.
15
     *
16
     * @var string
17
     */
18
    protected $baseUrl = 'http://localhost';
19
20
    /**
21
     * Creates the application.
22
     *
23
     * @return \Illuminate\Foundation\Application
24
     */
25
    public function createApplication()
26
    {
27
        $app = require __DIR__.'/../vendor/laravel/laravel/bootstrap/app.php';
28
29
        $app->register(Leo108\CAS\CASServerServiceProvider::class);
30
31
        $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
32
33
        return $app;
34
    }
35
36
    /**
37
     * Setup DB before each test.
38
     *
39
     * @return void
40
     */
41
    public function setUp()
42
    {
43
        parent::setUp();
44
45
        $config = require(__DIR__.'/../config/cas.php');
46
47
        $config['user_table']['model'] = User::class;
48
49
        $this->app['config']->set('cas', $config);
50
        $this->app['config']->set('database.default', 'sqlite');
51
        $this->app['config']->set('database.connections.sqlite.database', ':memory:');
52
53
        $this->migrate();
54
    }
55
56
    /**
57
     * run package database migrations
58
     *
59
     * @return void
60
     */
61
    public function migrate()
62
    {
63
        $fileSystem  = new Filesystem();
64
        $classFinder = new ClassFinder();
65
66
        foreach ($fileSystem->files(__DIR__.'/../database/migrations') as $file) {
67
            $fileSystem->requireOnce($file);
68
            $migrationClass = $classFinder->findClass($file);
69
70
            (new $migrationClass())->up();
71
        }
72
73
        $usersMigrationFile = __DIR__.'/_support/create_users_table.php';
74
75
        $fileSystem->requireOnce($usersMigrationFile);
76
        $migrationClass = $classFinder->findClass($usersMigrationFile);
77
        (new $migrationClass())->up();
78
    }
79
80
    protected static function getNonPublicMethod($obj, $name)
81
    {
82
        $class  = new ReflectionClass($obj);
83
        $method = $class->getMethod($name);
84
        $method->setAccessible(true);
85
86
        return $method;
87
    }
88
89
    protected static function getNonPublicProperty($obj, $name)
90
    {
91
        $class    = new ReflectionClass($obj);
92
        $property = $class->getProperty($name);
93
        $property->setAccessible(true);
94
95
        return $property;
96
    }
97
}
98