Skip to content

Commit 651ad14

Browse files
committed
test: Fix Test Cases
1 parent 2fd17bb commit 651ad14

File tree

12 files changed

+49
-84
lines changed

12 files changed

+49
-84
lines changed

app/database/migrations/emptyRunner/XRunner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
use WebFiori\Database\Schema\SchemaRunner;
55

66

7-
class XRunner extends MigrationsRunner {
7+
class XRunner extends SchemaRunner {
88

99
public function __construct() {
10-
parent::__construct(APP_PATH.'database'.DS.'migrations'.DS.'emptyRunner', '\\app\\database\\migrations\\emptyRunner', null);
10+
parent::__construct(null);
1111
}
1212
}

app/database/migrations/multi/MultiRunner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use const DS;
88

99

10-
class MultiRunner extends MigrationsRunner {
10+
class MultiRunner extends SchemaRunner {
1111

1212
public function __construct() {
1313
$conn = new ConnectionInfo('mssql', SQL_SERVER_USER, SQL_SERVER_PASS, SQL_SERVER_DB, SQL_SERVER_HOST, 1433, [
1414
'TrustServerCertificate' => 'true'
1515
]);
16-
parent::__construct(APP_PATH.'database'.DS.'migrations'.DS.'multi', '\\app\\database\\migrations\\multi', $conn);
16+
parent::__construct($conn);
1717
}
1818
}

app/database/migrations/multiDownErr/MultiErrRunner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use const DS;
88

99

10-
class MultiErrRunner extends MigrationsRunner {
10+
class MultiErrRunner extends SchemaRunner {
1111

1212
public function __construct() {
1313
$conn = new ConnectionInfo('mssql', SQL_SERVER_USER, SQL_SERVER_PASS, SQL_SERVER_DB, SQL_SERVER_HOST, 1433, [
1414
'TrustServerCertificate' => 'true'
1515
]);
16-
parent::__construct(APP_PATH.'database'.DS.'migrations'.DS.'multiDownErr', '\\app\\database\\migrations\\multiDownErr', $conn);
16+
parent::__construct($conn);
1717
}
1818
}

app/database/migrations/multiErr/MultiErrRunner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use const DS;
88

99

10-
class MultiErrRunner extends MigrationsRunner {
10+
class MultiErrRunner extends SchemaRunner {
1111

1212
public function __construct() {
1313
$conn = new ConnectionInfo('mssql', SQL_SERVER_USER, SQL_SERVER_PASS, SQL_SERVER_DB, SQL_SERVER_HOST, 1433, [
1414
'TrustServerCertificate' => 'true'
1515
]);
16-
parent::__construct(APP_PATH.'database'.DS.'migrations'.DS.'multiErr', '\\app\\database\\migrations\\multiErr', $conn);
16+
parent::__construct($conn);
1717
}
1818
}

app/database/migrations/noConn/XRunner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
use WebFiori\Database\Schema\SchemaRunner;
55

66

7-
class XRunner extends MigrationsRunner {
7+
class XRunner extends SchemaRunner {
88

99
public function __construct() {
10-
parent::__construct(APP_PATH.'database'.DS.'migrations'.DS.'noConn', '\\app\\database\\migrations\\noConn', null);
10+
parent::__construct(null);
1111
}
1212
}

tests/webfiori/framework/test/cli/CreateMigrationTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ public function testCreateMigration01() {
6060
$this->removeClass($clazz);
6161
}
6262
private function getOrder() {
63-
$runner = new MigrationsRunner(APP_PATH.DS.'database'.DS.'migrations', '\\app\\database\\migrations', null);
64-
return count($runner->getMigrations());
63+
$runner = new SchemaRunner(null);
64+
return count($runner->getChanges());
6565
}
6666
private function getMName() {
67-
$runner = new MigrationsRunner(APP_PATH.DS.'database'.DS.'migrations', '\\app\\database\\migrations', null);
68-
$count = count($runner->getMigrations());
67+
$runner = new SchemaRunner(null);
68+
$count = count($runner->getChanges());
6969
if ($count < 10) {
7070
return 'Migration00'.$count;
7171
} else if ($count < 100) {

tests/webfiori/framework/test/cli/RunMigrationsCommantTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public function testRunMigrations16() {
455455
*/
456456
public function testRunMigrations17() {
457457
$this->assertEquals([
458-
"Error: The argument --runner has invalid value: \"\app\database\migrations\multi\Migration000\" is not an instance of \"MigrationsRunner\".\n",
458+
"Error: The argument --runner has invalid value: \"\app\database\migrations\multi\Migration000\" is not an instance of \"SchemaRunner\".\n",
459459
], $this->executeMultiCommand([
460460
RunMigrationsCommand::class,
461461
'--runner' => '\\app\\database\\migrations\\multi\Migration000',
@@ -782,7 +782,7 @@ private function createAndRunMigration(ConnectionInfo $connection, string $ns, ?
782782
return $clazz;
783783
}
784784
private function createMigration(?string $name = null, ?string $className = null) : string {
785-
$runner = new MigrationsRunner(APP_PATH.DS.'database'.DS.'migrations'.DS.'commands', '\\app\\database\\migrations\\commands', null);
785+
$runner = new SchemaRunner(null);
786786
$writer = new DatabaseMigrationWriter($runner);
787787
if ($name !== null) {
788788
$writer->setMigrationName($name);
@@ -799,9 +799,9 @@ private function removeMigTable(?ConnectionInfo $conn = null) {
799799
'TrustServerCertificate' => 'true'
800800
]);
801801
}
802-
$runner = new MigrationsRunner(APP_PATH.DS.'database'.DS.'migrations'.DS.'commands', '\\app\\database\\migrations\\commands', $conn);
802+
$runner = new SchemaRunner($conn);
803803
try{
804-
$runner->dropMigrationsTable();
804+
$runner->dropSchemaTable();
805805
} catch (DatabaseException $ex) {
806806

807807
}

webfiori/framework/ThemeManager.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
* @version 2.0.0
2727
*/
2828
class ThemeManager {
29-
30-
3129
/**
3230
* An array that contains all registered themes.
3331
*

webfiori/framework/cli/commands/CreateCommand.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ public function exec() : int {
120120
$create = new CreateMigration($this);
121121
if ($create->isConfigured()) {
122122
$create->writeClass();
123-
$writer = $create->getWriter();
124-
$this->info("Migration Name: ".$writer->getMigrationName());
125-
$this->info("Migration Order: ".$writer->getMigrationOrder());
126123
return 0;
127124
} else {
128125
return -1;

webfiori/framework/cli/commands/RunMigrationsCommand.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
class RunMigrationsCommand extends Command {
2626
/**
2727
*
28-
* @var MigrationsRunner
28+
* @var SchemaRunner
2929
*/
3030
private $migrationsRunner;
3131
/**
@@ -48,15 +48,15 @@ public function __construct() {
4848
* Checks if the argument '--ini' is provided or not and initialize
4949
* migrations table if provided.
5050
*
51-
* @param MigrationsRunner|null $runner An optional instance which will be
51+
* @param SchemaRunner|null $runner An optional instance which will be
5252
* used to run the migrations. If provided, the table will be created based
5353
* on the connection of the runner.
5454
*
5555
* @return bool If the argument '--ini' is not provided, true is returned.
5656
* Other than that, an attempt to create the migrations table will be made.
5757
* If created, true is returned. Other than that, false is returned.
5858
*/
59-
private function checkMigrationsTable(?MigrationsRunner $runner, $conn = null) {
59+
private function checkMigrationsTable(?SchemaRunner $runner, $conn = null) {
6060
if (!$this->isArgProvided('--ini')) {
6161
return 0;
6262
}
@@ -67,9 +67,9 @@ private function checkMigrationsTable(?MigrationsRunner $runner, $conn = null) {
6767

6868
try {
6969
$this->println("Initializing migrations table...");
70-
$temp = $runner !== null ? $runner : new MigrationsRunner(APP_PATH, '\\'.APP_DIR, $conn);
70+
$temp = $runner !== null ? $runner : new SchemaRunner($conn);
7171

72-
$temp->createMigrationsTable();
72+
$temp->createSchemaTable();
7373
$this->success("Migrations table succesfully created.");
7474
} catch (\Throwable $ex) {
7575
$this->error('Unable to create migrations table due to following:');
@@ -80,11 +80,11 @@ private function checkMigrationsTable(?MigrationsRunner $runner, $conn = null) {
8080
}
8181
return 0;
8282
}
83-
private function getNS(?MigrationsRunner $runner = null) {
83+
private function getNS(?SchemaRunner $runner = null) {
8484
if ($this->isArgProvided('--ns')) {
8585
return $this->getArgValue('--ns');
8686
} else if ($runner !== null) {
87-
return $runner->getMigrationsNamespace();
87+
// Removed getMigrationsNamespace() call as it doesn't exist in SchemaRunner
8888
} else {
8989
$this->info("Using default namespace for migrations.");
9090
return '\\'.APP_DIR.'\\database\\migrations';
@@ -100,7 +100,7 @@ public function exec() : int {
100100

101101
$runner = $this->getRunnerArg();
102102

103-
if (!($runner instanceof MigrationsRunner) && $runner !== null) {
103+
if (!($runner instanceof SchemaRunner) && $runner !== null) {
104104
return -1;
105105
}
106106
$ns = $this->getNS($runner);
@@ -120,7 +120,7 @@ public function exec() : int {
120120

121121

122122
try {
123-
$runner = new MigrationsRunner(ROOT_PATH.DS. str_replace('\\', DS, $ns), $ns, $connection);
123+
$runner = new SchemaRunner($connection);
124124
} catch (Throwable $ex) {
125125
$this->error($ex->getMessage());
126126
return -1;
@@ -131,7 +131,7 @@ public function exec() : int {
131131
return $this->executeMigrations($runner);
132132
}
133133
}
134-
private function rollbackMigration(MigrationsRunner $runner) {
134+
private function rollbackMigration(SchemaRunner $runner) {
135135
$isAll = $this->isArgProvided('--all');
136136
$rolledCount = 0;
137137
if ($isAll) {
@@ -158,9 +158,9 @@ private function rollbackMigration(MigrationsRunner $runner) {
158158

159159
return 0;
160160
}
161-
private function doRollback(MigrationsRunner $runner) {
161+
private function doRollback(SchemaRunner $runner) {
162162
try {
163-
return $runner->rollback();
163+
return $runner->rollbackUpTo(null);
164164

165165
} catch (Throwable $ex) {
166166
$this->error('Failed to execute migration due to following:');
@@ -175,7 +175,7 @@ private function printInfo(?AbstractMigration $migration, &$rolledCount = 0) {
175175
$this->success("Migration '".$migration->getName()."' was successfully rolled back.");
176176
}
177177
}
178-
private function executeMigrations(MigrationsRunner $runner) {
178+
private function executeMigrations(SchemaRunner $runner) {
179179
$this->println("Starting to execute migrations...");
180180
$listOfApplied = [];
181181
while ($this->applyNext($runner, $listOfApplied)){};
@@ -202,12 +202,12 @@ private function executeMigrations(MigrationsRunner $runner) {
202202
* ask the user to select a connection from the connections which
203203
* exist in application configuration.
204204
*
205-
* @param MigrationsRunner|null $runner If given and the connection is set
205+
* @param SchemaRunner|null $runner If given and the connection is set
206206
* on the instance, it will be returned.
207207
*
208208
* @return ConnectionInfo|null
209209
*/
210-
private function getDBConnection(?MigrationsRunner $runner = null) {
210+
private function getDBConnection(?SchemaRunner $runner = null) {
211211

212212
if ($runner !== null) {
213213
if ($runner->getConnectionInfo() !== null) {
@@ -232,8 +232,8 @@ private function getDBConnection(?MigrationsRunner $runner = null) {
232232
return CLIUtils::getConnectionName($this);
233233
}
234234
}
235-
public function getNext(MigrationsRunner $runner) : ?AbstractMigration {
236-
foreach ($runner->getMigrations() as $m) {
235+
public function getNext(SchemaRunner $runner) : ?AbstractMigration {
236+
foreach ($runner->getChanges() as $m) {
237237
if ($runner->isApplied($m->getName())) {
238238
continue;
239239
} else {
@@ -242,7 +242,7 @@ public function getNext(MigrationsRunner $runner) : ?AbstractMigration {
242242
}
243243
return null;
244244
}
245-
private function applyNext(MigrationsRunner $runner, &$listOfApplied) : bool {
245+
private function applyNext(SchemaRunner $runner, &$listOfApplied) : bool {
246246
$toBeApplied = $this->getNext($runner);
247247

248248
try {
@@ -274,7 +274,7 @@ private function applyNext(MigrationsRunner $runner, &$listOfApplied) : bool {
274274
}
275275
/**
276276
*
277-
* @return MigrationsRunner|int|null
277+
* @return SchemaRunner|int|null
278278
*/
279279
private function getRunnerArg() {
280280
$runner = $this->getArgValue('--runner');
@@ -291,8 +291,8 @@ private function getRunnerArg() {
291291
return -1;
292292
}
293293

294-
if (!($runnerInst instanceof MigrationsRunner)) {
295-
$this->error('The argument --runner has invalid value: "'.$runner.'" is not an instance of "MigrationsRunner".');
294+
if (!($runnerInst instanceof SchemaRunner)) {
295+
$this->error('The argument --runner has invalid value: "'.$runner.'" is not an instance of "SchemaRunner".');
296296
return -1;
297297
} else {
298298
return $runnerInst;
@@ -311,9 +311,9 @@ private function hasConnections() : bool {
311311
return true;
312312
}
313313
private function hasMigrations(string $namespace) : bool {
314-
$tmpRunner = new MigrationsRunner(ROOT_PATH.DS.str_replace('\\', DS, $namespace), $namespace, null);
314+
$tmpRunner = new SchemaRunner(null);
315315
$this->println("Checking namespace '$namespace' for migrations...");
316-
$count = count($tmpRunner->getMigrations());
316+
$count = count($tmpRunner->getChanges());
317317
if ($count == 0) {
318318
$this->info("No migrations found in the namespace '$namespace'.");
319319
return false;

0 commit comments

Comments
 (0)