11<?php
22namespace webfiori \framework \test \cli ;
33
4+ use app \database \migrations \multiErr \MultiErrRunner ;
45use webfiori \database \ConnectionInfo ;
6+ use webfiori \database \DatabaseException ;
57use webfiori \database \migration \MigrationsRunner ;
68use webfiori \framework \App ;
79use webfiori \framework \cli \CLITestCase ;
810use webfiori \framework \cli \commands \RunMigrationsCommand ;
911use webfiori \framework \writers \DatabaseMigrationWriter ;
12+ use const APP_PATH ;
13+ use const DS ;
14+ use const SQL_SERVER_DB ;
15+ use const SQL_SERVER_HOST ;
16+ use const SQL_SERVER_PASS ;
17+ use const SQL_SERVER_USER ;
1018/**
1119 * @author Ibrahim
1220 */
@@ -147,7 +155,7 @@ public function testRunMigrations07() {
147155 App::getConfig ()->addOrUpdateDBConnection ($ conn );
148156 $ this ->assertEquals ([
149157 "Checking namespace '\app\database\migrations' for migrations... \n" ,
150- "Info: Found 2 migration(s) in the namespace '\app\database\migrations'. \n" ,
158+ "Info: Found 1 migration(s) in the namespace '\app\database\migrations'. \n" ,
151159 "Select database connection: \n" ,
152160 "0: default-conn <-- \n" ,
153161 "Error: Invalid answer. \n" ,
@@ -179,15 +187,15 @@ public function testRunMigrations08() {
179187 App::getConfig ()->addOrUpdateDBConnection ($ conn );
180188 $ this ->assertEquals ([
181189 "Checking namespace '\app\database\migrations' for migrations... \n" ,
182- "Info: Found 2 migration(s) in the namespace '\app\database\migrations'. \n" ,
190+ "Info: Found 1 migration(s) in the namespace '\app\database\migrations'. \n" ,
183191 "Select database connection: \n" ,
184192 "0: default-conn <-- \n" ,
185193 "Error: Invalid answer. \n" ,
186194 "Select database connection: \n" ,
187195 "0: default-conn <-- \n" ,
188- "Executing migration... \n" ,
196+ // "Executing migration...\n",
189197 "Error: Failed to execute migration due to following: \n" ,
190- "208 - [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'migrations'. \n" ,
198+ "208 - [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Invalid object name 'migrations'. (Line 361) \n" ,
191199 "Warning: Execution stopped. \n" ,
192200 "Info: No migrations were executed. \n"
193201 ], $ this ->executeMultiCommand ([
@@ -213,16 +221,16 @@ public function testRunMigrations09() {
213221 $ this ->assertTrue (class_exists ($ clazz ));
214222 App::getConfig ()->addOrUpdateDBConnection ($ conn );
215223 $ this ->assertEquals ([
224+ "Checking namespace '\app\database\migrations' for migrations... \n" ,
225+ "Info: Found 1 migration(s) in the namespace '\app\database\migrations'. \n" ,
216226 "Select database connection: \n" ,
217227 "0: default-conn <-- \n" ,
218228 "Error: Invalid answer. \n" ,
219229 "Select database connection: \n" ,
220230 "0: default-conn <-- \n" ,
221231 "Initializing migrations table... \n" ,
222232 "Success: Migrations table succesfully created. \n" ,
223- "Checking namespace '\app\database\migrations' for migrations... \n" ,
224- "Found 1 migration(s). \n" ,
225- "Executing migration... \n" ,
233+ //"Executing migration...\n",
226234 "Success: Migration 'Migration000' applied successfuly. \n" ,
227235 "Info: Number of applied migrations: 1 \n" ,
228236 "Names of applied migrations: \n" ,
@@ -252,11 +260,12 @@ public function testRunMigrations10() {
252260 $ this ->assertTrue (class_exists ($ clazz ));
253261 App::getConfig ()->addOrUpdateDBConnection ($ conn );
254262 $ this ->assertEquals ([
255- "Initializing migrations table... \n" ,
256- "Success: Migrations table succesfully created. \n" ,
257263 "Checking namespace '\app\database\migrations' for migrations... \n" ,
258264 "Found 1 migration(s). \n" ,
259- "Executing migration... \n" ,
265+ "Initializing migrations table... \n" ,
266+ "Success: Migrations table succesfully created. \n" ,
267+
268+ //"Executing migration...\n",
260269 "Success: Migration 'Cool One' applied successfuly. \n" ,
261270 "Info: Number of applied migrations: 1 \n" ,
262271 "Names of applied migrations: \n" ,
@@ -286,14 +295,15 @@ public function testRunMigrations11() {
286295 $ this ->assertTrue (class_exists ($ clazz ));
287296 App::getConfig ()->addOrUpdateDBConnection ($ conn );
288297 $ this ->assertEquals ([
298+ "Info: Using default namespace for migrations. \n" ,
299+ "Checking namespace '\app\database\migrations' for migrations... \n" ,
300+ "Found 1 migration(s). \n" ,
289301 "Select database connection: \n" ,
290302 "0: default-conn <-- \n" ,
291303 "Initializing migrations table... \n" ,
292304 "Success: Migrations table succesfully created. \n" ,
293- "Info: Using default namespace for migrations. \n" ,
294- "Checking namespace '\app\database\migrations' for migrations... \n" ,
295- "Found 1 migration(s). \n" ,
296- "Executing migration... \n" ,
305+
306+ //"Executing migration...\n",
297307 "Success: Migration 'Cool One' applied successfuly. \n" ,
298308 "Info: Number of applied migrations: 1 \n" ,
299309 "Names of applied migrations: \n" ,
@@ -319,6 +329,9 @@ public function testRunMigrations12() {
319329 $ conn ->setName ('default-conn ' );
320330 App::getConfig ()->addOrUpdateDBConnection ($ conn );
321331 $ this ->assertEquals ([
332+ "Info: Using default namespace for migrations. \n" ,
333+ "Checking namespace '\app\database\migrations' for migrations... \n" ,
334+ "Info: Found 1 migration(s) in the namespace '\app\database\migrations'. \n" ,
322335 "Select database connection: \n" ,
323336 "0: default-conn <-- \n" ,
324337 "Initializing migrations table... \n" ,
@@ -338,6 +351,9 @@ public function testRunMigrations12() {
338351 */
339352 public function testRunMigrations13 () {
340353 $ this ->assertEquals ([
354+ "Info: Using default namespace for migrations. \n" ,
355+ "Checking namespace '\app\database\migrations' for migrations... \n" ,
356+ "\n" ,
341357 "Info: No connections were found in application configuration. \n" ,
342358 ], $ this ->executeMultiCommand ([
343359 RunMigrationsCommand::class,
@@ -352,6 +368,8 @@ public function testRunMigrations13() {
352368 */
353369 public function testRunMigrations14 () {
354370 $ this ->assertEquals ([
371+ "Checking namespace '\app\database\migrations \emptyRunner' for migrations... \n" ,
372+ "\n" ,
355373 "Initializing migrations table... \n" ,
356374 "Error: Unable to create migrations table due to following: \n" ,
357375 "Connection information not set. \n" ,
@@ -369,12 +387,10 @@ public function testRunMigrations15() {
369387 $ this ->assertEquals ([
370388 "Initializing migrations table... \n" ,
371389 "Success: Migrations table succesfully created. \n" ,
390+ "\n" ,
372391 "Info: Found 3 migration(s) in the namespace '\app\database\migrations\multi'. \n" ,
373- "Executing migration... \n" ,
374392 "Success: Migration 'First One' applied successfuly. \n" ,
375- "Executing migration... \n" ,
376393 "Success: Migration 'Second one' applied successfuly. \n" ,
377- "Executing migration... \n" ,
378394 "Success: Migration 'Third One' applied successfuly. \n" ,
379395 "Info: Number of applied migrations: 3 \n" ,
380396 "Names of applied migrations: \n" ,
@@ -437,13 +453,13 @@ public function testRunMigrations19() {
437453 "Success: Migrations table succesfully created. \n" ,
438454 "Checking namespace '\app\database\migrations\multiErr' for migrations... \n" ,
439455 "Info: Found 3 migration(s) in the namespace '\app\database\migrations\multiErr'. \n" ,
440- "Executing migration... \n" ,
456+ // "Executing migration...\n",
441457 "Success: Migration 'First One' applied successfuly. \n" ,
442- "Executing migration... \n" ,
458+ // "Executing migration...\n",
443459 "Success: Migration 'Second one' applied successfuly. \n" ,
444- "Executing migration... \n" ,
460+ // "Executing migration...\n",
445461 "Error: Failed to execute migration due to following: \n" ,
446- "Call to undefined method app\database\migrations\multiErr\Migration000::x() at line 22 \n" ,
462+ "Call to undefined method app\database\migrations\multiErr\Migration000::x() (Line 22) \n" ,
447463 "Warning: Execution stopped. \n" ,
448464 "Info: Number of applied migrations: 2 \n" ,
449465 "Names of applied migrations: \n" ,
@@ -455,6 +471,8 @@ public function testRunMigrations19() {
455471 '--ini '
456472 ]));
457473 $ this ->assertEquals (0 , $ this ->getExitCode ());
474+ $ r = new MultiErrRunner ();
475+ $ this ->removeMigTable ($ r ->getConnectionInfo ());
458476 }
459477 private function createMigration (?string $ name = null , ?string $ className = null ) : string {
460478 $ runner = new MigrationsRunner (APP_PATH .DS .'database ' .DS .'migrations ' .DS .'commands ' , '\\app \\database \\migrations \\commands ' , null );
@@ -477,7 +495,7 @@ private function removeMigTable(?ConnectionInfo $conn = null) {
477495 $ runner = new MigrationsRunner (APP_PATH .DS .'database ' .DS .'migrations ' .DS .'commands ' , '\\app \\database \\migrations \\commands ' , $ conn );
478496 try {
479497 $ runner ->dropMigrationsTable ();
480- } catch (\ webfiori \ database \ DatabaseException $ ex ) {
498+ } catch (DatabaseException $ ex ) {
481499
482500 }
483501 }
0 commit comments