-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test to check if LangCountryData files have all attributes
- Loading branch information
Showing
1 changed file
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
it('should contain all attributes as given in the template file', function () { | ||
$attributes = array_keys(json_decode(file_get_contents(__DIR__ . '/../../../src/LangCountryData/_template.json'), true)); | ||
|
||
// Retrieve all files from the LangCountryData directory, except the template file | ||
$files = glob(__DIR__ . '/../../../src/LangCountryData/*.json'); | ||
$files = array_filter($files, function ($file) { | ||
return ! preg_match('/_template.json/', $file); | ||
}); | ||
|
||
// Check if all files contain the same attributes from the $attributes array and that the values are not null or empty | ||
foreach ($files as $file) { | ||
$json = json_decode(file_get_contents($file), true); | ||
|
||
foreach ($attributes as $attribute) { | ||
expect(array_key_exists($attribute, $json))->toBeTrue() | ||
->and($json[$attribute])->not->toBeNull() | ||
->and($json[$attribute])->not->toBeEmpty(); | ||
} | ||
} | ||
|
||
}); |