Skip to content

Commit 3b0ad16

Browse files
lonnieezellMGatner
authored andcommitted
Fixing tests and stuff
1 parent 1d65f3a commit 3b0ad16

6 files changed

Lines changed: 38 additions & 32 deletions

File tree

system/Commands/Database/Migrate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ public function run(array $params = [])
105105
{
106106
$runner = Services::migrations();
107107
$runner->clearCliMessages();
108-
109-
CLI::write(lang('Migrations.progress'), 'yellow');
108+
109+
CLI::write(lang('Migrations.latest'), 'yellow');
110110

111111
$namespace = $params['-n'] ?? CLI::getOption('n');
112112
$group = $params['-g'] ?? CLI::getOption('g');
@@ -124,7 +124,7 @@ public function run(array $params = [])
124124
$runner->setNamespace($namespace);
125125
}
126126

127-
if (! $runner->progress($group))
127+
if (! $runner->latest($group))
128128
{
129129
CLI::write(lang('Migrations.generalFault'), 'red');
130130
}

system/Database/MigrationRunner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function __construct(BaseConfig $config, $db = null)
168168
*
169169
* @param string|null $group
170170
*/
171-
public function progress(string $group = null)
171+
public function latest(string $group = null)
172172
{
173173
if (! $this->enabled)
174174
{

system/Language/en/Migrations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
'writeError' => 'Error trying to create file.',
3939
'migNumberError' => 'Migration number must be three digits, and there must not be any gaps in the sequence.',
4040

41-
'progress' => 'Running all new migrations...',
41+
'latest' => 'Running all new migrations...',
4242
'generalFault' => 'Migration failed!',
4343
'migInvalidVersion' => 'Invalid version number provided.',
4444
'toVersionPH' => 'Migrating to version %s...',

system/Test/CIDatabaseTestCase.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -177,23 +177,23 @@ protected function setUp()
177177
// Delete all of the tables to ensure we're at a clean start.
178178
$tables = $this->db->listTables();
179179

180-
// if (is_array($tables))
181-
// {
182-
// $forge = Database::forge('tests');
183-
//d($tables);
184-
// foreach ($tables as $table)
185-
// {
186-
// if ($table === $this->db->DBPrefix . 'migrations')
187-
// {
188-
// continue;
189-
// }
190-
//
191-
// $forge->dropTable($table, true);
192-
// }
193-
// }
180+
if (is_array($tables))
181+
{
182+
$forge = Database::forge('tests');
183+
184+
foreach ($tables as $table)
185+
{
186+
if ($table === $this->db->DBPrefix . 'migrations')
187+
{
188+
continue;
189+
}
190+
191+
$forge->dropTable($table, true);
192+
}
193+
}
194194

195195
$this->migrations->regress(0, 'tests');
196-
$this->migrations->progress('tests');
196+
$this->migrations->latest('tests');
197197
}
198198

199199
if (! empty($this->seed))

tests/system/Database/Migrations/MigrationRunnerTest.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ public function testFindMigrationsSuccessTimestamp()
193193
'version' => '2018-01-24-102302',
194194
'class' => 'Tests\Support\MigrationTestMigrations\Database\Migrations\Migration_another_migration',
195195
'namespace' => 'Tests\Support\MigrationTestMigrations',
196+
'uid' => '2018-01-24-102302Tests\Support\MigrationTestMigrations\Database\Migrations\Migration_another_migration',
196197
];
197198
$mig1->uid = $runner->getObjectUid($mig1);
198199

@@ -215,7 +216,7 @@ public function testMigrationThrowsDisabledException()
215216

216217
$runner->setSilent(false);
217218

218-
$runner = $runner->setPath($this->start);
219+
$runner = $runner->setNamespace('Tests\Support\MigrationTestMigrations');
219220

220221
vfsStream::copyFromFileSystem(
221222
TESTPATH . '_support/MigrationTestMigrations/Database/Migrations',
@@ -225,7 +226,7 @@ public function testMigrationThrowsDisabledException()
225226
$this->expectException(ConfigException::class);
226227
$this->expectExceptionMessage('Migrations have been loaded but are disabled or setup incorrectly.');
227228

228-
$runner->progress();
229+
$runner->latest();
229230
}
230231

231232
public function testVersionReturnsUpDownSuccess()
@@ -240,7 +241,7 @@ public function testVersionReturnsUpDownSuccess()
240241

241242
$runner = $runner->setNamespace('Tests\Support\MigrationTestMigrations');
242243

243-
$runner->progress();
244+
$runner->latest();
244245
$version = $runner->getBatchEnd($runner->getLastBatch());
245246

246247
$this->assertEquals('2018-01-24-102302', $version);
@@ -262,7 +263,7 @@ public function testProgressSuccess()
262263

263264
$runner = $runner->setNamespace('Tests\Support\MigrationTestMigrations');
264265

265-
$runner->progress();
266+
$runner->latest();
266267
$version = $runner->getBatchEnd($runner->getLastBatch());
267268

268269
$this->assertEquals('2018-01-24-102302', $version);
@@ -280,7 +281,7 @@ public function testRegressSuccess()
280281
$runner->setSilent(false);
281282

282283
$runner = $runner->setNamespace('Tests\Support\MigrationTestMigrations');
283-
$runner->progress();
284+
$runner->latest();
284285

285286
$runner->regress();
286287
$version = $runner->getBatchEnd($runner->getLastBatch());
@@ -302,16 +303,17 @@ public function testHistoryRecordsBatches()
302303

303304
$runner = $runner->setNamespace('Tests\Support\MigrationTestMigrations');
304305

305-
$runner->progress();
306+
$runner->latest();
306307
$version = $runner->getBatchEnd($runner->getLastBatch());
307308

308-
$this->assertEquals('2018-01-24-102301', $version);
309+
$this->assertEquals('2018-01-24-102302', $version);
309310

310311
$history = $runner->getHistory('tests');
312+
311313
$this->assertEquals(1, $history[0]->batch);
312314

313315
$this->assertEquals(1, $history[0]->batch);
314-
$this->assertEquals(2, $history[1]->batch);
316+
$this->assertEquals(1, $history[1]->batch);
315317

316318
$this->seeInDatabase('migrations', [
317319
'batch' => 1,
@@ -328,7 +330,7 @@ public function testGetBatchVersions()
328330

329331
$runner = $runner->setNamespace('Tests\Support\MigrationTestMigrations');
330332

331-
$runner->progress();
333+
$runner->latest();
332334

333335
$this->assertEquals('2018-01-24-102301', $runner->getBatchStart(1));
334336
$this->assertEquals('2018-01-24-102302', $runner->getBatchEnd(1));

user_guide_src/source/dbmgmt/migration.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ need to be run against the production machines next time you deploy.
1010

1111
The database table **migration** tracks which migrations have already been
1212
run so all you have to do is make sure your migrations are in place and
13-
call ``$migration->progress()`` to bring the database up to the most recent
13+
call ``$migration->latest()`` to bring the database up to the most recent
1414
state. You can also use ``$migration->setNamespace(null)->progess()`` to
1515
include migrations from all namespaces.
1616

@@ -199,6 +199,10 @@ This example will migrate Blog namespace with any new migrations on the test dat
199199

200200
> php spark migrate -g test -n Blog
201201

202+
When using the `-all` option, it will scan through all namespaces attempting to find any migrations that have
203+
not been ran. These will all be collected and then sorted as a group by date created. This should help
204+
to minimize any potential conflicts between the main application and any modules.
205+
202206
**rollback**
203207

204208
Rolls back all migrations, taking the database group to a blank slate, effectively migration 0::
@@ -275,15 +279,15 @@ Class Reference
275279

276280
An array of migration filenames are returned that are found in the **path** property.
277281

278-
.. php:method:: progress($group)
282+
.. php:method:: latest($group)
279283
280284
:param mixed $group: database group name, if null default database group will be used.
281285
:returns: TRUE on success, FALSE on failure
282286
:rtype: bool
283287

284288
This locates migrations for a namespace (or all namespaces), determines which migrations
285289
have not yet been run, and runs them in order of their version (namespaces intermingled).
286-
290+
287291
.. php:method:: regress($batch, $group)
288292
289293
:param mixed $batch: previous batch to migrate down to; 1+ specifies the batch, 0 reverts all, negative refers to the relative batch (e.g. -3 means "three batches back")

0 commit comments

Comments
 (0)