|
6 | 6 | class TestsBase extends TestCase
|
7 | 7 | {
|
8 | 8 | protected $queriesCount;
|
| 9 | + protected static $db2Setup = false; |
9 | 10 |
|
10 | 11 | const DB_NAME = 'translatable_test';
|
| 12 | + const DB_NAME2 = 'translatable_test2'; |
11 | 13 | const DB_USERNAME = 'homestead';
|
12 | 14 | const DB_PASSWORD = 'secret';
|
13 | 15 |
|
14 | 16 | public function setUp()
|
15 | 17 | {
|
16 |
| - $this->makeSureDatabaseExists(); |
| 18 | + $this->makeSureDatabaseExists(static::DB_NAME); |
| 19 | + |
| 20 | + if (! static::$db2Setup) { |
| 21 | + $this->makeSureDatabaseExists(static::DB_NAME2); |
| 22 | + } |
17 | 23 |
|
18 | 24 | parent::setUp();
|
19 | 25 |
|
20 |
| - $this->makeSureSchemaIsCreated(); |
| 26 | + if (! static::$db2Setup) { |
| 27 | + $this->makeSureSchemaIsCreated('mysql2'); |
| 28 | + $this->truncateAllTablesButMigrations(static::DB_NAME2); |
| 29 | + static::$db2Setup = true; |
| 30 | + } |
| 31 | + |
| 32 | + $this->makeSureSchemaIsCreated('mysql'); |
21 | 33 | $this->enableQueryCounter();
|
22 | 34 | $this->refreshSeedData();
|
23 | 35 | }
|
24 | 36 |
|
25 | 37 | private function refreshSeedData()
|
26 | 38 | {
|
27 |
| - $this->truncateAllTablesButMigrations(); |
| 39 | + $this->truncateAllTablesButMigrations(static::DB_NAME); |
28 | 40 | $seeder = new AddFreshSeeds;
|
29 | 41 | $seeder->run();
|
30 | 42 | }
|
31 | 43 |
|
32 |
| - private function makeSureDatabaseExists() |
| 44 | + private function makeSureDatabaseExists($dbName) |
33 | 45 | {
|
34 |
| - $this->runQuery('CREATE DATABASE IF NOT EXISTS '.static::DB_NAME); |
| 46 | + $this->runQuery('CREATE DATABASE IF NOT EXISTS '.$dbName); |
35 | 47 | }
|
36 | 48 |
|
37 |
| - private function makeSureSchemaIsCreated() |
| 49 | + private function makeSureSchemaIsCreated($dbConnectionName) |
38 | 50 | {
|
39 | 51 | $migrationsPath = '../../../../tests/migrations';
|
40 | 52 | $artisan = $this->app->make('Illuminate\Contracts\Console\Kernel');
|
41 | 53 |
|
42 | 54 | // Makes sure the migrations table is created
|
43 | 55 | $artisan->call('migrate', [
|
44 |
| - '--database' => 'mysql', |
| 56 | + '--database' => $dbConnectionName, |
45 | 57 | '--path' => $migrationsPath,
|
46 | 58 | ]);
|
47 | 59 | }
|
48 | 60 |
|
49 |
| - private function truncateAllTablesButMigrations() |
| 61 | + private function truncateAllTablesButMigrations($dbName) |
50 | 62 | {
|
51 | 63 | $db = $this->app->make('db');
|
52 | 64 | $db->statement('SET FOREIGN_KEY_CHECKS=0;');
|
53 | 65 |
|
54 | 66 | foreach ($tables = $db->select('SHOW TABLES') as $table) {
|
55 |
| - $table = $table->{'Tables_in_'.static::DB_NAME}; |
| 67 | + $table = $table->{'Tables_in_'.$dbName}; |
56 | 68 | if ($table != 'migrations') {
|
57 | 69 | $db->table($table)->truncate();
|
58 | 70 | }
|
@@ -101,6 +113,16 @@ protected function getEnvironmentSetUp($app)
|
101 | 113 | 'collation' => 'utf8_unicode_ci',
|
102 | 114 | 'strict' => false,
|
103 | 115 | ]);
|
| 116 | + $app['config']->set('database.connections.mysql2', [ |
| 117 | + 'driver' => 'mysql', |
| 118 | + 'host' => '127.0.0.1', |
| 119 | + 'database' => static::DB_NAME2, |
| 120 | + 'username' => static::DB_USERNAME, |
| 121 | + 'password' => static::DB_PASSWORD, |
| 122 | + 'charset' => 'utf8', |
| 123 | + 'collation' => 'utf8_unicode_ci', |
| 124 | + 'strict' => false, |
| 125 | + ]); |
104 | 126 | $app['config']->set('translatable.locales', ['el', 'en', 'fr', 'de', 'id']);
|
105 | 127 | }
|
106 | 128 |
|
|
0 commit comments