Skip to content

Commit e4ab4bd

Browse files
committed
ITT: seeArtisanTableOutput assertion added.
1 parent 44bcff5 commit e4ab4bd

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/Asserts/ArtisanAsserts.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,36 @@ protected function dontSeeArtisanOutput($output)
1919
$actual = trim(Artisan::output());
2020
$this->assertNotEquals($expected, $actual, "Failed asserting that artisan output is not `{$expected}`.");
2121
}
22+
23+
protected function seeArtisanTableOutput(array $data)
24+
{
25+
$message = "Failed asserting that artisan table output equals to expected value.";
26+
$this->assertEquals($data, $this->parseArtisanTableOutput(Artisan::output()), $message);
27+
}
28+
29+
private function parseArtisanTableOutput($output)
30+
{
31+
$parsed = [];
32+
33+
$headers = [];
34+
$outputRows = explode("\n", trim($output));
35+
foreach ($outputRows as $row) {
36+
if (!str_contains($row, '|')) {
37+
continue;
38+
}
39+
40+
$row = explode('|', $row);
41+
$row = array_filter($row);
42+
$row = array_map('trim', $row);
43+
44+
if (empty($headers)) {
45+
$headers = $row;
46+
continue;
47+
}
48+
49+
$parsed[] = array_combine($headers, $row);
50+
}
51+
52+
return $parsed;
53+
}
2254
}

0 commit comments

Comments
 (0)