Skip to content

Commit

Permalink
Add test to check if LangCountryData files have all attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
stefro committed Nov 18, 2023
1 parent 3862f5e commit 496617d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/Feature/LangCountryData/LangCountryDataTest.php
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();
}
}

});

0 comments on commit 496617d

Please sign in to comment.