Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Helldar committed Jun 1, 2021
1 parent 9640443 commit 5c2532b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
4 changes: 1 addition & 3 deletions app/tests/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ final class JsonTest extends TestCase
public function testJson(): void
{
foreach ($this->files('.json') as $filename) {
$resolved = $this->resolveFilename($filename);

$source = $this->source($resolved);
$source = $this->source($filename);

foreach ($this->locales() as $locale) {
$filename = $this->resolveFilename($filename, $locale);
Expand Down
29 changes: 26 additions & 3 deletions app/tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class TestCase extends BaseTestCase

protected function source(string $filename): array
{
$content = $this->load($this->source_path . '/' . $filename);
$content = $this->isJsonFile($filename) ? $this->loadJson() : $this->loadFile($filename);

if ($this->isValidation($filename)) {
$custom = Arr::get($content, 'custom', []);
Expand All @@ -38,6 +38,24 @@ protected function source(string $filename): array
return Arr::ksort($content);
}

protected function loadFile(string $filename): array
{
return $this->load($this->source_path . '/' . $filename);
}

protected function loadJson(): array
{
$items = [];

foreach ($this->files('json', true) as $file) {
$values = $this->loadFile($file);

$items = Arr::addUnique($items, $values);
}

return Arr::renameKeys($items, static fn ($key, $value) => $value);
}

protected function assertSee(string $path, string $content): void
{
$file = File::make()->loadRaw($path);
Expand Down Expand Up @@ -67,9 +85,9 @@ protected function sort(array &$array): void
$array = Arr::ksort($array);
}

protected function files(string $extension): array
protected function files(string $extension, bool $recursive = false): array
{
return Filesystem::names($this->source_path, static fn ($filename) => str_ends_with($filename, $extension), recursive: true);
return Filesystem::names($this->source_path, static fn ($filename) => str_ends_with($filename, $extension), $recursive);
}

protected function locales(): array
Expand Down Expand Up @@ -98,6 +116,11 @@ protected function isMainJson(string $filename): bool
return Directory::exists(__DIR__ . '/../../locales/' . $locale);
}

protected function isJsonFile(string $filename): bool
{
return str_ends_with($filename, 'json');
}

protected function isEnglish(string $filename): bool
{
return str_starts_with($filename, Locales::ENGLISH);
Expand Down

0 comments on commit 5c2532b

Please sign in to comment.