Skip to content

Commit 5558fe9

Browse files
authored
Merge pull request #6853 from paulbalandan/fix-showtableinfotest
Fix ShowTableInfoTest to pass on Windows
2 parents 44530a5 + 11fbcdb commit 5558fe9

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

tests/system/Commands/Database/ShowTableInfoTest.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\Commands\Database;
1313

14+
use CodeIgniter\CLI\CLI;
1415
use CodeIgniter\Test\CIUnitTestCase;
1516
use CodeIgniter\Test\DatabaseTestTrait;
1617
use CodeIgniter\Test\Filters\CITestStreamFilter;
@@ -33,6 +34,9 @@ protected function setUp(): void
3334
{
3435
parent::setUp();
3536

37+
putenv('NO_COLOR=1');
38+
CLI::init();
39+
3640
CITestStreamFilter::$buffer = '';
3741

3842
$this->streamFilter = stream_filter_append(STDOUT, 'CITestStreamFilter');
@@ -43,23 +47,22 @@ protected function tearDown(): void
4347
{
4448
parent::tearDown();
4549

50+
putenv('NO_COLOR');
51+
CLI::init();
52+
4653
stream_filter_remove($this->streamFilter);
4754
}
4855

49-
private function getResultWithoutControlCode(): string
56+
private function getNormalizedResult(): string
5057
{
51-
return str_replace(
52-
["\033[0;30m", "\033[0;33m", "\033[43m", "\033[0m"],
53-
'',
54-
CITestStreamFilter::$buffer
55-
);
58+
return str_replace(PHP_EOL, "\n", CITestStreamFilter::$buffer);
5659
}
5760

5861
public function testDbTable(): void
5962
{
6063
command('db:table db_migrations');
6164

62-
$result = $this->getResultWithoutControlCode();
65+
$result = $this->getNormalizedResult();
6366

6467
$expected = 'Data of Table "db_migrations":';
6568
$this->assertStringContainsString($expected, $result);
@@ -76,7 +79,7 @@ public function testDbTableShow(): void
7679
{
7780
command('db:table --show');
7881

79-
$result = $this->getResultWithoutControlCode();
82+
$result = $this->getNormalizedResult();
8083

8184
$expected = 'The following is a list of the names of all database tables:';
8285
$this->assertStringContainsString($expected, $result);
@@ -93,7 +96,7 @@ public function testDbTableMetadata(): void
9396
{
9497
command('db:table db_migrations --metadata');
9598

96-
$result = $this->getResultWithoutControlCode();
99+
$result = $this->getNormalizedResult();
97100

98101
$expected = 'List of Metadata Information in Table "db_migrations":';
99102
$this->assertStringContainsString($expected, $result);
@@ -112,7 +115,7 @@ public function testDbTableDesc(): void
112115

113116
command('db:table db_user --desc');
114117

115-
$result = $this->getResultWithoutControlCode();
118+
$result = $this->getNormalizedResult();
116119

117120
$expected = 'Data of Table "db_user":';
118121
$this->assertStringContainsString($expected, $result);
@@ -134,7 +137,7 @@ public function testDbTableLimitFieldValueLength(): void
134137
{
135138
command('db:table db_user --limit-field-value 5');
136139

137-
$result = $this->getResultWithoutControlCode();
140+
$result = $this->getNormalizedResult();
138141

139142
$expected = 'Data of Table "db_user":';
140143
$this->assertStringContainsString($expected, $result);
@@ -156,7 +159,7 @@ public function testDbTableLimitRows(): void
156159
{
157160
command('db:table db_user --limit-rows 2');
158161

159-
$result = $this->getResultWithoutControlCode();
162+
$result = $this->getNormalizedResult();
160163

161164
$expected = 'Data of Table "db_user":';
162165
$this->assertStringContainsString($expected, $result);
@@ -176,7 +179,7 @@ public function testDbTableAllOptions(): void
176179
{
177180
command('db:table db_user --limit-rows 2 --limit-field-value 5 --desc');
178181

179-
$result = $this->getResultWithoutControlCode();
182+
$result = $this->getNormalizedResult();
180183

181184
$expected = 'Data of Table "db_user":';
182185
$this->assertStringContainsString($expected, $result);

0 commit comments

Comments
 (0)