Skip to content

Fix ShowTableInfoTest to pass on Windows #6853

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions tests/system/Commands/Database/ShowTableInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CodeIgniter\Commands\Database;

use CodeIgniter\CLI\CLI;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use CodeIgniter\Test\Filters\CITestStreamFilter;
Expand All @@ -33,6 +34,9 @@ protected function setUp(): void
{
parent::setUp();

putenv('NO_COLOR=1');
CLI::init();

CITestStreamFilter::$buffer = '';

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

putenv('NO_COLOR');
CLI::init();

stream_filter_remove($this->streamFilter);
}

private function getResultWithoutControlCode(): string
private function getNormalizedResult(): string
{
return str_replace(
["\033[0;30m", "\033[0;33m", "\033[43m", "\033[0m"],
'',
CITestStreamFilter::$buffer
);
return str_replace(PHP_EOL, "\n", CITestStreamFilter::$buffer);
}

public function testDbTable(): void
{
command('db:table db_migrations');

$result = $this->getResultWithoutControlCode();
$result = $this->getNormalizedResult();

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

$result = $this->getResultWithoutControlCode();
$result = $this->getNormalizedResult();

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

$result = $this->getResultWithoutControlCode();
$result = $this->getNormalizedResult();

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

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

$result = $this->getResultWithoutControlCode();
$result = $this->getNormalizedResult();

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

$result = $this->getResultWithoutControlCode();
$result = $this->getNormalizedResult();

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

$result = $this->getResultWithoutControlCode();
$result = $this->getNormalizedResult();

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

$result = $this->getResultWithoutControlCode();
$result = $this->getNormalizedResult();

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