Skip to content

Commit e7608ca

Browse files
committed
Filters for JSON files, closes #8
1 parent 58f1062 commit e7608ca

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/Updater.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ protected function getFiles(string $directory, $model = null)
106106
return Collection::wrap($directory . '/' . $model . '.json');
107107
}
108108

109-
return collect(File::files($directory))->map(function ($path) {
110-
return $path->getPathname();
111-
});
109+
return collect(File::files($directory))
110+
->filter(function($file) {
111+
return pathinfo($file, PATHINFO_EXTENSION) == 'json';
112+
})->map(function ($path) {
113+
return $path->getPathname();
114+
});
112115
}
113116

114117
/**

tests/Unit/UpdaterTest.php

+9
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,13 @@ public function exception_is_thrown_if_imports_are_in_incorrect_order()
131131
$updater = new UpdaterFake(__DIR__ . '/../test-data/ordered');
132132
$updater->run();
133133
}
134+
135+
/** @test */
136+
public function it_ignores_non_json_files()
137+
{
138+
$updater = new UpdaterFake(__DIR__ . '/../test-data/not-json');
139+
$updater->run();
140+
141+
$this->assertDatabaseMissing('roles', ['slug' => 'update-student-records']);
142+
}
134143
}

tests/test-data/not-json/roles.txt

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[
2+
{
3+
"_slug": "update-student-records",
4+
"category": "testing",
5+
"supervisor": {
6+
"name": "CEO"
7+
}
8+
}
9+
]

0 commit comments

Comments
 (0)