Skip to content

Commit 55a472f

Browse files
committed
Update RunMigrationsCommantTest.php
1 parent 65821fb commit 55a472f

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testRunMigrations01() {
3535

3636
$this->assertEquals([
3737
"Checking namespace '\app\database\migrations' for migrations...\n",
38-
"Found 1 migration(s).\n",
38+
"Found 1 migration(s) in the namespace '\app\database\migrations'.\n",
3939
"Info: No connections were found in application configuration.\n",
4040
], $this->executeMultiCommand([
4141
RunMigrationsCommand::class,
@@ -57,43 +57,44 @@ public function testRunMigrations02() {
5757
App::getConfig()->addOrUpdateDBConnection($conn);
5858
$this->assertEquals([
5959
"Checking namespace '\app\database\migrations' for migrations...\n",
60-
"Found 1 migration(s).\n",
60+
"Found 1 migration(s) in the namespace '\app\database\migrations'.\n",
6161
"Error: No connection was found which has the name 'ABC'.\n",
6262
], $this->executeMultiCommand([
6363
RunMigrationsCommand::class,
6464
'--ns' => '\\app\\database\\migrations',
6565
'--connection' => 'ABC'
6666
]));
6767
$this->removeClass($clazz);
68-
$this->assertEquals(-2, $this->getExitCode());
68+
$this->assertEquals(0, $this->getExitCode());
6969
App::getConfig()->removeAllDBConnections();
7070
}
7171
/**
7272
* @test
7373
*/
7474
public function testRunMigrations03() {
75-
$conn = new ConnectionInfo('mysql', 'root', 'x123456', 'testing_db');
75+
$conn = new ConnectionInfo('mssql', SQL_SERVER_USER, 'x123456', SQL_SERVER_DB);
7676
$conn->setName('default-conn');
77-
$clazz = $this->createMigration();
77+
$clazz = $this->createMigration('PO', 'MyPOMigration');
7878
$this->assertTrue(class_exists($clazz));
7979
App::getConfig()->addOrUpdateDBConnection($conn);
8080
$this->assertEquals([
8181
"Checking namespace '\app\database\migrations' for migrations...\n",
82-
"Found 1 migration(s).\n",
82+
"Found 1 migration(s) in the namespace '\app\database\migrations'.\n",
8383
"Select database connection:\n",
8484
"0: default-conn <--\n",
8585
"Error: Invalid answer.\n",
8686
"Select database connection:\n",
8787
"0: default-conn <--\n",
88-
"Error: Unable to connect to database: 2002 - No such file or directory\n",
88+
"Error: Unable to connect to database: 2 - [Microsoft][ODBC Driver 18 for SQL Server]A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.\n",
8989
], $this->executeMultiCommand([
9090
RunMigrationsCommand::class,
9191
'--ns' => '\\app\\database\\migrations',
9292
], [
9393
'7',
9494
''
9595
]));
96-
$this->assertEquals(-1, $this->getExitCode());
96+
$this->assertEquals(0, $this->getExitCode());
97+
$this->removeClass($clazz);
9798
App::getConfig()->removeAllDBConnections();
9899
}
99100
/**
@@ -125,7 +126,8 @@ public function testRunMigrations05() {
125126
*/
126127
public function testRunMigrations06() {
127128
$this->assertEquals([
128-
"Info: No migrations where found in the namespace '\app\database\migrations\\emptyRunner'.\n",
129+
"Checking namespace '\app\database\migrations\\emptyRunner' for migrations...\n",
130+
"Info: No migrations found in the namespace '\app\database\migrations\\emptyRunner'.\n",
129131
], $this->executeMultiCommand([
130132
RunMigrationsCommand::class,
131133
'--runner' => '\\app\\database\\migrations\\emptyRunner\XRunner',
@@ -140,12 +142,12 @@ public function testRunMigrations07() {
140142
'TrustServerCertificate' => 'true'
141143
]);
142144
$conn->setName('default-conn');
143-
$clazz = $this->createMigration();
145+
$clazz = $this->createMigration('Cool', 'CoolOne');
144146
$this->assertTrue(class_exists($clazz));
145147
App::getConfig()->addOrUpdateDBConnection($conn);
146148
$this->assertEquals([
147149
"Checking namespace '\app\database\migrations' for migrations...\n",
148-
"Found 1 migration(s).\n",
150+
"Info: Found 2 migration(s) in the namespace '\app\database\migrations'.\n",
149151
"Select database connection:\n",
150152
"0: default-conn <--\n",
151153
"Error: Invalid answer.\n",
@@ -160,6 +162,7 @@ public function testRunMigrations07() {
160162
''
161163
]));
162164
$this->assertEquals(-1, $this->getExitCode());
165+
$this->removeClass($clazz);
163166
App::getConfig()->removeAllDBConnections();
164167
}
165168
/**
@@ -170,7 +173,7 @@ public function testRunMigrations08() {
170173
'TrustServerCertificate' => 'true'
171174
]);
172175
$conn->setName('default-conn');
173-
$clazz = $this->createMigration();
176+
$clazz = $this->createMigration('Super', 'SuperMigration');
174177
$this->assertTrue(class_exists($clazz));
175178
App::getConfig()->addOrUpdateDBConnection($conn);
176179
$this->assertEquals([
@@ -365,6 +368,7 @@ public function testRunMigrations15() {
365368
$this->assertEquals([
366369
"Initializing migrations table...\n",
367370
"Success: Migrations table succesfully created.\n",
371+
"Info: Found 3 migration(s) in the namespace '\app\database\migrations\multi'.\n",
368372
"Executing migration...\n",
369373
"Success: Migration 'First One' applied successfuly.\n",
370374
"Executing migration...\n",
@@ -449,12 +453,15 @@ public function testRunMigrations19() {
449453
]));
450454
$this->assertEquals(0, $this->getExitCode());
451455
}
452-
private function createMigration(?string $name = null) : string {
456+
private function createMigration(?string $name = null, ?string $className = null) : string {
453457
$runner = new MigrationsRunner(APP_PATH.DS.'database'.DS.'migrations'.DS.'commands', '\\app\\database\\migrations\\commands', null);
454458
$writer = new DatabaseMigrationWriter($runner);
455459
if ($name !== null) {
456460
$writer->setMigrationName($name);
457461
}
462+
if ($className !== null) {
463+
$writer->setClassName($className);
464+
}
458465
$writer->writeClass();
459466
return $writer->getName(true);
460467
}

0 commit comments

Comments
 (0)