11<?php declare (strict_types=1 );
22
3- const SchemaDir = __DIR__ .'/../../../../schema/ ' ;
4-
5- const SchemasFiles = [
6- SchemaDir.'/bom-1.2.schema.json ' ,
7- SchemaDir.'/bom-1.2-strict.schema.json ' ,
8- SchemaDir.'/bom-1.3.schema.json ' ,
9- SchemaDir.'/bom-1.3-strict.schema.json ' ,
10- SchemaDir.'/bom-1.4-SNAPSHOT.schema.json ' ,
11- SchemaDir.'/bom-1.4.schema.json ' ,
12- SchemaDir.'/bom-1.4-strict.schema.json ' ,
13- SchemaDir.'/jsf-0.82.schema.json ' ,
14- SchemaDir.'/spdx.schema.json ' ,
15- ];
3+ // region config
4+
5+ const SchemaFileGlob = '*.schema.json ' ;
6+ const SchemaDir = __DIR__ .'/../../../../schema/ ' ;
7+
8+ // endregion config
9+
10+ // region pre-check
11+
12+ if (!is_dir (SchemaDir)) {
13+ throw new RuntimeException ('No such dir: ' .SchemaDir);
14+ }
15+
16+ $ schemasFiles = glob (SchemaDir.SchemaFileGlob, GLOB_ERR );
17+ if (empty ($ schemasFiles )) {
18+ throw new RuntimeException ('No schema files found ' );
19+ }
20+
21+ // region pre-check
1622
1723require_once __DIR__ .'/vendor/autoload.php ' ;
1824
1925$ errCnt = 0 ;
20- $ schemaLoader = new Opis \JsonSchema \SchemaLoader ();
2126
22- foreach (SchemasFiles as $ schemasFile ) {
23- $ schemasFile = realpath ($ schemasFile );
24- if (!$ schemasFile ) {
25- // skip
26- continue ;
27- }
28- echo PHP_EOL , "Schema: $ schemasFile " , PHP_EOL ;
27+ foreach ($ schemasFiles as $ schemasFilePath ) {
28+ echo PHP_EOL , "SchemaFile: $ schemasFilePath " , PHP_EOL ;
2929
3030 try {
31- $ schema = json_decode (file_get_contents ($ schemasFile ), false , 512 , JSON_THROW_ON_ERROR );
31+ $ schema = json_decode (file_get_contents ($ schemasFilePath ), false , 512 , JSON_THROW_ON_ERROR );
3232 if (!is_object ($ schema )) {
33- throw new DomainException (" decode to a non-object " );
33+ throw new DomainException (' decode to a non-object ' );
3434 }
35- }
36- catch (Exception $ exception )
37- {
35+ } catch (Exception $ exception ) {
3836 ++$ errCnt ;
39- echo " JSON DECODE ERROR: " , $ exception ->getMessage (), PHP_EOL ;
37+ echo ' JSON DECODE ERROR: ' , $ exception ->getMessage (), PHP_EOL ;
4038 continue ;
4139 }
4240
4341 try {
44- $ schemaLoader ->loadObjectSchema ($ schema );
45- echo "OK. " , PHP_EOL ;
42+ // run on individual instances, so no pollution or artifacts can distort tests
43+ (new Opis \JsonSchema \SchemaLoader ())->loadObjectSchema ($ schema );
44+ echo 'OK. ' , PHP_EOL ;
4645 } catch (Opis \JsonSchema \Exceptions \SchemaException $ exception ) {
4746 ++$ errCnt ;
48- echo " SCHEMA ERROR: " , $ exception ->getMessage (), PHP_EOL ;
47+ echo ' SCHEMA ERROR: ' , $ exception ->getMessage (), PHP_EOL ;
4948 continue ;
5049 } catch (Exception $ exception ) {
5150 ++$ errCnt ;
52- echo " UNEXPECTED ERROR: " , $ exception ->getMessage (), PHP_EOL ;
51+ echo ' UNEXPECTED ERROR: ' , $ exception ->getMessage (), PHP_EOL ;
5352 continue ;
5453 }
5554}
5655
57- exit ($ errCnt );
56+ // Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used.
57+ // The status 0 is used to terminate the program successfully.
58+ exit (min ($ errCnt , 254 ));
0 commit comments