From 3833f5bffef2acd179dc5274a6bc3b830cad27a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Fejfar?= Date: Sun, 20 May 2018 18:05:58 +0200 Subject: [PATCH] No manifest behaves like empty manifest --- CHANGELOG.md | 3 +++ src/Manifest/ManifestManager.php | 9 +++++++-- tests/Manifest/ManifestManagerTest.php | 7 +++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 819733b0..f03b34f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ ## master +**Feature:** +- [\#37](https://github.com/keboola/php-component/pull/37): No manifest behaves like empty manifest + ## 4.1.1 **Patch:** diff --git a/src/Manifest/ManifestManager.php b/src/Manifest/ManifestManager.php index 6372b177..0d067fc1 100644 --- a/src/Manifest/ManifestManager.php +++ b/src/Manifest/ManifestManager.php @@ -80,8 +80,8 @@ public function getTableManifest(string $tableName) private function loadManifest(string $fileName, string $baseDir): array { $isPathInDirectory = strpos($fileName, $baseDir) === 0; + $fs = new Filesystem(); if (!$isPathInDirectory) { - $fs = new Filesystem(); if ($fs->isAbsolutePath($fileName)) { throw new InvalidArgumentException(sprintf( 'Manifest source "%s" must be in the data directory (%s)!', @@ -93,8 +93,13 @@ private function loadManifest(string $fileName, string $baseDir): array $fileName = implode('/', [$baseDir, $fileName]); } + $manifestFilename = $this->getManifestFilename($fileName); + if (!$fs->exists($manifestFilename)) { + return []; + } + $decoder = new JsonEncoder(); - return $decoder->decode(file_get_contents($this->getManifestFilename($fileName)), JsonEncoder::FORMAT); + return $decoder->decode(file_get_contents($manifestFilename), JsonEncoder::FORMAT); } /** diff --git a/tests/Manifest/ManifestManagerTest.php b/tests/Manifest/ManifestManagerTest.php index 2dc65b4e..49616a97 100644 --- a/tests/Manifest/ManifestManagerTest.php +++ b/tests/Manifest/ManifestManagerTest.php @@ -97,6 +97,13 @@ public function testWillLoadTableManifest(): void $this->assertSame($expectedManifest, $manager->getTableManifest('people.csv')); } + public function testNonexistentManifestReturnsEmptyArray(): void + { + $manager = new ManifestManager(__DIR__ . '/fixtures/manifest-data-dir'); + + $this->assertSame([], $manager->getTableManifest('manifest-does-not-exist')); + } + public function testWillLoadTableManifestWithoutCsv(): void { $manager = new ManifestManager(__DIR__ . '/fixtures/manifest-data-dir');