Skip to content

Commit

Permalink
Merge branch 'next' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloelcolombiano committed Dec 1, 2020
2 parents c5f0377 + 116e89f commit dfe8d18
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
11 changes: 7 additions & 4 deletions src/ConfigReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,26 @@ public function readMigrationsInDatasources(FixtureManager $fixtureManager)
$this->config = array_merge($this->config, $config);
}
}
if (empty($this->config)) {
$this->config = [['connection' => 'test']];
}
return $this;
}

/**
* @param array $config
* @return $this
*/
public function loadConfig(array $config = [])
public function prepareConfig(array $config = [])
{
$config = array_merge(Configure::read('TestFixtureMigrations', []), $config);
if (!empty($config)) {
$this->normalizeArray($config);
$this->config = array_merge($this->config, $config);
}
foreach ($this->config as $k => $config) {
$this->config[$k]['connection'] = $this->config[$k]['connection'] ?? 'test';
}
if (empty($this->config)) {
$this->config = [['connection' => 'test']];
}
return $this;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Migrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function migrate(array $config = []): void
$migrator = new static();

$migrator
->loadConfig($config)
->prepareConfig($config)
->dropTablesForMissingMigrations()
->runAllMigrations();
}
Expand Down Expand Up @@ -100,9 +100,9 @@ protected function isMigrationMissing(Migrations $migrations): bool
* @param array $config
* @return $this
*/
protected function loadConfig(array $config)
protected function prepareConfig(array $config)
{
$this->getConfigReader()->loadConfig($config);
$this->getConfigReader()->prepareConfig($config);
return $this;
}

Expand Down
26 changes: 18 additions & 8 deletions tests/TestCase/ConfigReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,37 @@ public function tearDown(): void
public function testSetConfigFromInjection()
{
$config = [
'connection' => 'Foo',
'plugin' => 'Bar'
['connection' => 'Foo', 'plugin' => 'Bar',],
['plugin' => 'Bar',]
];

$this->ConfigReader->loadConfig($config);
$expect = [
['connection' => 'Foo', 'plugin' => 'Bar',],
['plugin' => 'Bar', 'connection' => 'test',]
];

$this->ConfigReader->prepareConfig($config);

$this->assertSame([$config], $this->ConfigReader->getConfig());
$this->assertSame($expect, $this->ConfigReader->getConfig());
}

public function testSetConfigWithConfigure()
{
$config = [
'connection' => 'FooTestSetConfigWithConfigure',
'source' => 'FooTestSetConfigWithConfigure',
'plugin' => 'BarTestSetConfigWithConfigure'
];
$expect = [[
'source' => 'FooTestSetConfigWithConfigure',
'plugin' => 'BarTestSetConfigWithConfigure',
'connection' => 'test',
]];

Configure::write('TestFixtureMigrations', $config);

$this->ConfigReader->loadConfig();
$this->ConfigReader->prepareConfig();

$this->assertSame([$config], $this->ConfigReader->getConfig());
$this->assertSame($expect, $this->ConfigReader->getConfig());

Configure::delete('TestFixtureMigrations');
}
Expand All @@ -78,7 +88,7 @@ public function testSetConfigWithConfigureAndInjection()

Configure::write('TestFixtureMigrations', $config2);

$this->ConfigReader->loadConfig($config1);
$this->ConfigReader->prepareConfig($config1);
$this->assertSame([$config1], $this->ConfigReader->getConfig());

Configure::delete('TestFixtureMigrations');
Expand Down

0 comments on commit dfe8d18

Please sign in to comment.