Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**
Expand Down
9 changes: 7 additions & 2 deletions src/Manifest/ManifestManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)!',
Expand All @@ -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);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/Manifest/ManifestManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down