From e7608ca9d6b2716ba5ee8ca2b7e6e5af77f8d977 Mon Sep 17 00:00:00 2001 From: distinctm Date: Wed, 12 Jun 2019 17:52:32 -0400 Subject: [PATCH] Filters for JSON files, closes #8 --- src/Updater.php | 9 ++++++--- tests/Unit/UpdaterTest.php | 9 +++++++++ tests/test-data/not-json/roles.txt | 9 +++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 tests/test-data/not-json/roles.txt diff --git a/src/Updater.php b/src/Updater.php index eee9664..80948de 100644 --- a/src/Updater.php +++ b/src/Updater.php @@ -106,9 +106,12 @@ class Updater return Collection::wrap($directory . '/' . $model . '.json'); } - return collect(File::files($directory))->map(function ($path) { - return $path->getPathname(); - }); + return collect(File::files($directory)) + ->filter(function($file) { + return pathinfo($file, PATHINFO_EXTENSION) == 'json'; + })->map(function ($path) { + return $path->getPathname(); + }); } /** diff --git a/tests/Unit/UpdaterTest.php b/tests/Unit/UpdaterTest.php index 7a611f2..e4f41dc 100644 --- a/tests/Unit/UpdaterTest.php +++ b/tests/Unit/UpdaterTest.php @@ -131,4 +131,13 @@ class UpdaterTest extends TestCase $updater = new UpdaterFake(__DIR__ . '/../test-data/ordered'); $updater->run(); } + + /** @test */ + public function it_ignores_non_json_files() + { + $updater = new UpdaterFake(__DIR__ . '/../test-data/not-json'); + $updater->run(); + + $this->assertDatabaseMissing('roles', ['slug' => 'update-student-records']); + } } \ No newline at end of file diff --git a/tests/test-data/not-json/roles.txt b/tests/test-data/not-json/roles.txt new file mode 100644 index 0000000..b1b0c7b --- /dev/null +++ b/tests/test-data/not-json/roles.txt @@ -0,0 +1,9 @@ +[ + { + "_slug": "update-student-records", + "category": "testing", + "supervisor": { + "name": "CEO" + } + } +] \ No newline at end of file