22
33namespace Lkrms \Tests ;
44
5+ use Lkrms \Console \Catalog \ConsoleLevel as Level ;
56use Lkrms \Utility \Pcre ;
7+ use Lkrms \Utility \Str ;
68use Closure ;
79use Throwable ;
810
@@ -14,22 +16,44 @@ abstract class TestCase extends \PHPUnit\Framework\TestCase
1416 * @param Closure(): mixed $callback
1517 * @param class-string<Throwable> $exception
1618 */
17- public function assertThrows (Closure $ callback , string $ exception , ?string $ exceptionMessage = null , string $ message = '' ): void
18- {
19+ public static function assertThrows (
20+ Closure $ callback ,
21+ string $ exception ,
22+ ?string $ exceptionMessage = null ,
23+ string $ message = ''
24+ ): void {
1925 try {
2026 $ callback ();
2127 } catch (Throwable $ ex ) {
22- $ this -> assertInstanceOf ($ exception , $ ex , $ message );
28+ static :: assertInstanceOf ($ exception , $ ex , $ message );
2329 if ($ exceptionMessage !== null ) {
24- $ this -> assertStringContainsString ($ exceptionMessage , $ ex ->getMessage (), $ message );
30+ static :: assertStringContainsString ($ exceptionMessage , $ ex ->getMessage (), $ message );
2531 }
2632 return ;
2733 }
28- $ this -> fail ($ message === ''
34+ static :: fail ($ message === ''
2935 ? sprintf ('Failed asserting that exception of type %s is thrown ' , $ exception )
3036 : $ message );
3137 }
3238
39+ /**
40+ * Assert that the given console messages are written, converting line
41+ * endings if necessary
42+ *
43+ * @param array<array{Level::*,string,2?:array<string,mixed>}> $expected
44+ * @param mixed[] $actual
45+ */
46+ public static function assertSameConsoleMessages (array $ expected , array $ actual , string $ message = '' ): void
47+ {
48+ foreach ($ expected as $ i => &$ expectedMessage ) {
49+ $ expectedMessage [1 ] = Str::eolFromNative ($ expectedMessage [1 ]);
50+ if (!isset ($ expectedMessage [2 ]) && isset ($ actual [$ i ][2 ])) {
51+ unset($ actual [$ i ][2 ]);
52+ }
53+ }
54+ static ::assertEquals ($ expected , $ actual , $ message );
55+ }
56+
3357 /**
3458 * Expect an exception if a given value is a string
3559 *
0 commit comments