Skip to content

Commit 21ea0c7

Browse files
committed
test: Fix Test Cases
1 parent d41e784 commit 21ea0c7

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,19 @@ public function testAddDBConnection02() {
163163
* @test
164164
*/
165165
public function testAddLang00() {
166+
// Generate a unique 2-character language code based on current microseconds
167+
$langCode = substr(str_replace('.', '', microtime(true)), -2);
168+
// Ensure it's exactly 2 characters and alphabetic
169+
$langCode = chr(65 + ($langCode[0] % 26)) . chr(65 + ($langCode[1] % 26));
170+
171+
// Clean up if it exists from previous runs
172+
if (class_exists('\\app\\langs\\Lang' . $langCode)) {
173+
$this->removeClass('\\app\\langs\\Lang' . $langCode);
174+
}
175+
166176
$output = $this->executeSingleCommand(new AddCommand(), [], [
167177
'2',
168-
'ZZ',
178+
$langCode,
169179
'F Name',
170180
'F description',
171181
'Default f Title',
@@ -188,8 +198,8 @@ public function testAddLang00() {
188198
"1: rtl\n",
189199
"Success: Language added. Also, a class for the language is created at \"".APP_DIR."\langs\" for that language.\n"
190200
], $output);
191-
$this->assertTrue(class_exists('\\app\\langs\\LangZZ'));
192-
$this->removeClass('\\app\\langs\\LangZZ');
201+
$this->assertTrue(class_exists('\\app\\langs\\Lang' . $langCode));
202+
$this->removeClass('\\app\\langs\\Lang' . $langCode);
193203
Controller::getDriver()->initialize();
194204
}
195205
/**

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88
* @author Ibrahim
99
*/
1010
class CreateMigrationTest extends CLITestCase {
11+
12+
protected function tearDown(): void {
13+
// Clean up all migration files after each test
14+
$migrationsDir = APP_PATH . DS . 'database' . DS . 'migrations';
15+
if (is_dir($migrationsDir)) {
16+
$files = glob($migrationsDir . DS . 'Migration*.php');
17+
foreach ($files as $file) {
18+
if (is_file($file)) {
19+
unlink($file);
20+
}
21+
}
22+
$files = glob($migrationsDir . DS . 'Cool*.php');
23+
foreach ($files as $file) {
24+
if (is_file($file)) {
25+
unlink($file);
26+
}
27+
}
28+
}
29+
parent::tearDown();
30+
}
1131
/**
1232
* @test
1333
*/

tests/webfiori/framework/test/writers/DatabaseMigrationWriterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,20 @@
1111
* @author Ibrahim
1212
*/
1313
class DatabaseMigrationWriterTest extends TestCase {
14+
15+
protected function tearDown(): void {
16+
// Clean up all migration files after each test
17+
$migrationsDir = APP_PATH . DS . 'database' . DS . 'migrations';
18+
if (is_dir($migrationsDir)) {
19+
$files = glob($migrationsDir . DS . 'Migration*.php');
20+
foreach ($files as $file) {
21+
if (is_file($file)) {
22+
unlink($file);
23+
}
24+
}
25+
}
26+
parent::tearDown();
27+
}
1428
/**
1529
* @test
1630
*/

0 commit comments

Comments
 (0)