Skip to content

Commit f32b289

Browse files
staabmclxmstaab
andauthored
use exit-code for AnalyzeApplication (#11)
Co-authored-by: Markus Staab <[email protected]>
1 parent b407b9a commit f32b289

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/AnalyzeApplication.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@
66

77
final class AnalyzeApplication
88
{
9+
const EXIT_SUCCESS = 0;
10+
const EXIT_ERROR = 1;
911

1012
/**
1113
* @param ResultPrinter::FORMAT_* $format
14+
*
15+
* @return self::EXIT_*
16+
*
1217
* @throws \Safe\Exceptions\FilesystemException
1318
*/
1419
public function start(string $glob, string $format): int
@@ -34,7 +39,10 @@ public function start(string $glob, string $format): int
3439
$this->printResult($format, $isFirst, $isLast, $stream);
3540
}
3641

37-
return 0;
42+
if ($numBaselines > 0) {
43+
return self::EXIT_SUCCESS;
44+
}
45+
return self::EXIT_ERROR;
3846
}
3947

4048
public function help(): void

tests/AnalyzeApplicationTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function testTextPrinting():void
1212
$app = new AnalyzeApplication();
1313

1414
ob_start();
15-
$app->start(__DIR__ . '/fixtures/all-in.neon', ResultPrinter::FORMAT_TEXT);
15+
$exitCode = $app->start(__DIR__ . '/fixtures/all-in.neon', ResultPrinter::FORMAT_TEXT);
1616
$rendered = ob_get_clean();
1717

1818
$rendered = str_replace(__DIR__, '', $rendered);
@@ -24,14 +24,15 @@ function testTextPrinting():void
2424
PHP;
2525

2626
$this->assertSame($expected, $rendered);
27+
$this->assertSame(0, $exitCode);
2728
}
2829

2930
function testJsonPrinting():void
3031
{
3132
$app = new AnalyzeApplication();
3233

3334
ob_start();
34-
$app->start(__DIR__ . '/fixtures/all-in.neon', ResultPrinter::FORMAT_JSON);
35+
$exitCode = $app->start(__DIR__ . '/fixtures/all-in.neon', ResultPrinter::FORMAT_JSON);
3536
$rendered = ob_get_clean();
3637

3738
$rendered = str_replace(trim(json_encode(__DIR__), '"'), '', $rendered);
@@ -41,5 +42,18 @@ function testJsonPrinting():void
4142
PHP;
4243

4344
$this->assertSame($expected, $rendered);
45+
$this->assertSame(0, $exitCode);
46+
}
47+
48+
function testNoMatchingGlob():void
49+
{
50+
$app = new AnalyzeApplication();
51+
52+
ob_start();
53+
$exitCode = $app->start('this/file/does/not/exist*baseline.neon', ResultPrinter::FORMAT_TEXT);
54+
$rendered = ob_get_clean();
55+
56+
$this->assertSame('', $rendered);
57+
$this->assertSame(1, $exitCode);
4458
}
4559
}

0 commit comments

Comments
 (0)