|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MaksimM\CompositePrimaryKeys\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use DB; |
|
6
|
|
|
use Exception; |
|
7
|
|
|
use Illuminate\Database\Events\QueryExecuted; |
|
8
|
|
|
use Illuminate\Foundation\Application; |
|
9
|
|
|
use Orchestra\Testbench\TestCase; |
|
10
|
|
|
use TestBinaryRoleSeeder; |
|
11
|
|
|
use TestBinaryUserSeeder; |
|
12
|
|
|
use TestOrganizationSeeder; |
|
13
|
|
|
use TestRoleSeeder; |
|
14
|
|
|
use TestUserNonCompositeSeeder; |
|
15
|
|
|
use TestUserSeeder; |
|
16
|
|
|
|
|
17
|
|
|
class CompositeKeyBaseUnit extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Setup the test environment. |
|
21
|
|
|
* |
|
22
|
|
|
* @throws Exception |
|
23
|
|
|
*/ |
|
24
|
|
|
protected function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
parent::setUp(); |
|
27
|
|
|
$this->loadMigrationsFrom(__DIR__.'/database/migrations'); |
|
28
|
|
|
|
|
29
|
|
|
$this->artisan('migrate', ['--database' => 'testing']); |
|
30
|
|
|
|
|
31
|
|
|
$this->seed(TestOrganizationSeeder::class); |
|
32
|
|
|
$this->seed(TestRoleSeeder::class); |
|
33
|
|
|
$this->seed(TestBinaryRoleSeeder::class); |
|
34
|
|
|
$this->seed(TestUserSeeder::class); |
|
35
|
|
|
$this->seed(TestUserNonCompositeSeeder::class); |
|
36
|
|
|
$this->seed(TestBinaryUserSeeder::class); |
|
37
|
|
|
|
|
38
|
|
|
if (env('DEBUG_QUERY_LOG', true)) { |
|
39
|
|
|
DB::listen( |
|
40
|
|
|
function (QueryExecuted $queryExecuted) { |
|
41
|
|
|
var_dump($queryExecuted->sql); |
|
|
|
|
|
|
42
|
|
|
var_dump($queryExecuted->bindings); |
|
43
|
|
|
} |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Define environment setup. |
|
50
|
|
|
* |
|
51
|
|
|
* @param Application $app |
|
52
|
|
|
*/ |
|
53
|
|
|
protected function getEnvironmentSetUp($app) |
|
54
|
|
|
{ |
|
55
|
|
|
$app['config']->set('database.default', 'testing'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
protected function loadMigrationsFrom($paths): void |
|
59
|
|
|
{ |
|
60
|
|
|
$paths = (is_array($paths)) ? $paths : [$paths]; |
|
61
|
|
|
$this->app->afterResolving('migrator', function ($migrator) use ($paths) { |
|
62
|
|
|
foreach ((array) $paths as $path) { |
|
63
|
|
|
$migrator->path($path); |
|
64
|
|
|
} |
|
65
|
|
|
}); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|