1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Simplifies the creation of tests creating a full application, running migrations and loading multiple Service Providers |
5
|
|
|
*/ |
6
|
|
|
namespace Rocket\Utilities; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class TestCase |
10
|
|
|
* @codeCoverageIgnore |
11
|
|
|
*/ |
12
|
|
|
class TestCase extends \Orchestra\Testbench\TestCase |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Setup the test environment. |
16
|
|
|
* |
17
|
|
|
* @return void |
18
|
|
|
*/ |
19
|
|
|
public function setUp(): void |
20
|
|
|
{ |
21
|
|
|
if (!$this->app) { |
22
|
|
|
$this->refreshApplication(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$artisan = $this->app->make('Illuminate\Contracts\Console\Kernel'); |
26
|
|
|
$artisan->call('vendor:publish'); |
27
|
|
|
|
28
|
|
|
//refresh configuration values |
29
|
|
|
$this->refreshApplication(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Clean up the testing environment before the next test. |
34
|
|
|
* |
35
|
|
|
* @return void |
36
|
|
|
*/ |
37
|
|
|
public function tearDown(): void |
38
|
|
|
{ |
39
|
|
|
parent::tearDown(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Define environment setup. |
44
|
|
|
* |
45
|
|
|
* @param \Illuminate\Foundation\Application $app |
46
|
|
|
* @return void |
47
|
|
|
*/ |
48
|
|
|
protected function getEnvironmentSetUp($app) |
49
|
|
|
{ |
50
|
|
|
// reset base path to point to our package's src directory |
51
|
|
|
$app['path.base'] = realpath(__DIR__ . '/..'); |
52
|
|
|
|
53
|
|
|
$app['config']->set( |
54
|
|
|
'database.connections', |
55
|
|
|
[ |
56
|
|
|
'default' => [ |
57
|
|
|
'driver' => 'sqlite', |
58
|
|
|
'database' => ':memory:', |
59
|
|
|
'prefix' => '', |
60
|
|
|
], |
61
|
|
|
// create database travis_test; |
62
|
|
|
// grant usage on *.* to travis@localhost; |
63
|
|
|
// grant all privileges on travis_test.* to travis@localhost; |
64
|
|
|
'travis-mysql' => [ |
65
|
|
|
'driver' => 'mysql', |
66
|
|
|
'host' => 'localhost', |
67
|
|
|
'database' => 'travis_test', |
68
|
|
|
'username' => 'travis', |
69
|
|
|
'password' => '', |
70
|
|
|
'charset' => 'utf8', |
71
|
|
|
'collation' => 'utf8_unicode_ci', |
72
|
|
|
'prefix' => '', |
73
|
|
|
], |
74
|
|
|
'travis-pgsql' => [ |
75
|
|
|
'driver' => 'pgsql', |
76
|
|
|
'host' => 'localhost', |
77
|
|
|
'database' => 'travis_test', |
78
|
|
|
'username' => 'postgres', |
79
|
|
|
'password' => '', |
80
|
|
|
'charset' => 'utf8', |
81
|
|
|
'prefix' => '', |
82
|
|
|
'schema' => 'public', |
83
|
|
|
], |
84
|
|
|
] |
85
|
|
|
); |
86
|
|
|
|
87
|
|
|
$app['config']->set('database.default', 'default'); |
88
|
|
|
if ($db = getenv('DB')) { |
89
|
|
|
if ($db == 'pgsql') { |
90
|
|
|
$app['config']->set('database.default', 'travis-pgsql'); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
if ($db == 'mysql') { |
94
|
|
|
$app['config']->set('database.default', 'travis-mysql'); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|