File tree Expand file tree Collapse file tree 5 files changed +53
-7
lines changed
Expand file tree Collapse file tree 5 files changed +53
-7
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,10 @@ public static function migrate(array $config = [])
4646 {
4747 $ migrator = new static ();
4848
49+ // Make sure that the connections are aliased, in case
50+ // the migrations invoke the table registry.
51+ $ migrator ->getFixtureManager ()->aliasConnections ();
52+
4953 $ migrator
5054 ->prepareConfig ($ config )
5155 ->dropTablesForMissingMigrations ()
@@ -129,4 +133,4 @@ protected function getFixtureManager(): FixtureManager
129133 {
130134 return $ this ->fixtureManager ;
131135 }
132- }
136+ }
Original file line number Diff line number Diff line change 1717class AppMigration extends AbstractMigration
1818{
1919 public function up ()
20- {}
20+ {
21+ $ this ->table ('articles ' )
22+ ->addPrimaryKey (['id ' ])
23+ ->addColumn ('title ' , 'string ' , [
24+ 'limit ' => 128 ,
25+ 'null ' => false ,
26+ ])
27+ ->addTimestamps ('created ' , 'modified ' )
28+ ->create ();
29+ }
2130
2231 public function down ()
2332 {}
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ /**
5+ * Licensed under The MIT License
6+ * For full copyright and license information, please see the LICENSE.txt
7+ * Redistributions of files must retain the above copyright notice.
8+ *
9+ * @copyright Copyright (c) 2020 Juan Pablo Ramirez and Nicolas Masson
10+ * @link https://webrider.de/
11+ * @since 1.0.0
12+ * @license http://www.opensource.org/licenses/mit-license.php MIT License
13+ */
14+ namespace TestApp \Model \Table ;
15+
16+ use Cake \ORM \Query ;
17+ use Cake \ORM \Table ;
18+
19+ class ArticlesTable extends Table
20+ {}
Original file line number Diff line number Diff line change 1515
1616
1717use Cake \Datasource \ConnectionManager ;
18+ use Cake \ORM \TableRegistry ;
1819use Cake \TestSuite \TestCase ;
1920use CakephpTestMigrator \Migrator ;
2021
@@ -64,4 +65,11 @@ public function testMigrate()
6465 $ this ->assertSame (['FooMigration ' ], $ fooPluginMigrations );
6566 $ this ->assertSame (['BarMigration ' ], $ barPluginMigrations );
6667 }
67- }
68+
69+ public function testTableRegistryConnectionName ()
70+ {
71+ $ Articles = TableRegistry::getTableLocator ()->get ('Articles ' );
72+ ConnectionManager::getConfigOrFail ('default ' );
73+ $ this ->assertSame ('test ' , $ Articles ->getConnection ()->configName ());
74+ }
75+ }
Original file line number Diff line number Diff line change 11<?php
22
33use Cake \Core \Configure ;
4+ use Cake \Datasource \ConnectionManager ;
45
56if (!defined ('DS ' )) {
67 define ('DS ' , DIRECTORY_SEPARATOR );
@@ -84,13 +85,17 @@ function loadPHPUnitAliases()
8485 ],
8586];
8687
87- \Cake \Datasource \ConnectionManager::setConfig ('test ' , $ dbConnection );
88+ ConnectionManager::setConfig ('test ' , $ dbConnection );
89+
90+ $ dbDefaultConnection = $ dbConnection ;
91+ $ dbDefaultConnection ['database ' ] = 'migrator ' ;
92+ ConnectionManager::setConfig ('default ' , $ dbConnection );
8893
8994$ dbConnection ['migrations ' ] = ['plugin ' => 'BarPlugin ' ];
90- \ Cake \ Datasource \ ConnectionManager::setConfig ('test_2 ' , $ dbConnection );
95+ ConnectionManager::setConfig ('test_2 ' , $ dbConnection );
9196
9297$ dbConnection ['migrations ' ] = true ;
93- \ Cake \ Datasource \ ConnectionManager::setConfig ('test_3 ' , $ dbConnection );
98+ ConnectionManager::setConfig ('test_3 ' , $ dbConnection );
9499
95100\Cake \Core \Plugin::load ('FooPlugin ' );
96- \Cake \Core \Plugin::load ('BarPlugin ' );
101+ \Cake \Core \Plugin::load ('BarPlugin ' );
You can’t perform that action at this time.
0 commit comments