11
11
12
12
namespace CodeIgniter \Commands \Database ;
13
13
14
+ use CodeIgniter \CLI \CLI ;
14
15
use CodeIgniter \Test \CIUnitTestCase ;
15
16
use CodeIgniter \Test \DatabaseTestTrait ;
16
17
use CodeIgniter \Test \Filters \CITestStreamFilter ;
@@ -33,6 +34,9 @@ protected function setUp(): void
33
34
{
34
35
parent ::setUp ();
35
36
37
+ putenv ('NO_COLOR=1 ' );
38
+ CLI ::init ();
39
+
36
40
CITestStreamFilter::$ buffer = '' ;
37
41
38
42
$ this ->streamFilter = stream_filter_append (STDOUT , 'CITestStreamFilter ' );
@@ -43,23 +47,22 @@ protected function tearDown(): void
43
47
{
44
48
parent ::tearDown ();
45
49
50
+ putenv ('NO_COLOR ' );
51
+ CLI ::init ();
52
+
46
53
stream_filter_remove ($ this ->streamFilter );
47
54
}
48
55
49
- private function getResultWithoutControlCode (): string
56
+ private function getNormalizedResult (): string
50
57
{
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 );
56
59
}
57
60
58
61
public function testDbTable (): void
59
62
{
60
63
command ('db:table db_migrations ' );
61
64
62
- $ result = $ this ->getResultWithoutControlCode ();
65
+ $ result = $ this ->getNormalizedResult ();
63
66
64
67
$ expected = 'Data of Table "db_migrations": ' ;
65
68
$ this ->assertStringContainsString ($ expected , $ result );
@@ -76,7 +79,7 @@ public function testDbTableShow(): void
76
79
{
77
80
command ('db:table --show ' );
78
81
79
- $ result = $ this ->getResultWithoutControlCode ();
82
+ $ result = $ this ->getNormalizedResult ();
80
83
81
84
$ expected = 'The following is a list of the names of all database tables: ' ;
82
85
$ this ->assertStringContainsString ($ expected , $ result );
@@ -93,7 +96,7 @@ public function testDbTableMetadata(): void
93
96
{
94
97
command ('db:table db_migrations --metadata ' );
95
98
96
- $ result = $ this ->getResultWithoutControlCode ();
99
+ $ result = $ this ->getNormalizedResult ();
97
100
98
101
$ expected = 'List of Metadata Information in Table "db_migrations": ' ;
99
102
$ this ->assertStringContainsString ($ expected , $ result );
@@ -112,7 +115,7 @@ public function testDbTableDesc(): void
112
115
113
116
command ('db:table db_user --desc ' );
114
117
115
- $ result = $ this ->getResultWithoutControlCode ();
118
+ $ result = $ this ->getNormalizedResult ();
116
119
117
120
$ expected = 'Data of Table "db_user": ' ;
118
121
$ this ->assertStringContainsString ($ expected , $ result );
@@ -134,7 +137,7 @@ public function testDbTableLimitFieldValueLength(): void
134
137
{
135
138
command ('db:table db_user --limit-field-value 5 ' );
136
139
137
- $ result = $ this ->getResultWithoutControlCode ();
140
+ $ result = $ this ->getNormalizedResult ();
138
141
139
142
$ expected = 'Data of Table "db_user": ' ;
140
143
$ this ->assertStringContainsString ($ expected , $ result );
@@ -156,7 +159,7 @@ public function testDbTableLimitRows(): void
156
159
{
157
160
command ('db:table db_user --limit-rows 2 ' );
158
161
159
- $ result = $ this ->getResultWithoutControlCode ();
162
+ $ result = $ this ->getNormalizedResult ();
160
163
161
164
$ expected = 'Data of Table "db_user": ' ;
162
165
$ this ->assertStringContainsString ($ expected , $ result );
@@ -176,7 +179,7 @@ public function testDbTableAllOptions(): void
176
179
{
177
180
command ('db:table db_user --limit-rows 2 --limit-field-value 5 --desc ' );
178
181
179
- $ result = $ this ->getResultWithoutControlCode ();
182
+ $ result = $ this ->getNormalizedResult ();
180
183
181
184
$ expected = 'Data of Table "db_user": ' ;
182
185
$ this ->assertStringContainsString ($ expected , $ result );
0 commit comments