1 | <?php |
||
8 | class AbstractTestCase extends TestCase |
||
9 | { |
||
10 | /** |
||
11 | * Define environment setup. |
||
12 | * |
||
13 | * @param \Illuminate\Foundation\Application $app |
||
14 | * @return void |
||
15 | */ |
||
16 | protected function getEnvironmentSetUp($app) |
||
17 | { |
||
18 | // Setup default database to use sqlite :memory: |
||
19 | $app['config']->set('database.default', 'testbench'); |
||
20 | $app['config']->set('database.connections.testbench', [ |
||
21 | 'driver' => 'sqlite', |
||
22 | 'database' => ':memory:', |
||
23 | 'prefix' => '', |
||
24 | ]); |
||
25 | |||
26 | if (! class_exists('MetaMigration')) { |
||
27 | static::makeMigration(); |
||
28 | } else { |
||
29 | static::migrate(); |
||
30 | } |
||
31 | |||
32 | parent::getEnvironmentSetUp($app); |
||
33 | } |
||
34 | |||
35 | protected function getPackageProviders($app) |
||
36 | { |
||
37 | return [MetaServiceProvider::class]; |
||
38 | } |
||
39 | |||
40 | protected static function makeMigration($args = []) |
||
41 | { |
||
42 | $artisan = app()->make('Illuminate\Contracts\Console\Kernel'); |
||
43 | |||
44 | $artisan->call('make:meta-migration', $args); |
||
45 | |||
46 | static::migrate(); |
||
47 | } |
||
48 | |||
49 | protected static function migrate() |
||
50 | { |
||
51 | $artisan = app()->make('Illuminate\Contracts\Console\Kernel'); |
||
52 | |||
53 | // Models |
||
54 | $artisan->call('migrate', [ |
||
55 | '--database' => 'testbench', |
||
56 | '--realpath' => realpath(__DIR__.'/Migrations'), |
||
57 | ]); |
||
58 | |||
59 | // Meta |
||
60 | $artisan->call('migrate', [ |
||
61 | '--database' => 'testbench', |
||
62 | '--realpath' => app()->databasePath().'/migrations', |
||
63 | ]); |
||
64 | } |
||
65 | } |
||
66 |