Skip to content

Commit

Permalink
Fix bug caused by a file not existing but having a metadata.
Browse files Browse the repository at this point in the history
  • Loading branch information
Potherca committed Jan 11, 2022
1 parent 080eb0d commit 743b028
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
13 changes: 9 additions & 4 deletions src/Flysystem/Adapter/Rdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,12 @@ final public function setVisibility($path, $visibility)

final public function has($path)
{
if ($this->format === "") {
$metadata = call_user_func_array([$this->adapter, __FUNCTION__], func_get_args());
} else {
$metadata = call_user_func_array([$this->adapter, __FUNCTION__], func_get_args());

if ($this->format !== '' || $metadata === false) {
$metadata = $this->getMetadata($path);
}

return $metadata;
}

Expand Down Expand Up @@ -163,7 +164,11 @@ final public function listContents($directory = '', $recursive = false)

final public function getMetadata($path)
{
$metadata = $this->adapter->getMetadata($path) ?? [];
$metadata = [];

if ($this->adapter->has($path)) {
$this->adapter->getMetadata($path) ?? [];
}

$format = $this->format;

Expand Down
25 changes: 16 additions & 9 deletions tests/unit/Flysystem/Adapter/RdfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public function testRdfAdapterShouldReturnInnerAdapterResultWhenProxyMethodsAreC
{
$expected = self::MOCK_CONTENTS;

$count = 1;

$adapterMethod = $method;

if ($method === 'read' || $method === 'readStream') {
Expand All @@ -146,6 +148,7 @@ public function testRdfAdapterShouldReturnInnerAdapterResultWhenProxyMethodsAreC
} elseif ($method === 'getMimetype') {
$expected = ['mimetype' => self::MOCK_MIME];
} elseif ($method === 'getMetadata') {
$count = 0;
$expected = [];
}

Expand All @@ -163,7 +166,7 @@ public function testRdfAdapterShouldReturnInnerAdapterResultWhenProxyMethodsAreC
->willReturn(false)
;

$this->mockAdapter->expects($this->once())
$this->mockAdapter->expects($this->exactly($count))
->method($adapterMethod)
->willReturn($expected)
;
Expand Down Expand Up @@ -260,7 +263,7 @@ public function testRdfAdapterShouldCallInnerAdapterAndGraphWhenNonProxyMethodsA
->willReturn(self::MOCK_MIME)
;

if ($method === 'getMimeType' || $method === 'getSize') {
if ($method === 'getMetadata' || $method === 'getMimeType' || $method === 'getSize') {
/*/ These inner adapter method should *never* be called when working with converted (meta)data /*/
$this->mockAdapter->expects($this->never())
->method($adapterMethod)
Expand All @@ -270,7 +273,7 @@ public function testRdfAdapterShouldCallInnerAdapterAndGraphWhenNonProxyMethodsA
->method($adapterMethod)
->willReturn(false)
;
} elseif ($method === 'getMetadata' || $method === 'read' || $method === 'readStream') {
} elseif ($method === 'read' || $method === 'readStream') {
$this->mockAdapter->expects($this->exactly($formatCount))
->method($adapterMethod)
;
Expand Down Expand Up @@ -373,13 +376,14 @@ public function testMetaDataShouldLookForMetaFileInDirectoryWhenCalledOnFileWith
$expected = 'a/longer/path/to/.meta';


$this->mockAdapter->expects($this->exactly(3))
$this->mockAdapter->expects($this->exactly(4))
->method('has')
->withConsecutive(
['a/longer/path/to/file.ext'],
['a/longer/path/to/file.ext.meta'],
[$expected],
)
->willReturnOnConsecutiveCalls(false, true, true)
->willReturnOnConsecutiveCalls(false, false, true, true)
;

$metadata = $adapter->getMetadata('a/longer/path/to/file.ext');
Expand Down Expand Up @@ -414,14 +418,15 @@ public function testMetaDataShouldLookForMetaFileInParentDirectoriesWhenCalledOn
$this->mockAdapter
->method('has')
->withConsecutive(
['a/longer/path/to/file.ext'],
['a/longer/path/to/file.ext.meta'],
['a/longer/path/to/.meta'],
['a/longer/path/.meta'],
['a/longer/.meta'],
['a/.meta'],
[$expected],
)
->willReturnOnConsecutiveCalls(false, false, false, false, false, true, true)
->willReturnOnConsecutiveCalls(false, false, false, false, false, false, true, true)
;

$metadata = $adapter->getMetadata('a/longer/path/to/file.ext');
Expand Down Expand Up @@ -506,14 +511,15 @@ public function testMetaDataShouldLookForAclFileInDirectoryWhenCalledOnFileWitho
$expected = '/a/longer/path/to/.acl';


$this->mockAdapter->expects($this->exactly(3))
$this->mockAdapter->expects($this->exactly(4))
->method('has')
->withConsecutive(
['/a/longer/path/to/file.ext'],
['/a/longer/path/to/file.ext.meta'],
['/a/longer/path/to/file.ext.acl'],
[$expected],
)
->willReturnOnConsecutiveCalls(true, false, true)
->willReturnOnConsecutiveCalls(true, true, false, true)
;

$metadata = $adapter->getMetadata('/a/longer/path/to/file.ext');
Expand Down Expand Up @@ -548,6 +554,7 @@ public function testMetaDataShouldLookForAclFileInParentDirectoriesWhenCalledOnF
$this->mockAdapter
->method('has')
->withConsecutive(
['/a/longer/path/to/file.ext'],
['/a/longer/path/to/file.ext.meta'],
['/a/longer/path/to/file.ext.acl'],
['/a/longer/path/to/.acl'],
Expand All @@ -556,7 +563,7 @@ public function testMetaDataShouldLookForAclFileInParentDirectoriesWhenCalledOnF
['/a/.acl'],
[$expected],
)
->willReturnOnConsecutiveCalls(true, false, false, false, false, false, true)
->willReturnOnConsecutiveCalls(true, true, false, false, false, false, false, true)
;

$metadata = $adapter->getMetadata('/a/longer/path/to/file.ext');
Expand Down

0 comments on commit 743b028

Please sign in to comment.