@@ -21,6 +21,8 @@ class Unit
21
21
private array $ units ;
22
22
private int $ index = 0 ;
23
23
private array $ error ;
24
+ private static string $ file = "" ;
25
+ private static array $ info = [];
24
26
25
27
public function __construct (bool $ quite = false )
26
28
{
@@ -75,18 +77,23 @@ public function add(string $message, callable $callback): void
75
77
$ data = $ test ->getTestResult ();
76
78
$ index = $ this ->index -1 ;
77
79
78
- $ this ->error [$ index ] = [
79
- 'message ' => $ message
80
+ $ count = count ($ test ->getTestCases ());
81
+ $ this ->error ['info ' ] = [
82
+ 'count ' => $ count ,
83
+ 'total ' => $ count
80
84
];
85
+ $ this ->error ['feed ' ][$ index ] = [
86
+ 'message ' => $ message ,
87
+ 'file ' => self ::$ file ,
88
+ 'error ' => []
89
+ ];
90
+
81
91
foreach ($ data as $ key => $ row ) {
82
92
if (!$ row ['test ' ]) {
83
- $ hasError = true ;
84
- $ this ->error [$ index ]['error ' ][ $ key ] = $ row ;
93
+ $ this -> error [ ' feed ' ][ $ index ][ ' error ' ][ $ key ] = $ row ;
94
+ $ this ->error [' info ' ]['count ' ]-- ;
85
95
}
86
96
}
87
- if (!$ hasError ) {
88
- unset($ this ->error [$ index ]);
89
- }
90
97
}
91
98
92
99
/**
@@ -127,25 +134,49 @@ public function execute(): void
127
134
$ run = new Run (new CliHandler ());
128
135
$ run ->load ();
129
136
130
- if (!is_null ($ this ->title ) && (!$ this ->quite || count ($ this ->error ) > 0 )) {
131
- $ this ->command ->title ("\n--------- $ this ->title --------- " );
132
- }
133
- if (count ($ this ->error ) > 0 ) {
134
- foreach ($ this ->error as $ error ) {
135
- //$tests = [];
136
- $ this ->command ->title ("\n{$ error ['message ' ]}" );
137
- foreach ($ error ['error ' ] as $ row ) {
138
- //$tests[] = $row['method'];
139
- $ this ->command ->error ("Test-value {$ row ['readableValue ' ]}" );
140
- $ this ->command ->error ("{$ row ['message ' ]}\n" );
137
+
138
+
139
+ $ this ->command ->message ("" );
140
+
141
+ foreach ($ this ->error ['feed ' ] as $ error ) {
142
+
143
+ $ color = ($ error ['error ' ] ? "red " : "blue " );
144
+ $ flag = $ this ->command ->getAnsi ()->style (['blueBg ' , 'white ' ], " PASS " );
145
+ if ($ error ['error ' ]) {
146
+ $ flag = $ this ->command ->getAnsi ()->style (['redBg ' , 'white ' ], " FAIL " );
147
+ }
148
+
149
+ $ this ->command ->message ("" );
150
+ $ this ->command ->message (
151
+ $ flag .
152
+ " " .
153
+ $ this ->command ->getAnsi ()->style (["bold " ], $ this ->formatFileTitle ($ error ['file ' ])) .
154
+ " - " .
155
+ $ this ->command ->getAnsi ()->style (["bold " , $ color ], $ error ['message ' ])
156
+ );
157
+ foreach ($ error ['error ' ] as $ row ) {
158
+ $ this ->command ->message ("" );
159
+
160
+ $ this ->command ->message ($ this ->command ->getAnsi ()->style (["bold " , "red " ], "Error: {$ row ['message ' ]}" ));
161
+ $ this ->command ->message ($ this ->command ->getAnsi ()->bold ("Value: " ) . "{$ row ['readableValue ' ]}" );
162
+ if (is_string ($ row ['method ' ])) {
163
+ $ this ->command ->message ($ this ->command ->getAnsi ()->bold ("Validation: " ) . "{$ row ['method ' ]}" );
141
164
}
165
+
142
166
}
143
167
144
- } elseif (!$ this ->quite ) {
145
- $ this ->command ->approve ("Every test has been successfully run! " );
168
+ $ this ->command ->message ("" );
169
+ $ this ->command ->message (
170
+ $ this ->command ->getAnsi ()->bold ("Passed: " ) .
171
+ $ this ->command ->getAnsi ()->style ([$ color , "bold " ], $ this ->error ['info ' ]['count ' ] . "/ " . $ this ->error ['info ' ]['total ' ]));
146
172
}
147
173
148
- $ this ->command ->message ($ this ->output );
174
+
175
+
176
+
177
+ if ($ this ->output ) {
178
+ $ this ->command ->message ($ this ->output );
179
+ }
149
180
}
150
181
151
182
/**
@@ -162,6 +193,7 @@ public function executeAll(string $directory): void
162
193
} else {
163
194
foreach ($ files as $ file ) {
164
195
extract ($ this ->args , EXTR_PREFIX_SAME , "wddx " );
196
+ self ::$ file = $ file ;
165
197
require_once ($ file );
166
198
}
167
199
}
@@ -248,4 +280,27 @@ function getNaturalPath(string $path): string
248
280
{
249
281
return str_replace ("\\" , "/ " , $ path );
250
282
}
283
+ /**
284
+ * Get path as natural path
285
+ * @param string $path
286
+ * @return string
287
+ */
288
+ function getUnnaturalPath (string $ path ): string
289
+ {
290
+ return str_replace ("/ " , "\\" , $ path );
291
+ }
292
+
293
+ /**
294
+ * Make file path into a title
295
+ * @param string $file
296
+ * @return string
297
+ */
298
+ function formatFileTitle (string $ file ): string
299
+ {
300
+ $ file = explode ("/ " , $ file );
301
+ $ file = array_chunk (array_reverse ($ file ), 3 );
302
+ $ file = implode ("\\" , array_reverse ($ file [0 ]));
303
+ $ exp = explode ('. ' , $ file );
304
+ return ".. " . reset ($ exp );
305
+ }
251
306
}
0 commit comments