Completed
Branch proxy (a8ed88)
by leo
08:29
created

TestCase::getNonPublicMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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