File tree 4 files changed +53
-3
lines changed
4 files changed +53
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
All notable changes to this publication will be documented in this file.
4
4
5
+ ## 1.0.1 - 2017-??-??
6
+ The validate command returns an evaluable return code.
7
+
5
8
## 1.0.0 - 2017-25-01
6
9
7
10
First stable release.
Original file line number Diff line number Diff line change @@ -22,4 +22,5 @@ if (! $autoload) {
22
22
require $ autoload ;
23
23
24
24
$ console = new \Pds \Skeleton \Console ();
25
- $ console ->execute ($ argv );
25
+ $ executeState = $ console ->execute ($ argv );
26
+ $ executeState === true ? exit (0 ) : exit (1 );
Original file line number Diff line number Diff line change @@ -9,13 +9,19 @@ class ComplianceValidator
9
9
const STATE_INCORRECT_PRESENT = 4 ;
10
10
11
11
protected $ files = null ;
12
+ protected $ compliant = true ;
12
13
13
14
public function execute ($ root = null )
14
15
{
15
16
$ lines = $ this ->getFiles ($ root );
16
17
$ results = $ this ->validate ($ lines );
17
18
$ this ->outputResults ($ results );
18
- return true ;
19
+ return $ this ->getCompliant ();
20
+ }
21
+
22
+ public function getCompliant ()
23
+ {
24
+ return $ this ->compliant ;
19
25
}
20
26
21
27
public function validate ($ lines )
@@ -39,6 +45,11 @@ public function validate($lines)
39
45
$ state = $ complianceResult [0 ];
40
46
$ expected = $ complianceResult [1 ];
41
47
$ 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
+
42
53
$ results [$ expected ] = [
43
54
'label ' => $ label ,
44
55
'state ' => $ state ,
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ public static function run()
9
9
{
10
10
$ tester = new ComplianceValidatorTest ();
11
11
$ tester ->testValidate_WithIncorrectBin_ReturnsIncorrectBin ();
12
+ $ tester ->testValidate_WithNonCompliance_SetsNonCompliantState ();
13
+ $ tester ->testValidate_WithCompliance_SetsCompliantState ();
12
14
echo __CLASS__ . " errors: {$ tester ->numErrors }" . PHP_EOL ;
13
15
}
14
16
@@ -51,4 +53,37 @@ public function testValidate_WithIncorrectBin_ReturnsIncorrectBin()
51
53
}
52
54
}
53
55
}
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
+ }
You can’t perform that action at this time.
0 commit comments