Skip to content

Commit c2037b7

Browse files
author
Paul M. Jones
authored
Merge pull request #34 from raphaelstolt/fix-evaluable-return-code
Exit with an evaluable return code
2 parents 82516c1 + 7e1a096 commit c2037b7

File tree

4 files changed

+53
-3
lines changed

4 files changed

+53
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
All notable changes to this publication will be documented in this file.
44

5+
## 1.0.1 - 2017-??-??
6+
The validate command returns an evaluable return code.
7+
58
## 1.0.0 - 2017-25-01
69

710
First stable release.

bin/pds-skeleton

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ if (! $autoload) {
2222
require $autoload;
2323

2424
$console = new \Pds\Skeleton\Console();
25-
$console->execute($argv);
25+
$executeState = $console->execute($argv);
26+
$executeState === true ? exit(0) : exit(1);

src/ComplianceValidator.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ class ComplianceValidator
99
const STATE_INCORRECT_PRESENT = 4;
1010

1111
protected $files = null;
12+
protected $compliant = true;
1213

1314
public function execute($root = null)
1415
{
1516
$lines = $this->getFiles($root);
1617
$results = $this->validate($lines);
1718
$this->outputResults($results);
18-
return true;
19+
return $this->getCompliant();
20+
}
21+
22+
public function getCompliant()
23+
{
24+
return $this->compliant;
1925
}
2026

2127
public function validate($lines)
@@ -39,6 +45,11 @@ public function validate($lines)
3945
$state = $complianceResult[0];
4046
$expected = $complianceResult[1];
4147
$actual = $complianceResult[2];
48+
49+
if ($expected !== $actual && ($state == self::STATE_INCORRECT_PRESENT || $state == self::STATE_RECOMMENDED_NOT_PRESENT)) {
50+
$this->compliant = false;
51+
}
52+
4253
$results[$expected] = [
4354
'label' => $label,
4455
'state' => $state,

tests/ComplianceValidatorTest.php

+36-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ public static function run()
99
{
1010
$tester = new ComplianceValidatorTest();
1111
$tester->testValidate_WithIncorrectBin_ReturnsIncorrectBin();
12+
$tester->testValidate_WithNonCompliance_SetsNonCompliantState();
13+
$tester->testValidate_WithCompliance_SetsCompliantState();
1214
echo __CLASS__ . " errors: {$tester->numErrors}" . PHP_EOL;
1315
}
1416

@@ -51,4 +53,37 @@ public function testValidate_WithIncorrectBin_ReturnsIncorrectBin()
5153
}
5254
}
5355
}
54-
}
56+
57+
public function testValidate_WithNonCompliance_SetsNonCompliantState()
58+
{
59+
$paths = [
60+
'cli/',
61+
'test/',
62+
];
63+
64+
$validator = new ComplianceValidator();
65+
$results = $validator->validate($paths);
66+
67+
if ($validator->getCompliant() == true) {
68+
$this->numErrors++;
69+
echo __FUNCTION__ . ": Expected a non compliant state" . PHP_EOL;
70+
}
71+
}
72+
73+
public function testValidate_WithCompliance_SetsCompliantState()
74+
{
75+
$paths = [
76+
'bin/',
77+
'tests/',
78+
'LICENSE.md',
79+
];
80+
81+
$validator = new ComplianceValidator();
82+
$results = $validator->validate($paths);
83+
84+
if ($validator->getCompliant() == false) {
85+
$this->numErrors++;
86+
echo __FUNCTION__ . ": Expected a compliant state" . PHP_EOL;
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)