forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
113 lines (92 loc) · 3.89 KB
/
bootstrap.php
File metadata and controls
113 lines (92 loc) · 3.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/**
* Test harness bootstrap that sets up initial defines and builds up the initial database schema
*/
// Bring in our standard bootstrap
include_once __DIR__ . '/../bootstrap/autoload.php';
require_once __DIR__ . '/../bootstrap/app.php';
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Support\Facades\Artisan;
use ProcessMaker\Models\ScriptExecutor;
// Bootstrap laravel
app()->make(Kernel::class)->bootstrap();
// Cache with new config so we don't overwrite our local development database
Artisan::call('config:cache', ['--env' => 'testing']);
//Ensure storage directory is linked
Artisan::call('storage:link', []);
if (env('RUN_MSSQL_TESTS')) {
// Setup our testexternal database
config(['database.connections.testexternal' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
// We set database to null to ensure we can create the testexternal database
'database' => null,
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'prefix' => '',
'strict' => true,
'engine' => null,
]]);
// First create the test external mysql database as well as our test database
DB::connection('testexternal')->unprepared('CREATE DATABASE IF NOT EXISTS testexternal');
// First create the test external mysql database as well as our test database
DB::connection('testexternal')->unprepared('CREATE DATABASE IF NOT EXISTS userexternal');
// Now set the database name properly
config(['database.connections.testexternal.database' => env('DB_TESTEXTERNAL_DB', 'testexternal')]);
DB::connection('testexternal')->reconnect();
// Now, drop all test tables and repopulate with schema
Schema::connection('testexternal')->dropIfExists('test');
Schema::connection('testexternal')->create('test', function ($table) {
$table->increments('id');
$table->string('value');
});
DB::connection('testexternal')->table('test')->insert([
'value' => 'testvalue',
]);
// Only do if we are supporting MSSql tests
config(['database.connections.mssql' => [
'driver' => 'sqlsrv',
'host' => env('MSSQL_HOST', '127.0.0.1'),
'database' => null,
'username' => env('MSSQL_USERNAME', 'root'),
'password' => env('MSSQL_PASSWORD', ''),
]]);
$mssqlDBName = env('MSSQL_DATABASE', 'testexternal');
// First create the test external mysql database as well as our test database
DB::connection('mssql')->unprepared("if db_id('" . $mssqlDBName . "') is null\nCREATE DATABASE " . $mssqlDBName);
// Now set the database name properly
config(['database.connections.mssql.database' => $mssqlDBName]);
DB::connection('mssql')->reconnect();
Schema::connection('mssql')->dropIfExists('test');
Schema::connection('mssql')->create('test', function ($table) {
$table->increments('id');
$table->string('value');
});
DB::connection('mssql')->table('test')->insert([
'value' => 'testvalue',
]);
}
// setup parallel test databases
if (env('TEST_TOKEN')) {
$database = 'test_' . env('TEST_TOKEN');
$_ENV['DB_DATABASE'] = $database;
$_ENV['DATA_DB_DATABASE'] = $database;
} elseif (env('POPULATE_DATABASE')) {
Artisan::call('db:wipe', ['--database' => \DB::connection()->getName()]);
Artisan::call('migrate:fresh', []);
Artisan::call('db:seed', ['--class' => 'AnonymousUserSeeder']);
\Illuminate\Foundation\Testing\RefreshDatabaseState::$migrated = true;
ScriptExecutor::firstOrCreate(
['language' => 'php'],
['title' => 'Test Executor']
);
ScriptExecutor::firstOrCreate(
['language' => 'lua'],
['title' => 'Test Executor']
);
if (env('PARALLEL_TEST_PROCESSES')) {
Artisan::call('processmaker:create-test-dbs');
}
}