Skip to content

Commit

Permalink
Code Coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
sifex committed Dec 8, 2019
1 parent 931e4ac commit 0623092
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions src/BunnyCDNAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ public function write($path, $contents, Config $config)
$url,
$this->bunnyCDNStorage->storageZoneName . '/' . $path
);
// @codeCoverageIgnoreStart
} catch (BunnyCDNStorageException $e) {
return false;
}
// @codeCoverageIgnoreEnd

return true;
}

/**
* @codeCoverageIgnore
* @param string $path
* @param resource $resource
* @param Config $config
Expand All @@ -82,6 +85,7 @@ public function update($path, $contents, Config $config)
}

/**
* @codeCoverageIgnore
* @param string $path
* @param resource $resource
* @param Config $config
Expand All @@ -108,6 +112,7 @@ public function rename($path, $newpath)
* @param string $path
* @param string $newpath
* @return bool
* @throws Exception
*/
public function copy($path, $newpath)
{
Expand All @@ -123,9 +128,11 @@ public function delete($path)
{
try {
return !$this->bunnyCDNStorage->deleteObject($path);
// @codeCoverageIgnoreStart
} catch (BunnyCDNStorageException $e) {
return false;
}
// @codeCoverageIgnoreEnd
}

/**
Expand All @@ -136,9 +143,11 @@ public function deleteDir($dirname)
{
try {
return !$this->bunnyCDNStorage->deleteObject($dirname);
// @codeCoverageIgnoreStart
} catch (BunnyCDNStorageException $e) {
return false;
}
// @codeCoverageIgnoreEnd
}

/**
Expand All @@ -159,9 +168,11 @@ public function createDir($dirname, Config $config)
$url,
$this->bunnyCDNStorage->storageZoneName . '/' . $dirname
);
// @codeCoverageIgnoreStart
} catch (BunnyCDNStorageException $e) {
return false;
}
// @codeCoverageIgnoreEnd

return true;
}
Expand All @@ -186,9 +197,11 @@ public function has($path)
$file === null
);
}, ARRAY_FILTER_USE_BOTH)) === 1;
// @codeCoverageIgnoreStart
} catch (BunnyCDNStorageException $e) {
return false;
}
// @codeCoverageIgnoreEnd
}

/**
Expand All @@ -205,14 +218,17 @@ public function read($path)
$this->normalizePath($this->bunnyCDNStorage->storageZoneName . '/' . $path),
stream_get_meta_data($temp_pointer)['uri']
);
// @codeCoverageIgnoreStart
} catch (BunnyCDNStorageException $e) {
return false;
}
// @codeCoverageIgnoreEnd

return file_get_contents(stream_get_meta_data($temp_pointer)['uri']);
}

/**
* @codeCoverageIgnore
* @param string $path
* @return array|false|void
*/
Expand Down Expand Up @@ -259,12 +275,16 @@ private function getIndividualFileMetadata($path)

// Check that the path isn't returning more than one file / folder
if (count($files) > 1) {
// @codeCoverageIgnoreStart
throw new UnreadableFileException('More than one file was returned for path:"' . $path . '", contact package author.');
// @codeCoverageIgnoreEnd
}

// Check 404
if (count($files) === 0) {
// @codeCoverageIgnoreStart
throw new FileNotFoundException('Could not find file: "' . $path . '".');
// @codeCoverageIgnoreEnd
}

return array_values($files)[0];
Expand All @@ -279,11 +299,13 @@ public function getMetadata($path)
{
try {
return get_object_vars($this->getIndividualFileMetadata($path));
// @codeCoverageIgnoreStart
} catch (FileNotFoundException $e) {
return false;
} catch (UnreadableFileException $e) {
return false;
}
// @codeCoverageIgnoreEnd
}

/**
Expand All @@ -295,14 +317,17 @@ public function getSize($path)
{
try {
return $this->getIndividualFileMetadata($path)->Length;
// @codeCoverageIgnoreStart
} catch (FileNotFoundException $e) {
return false;
} catch (UnreadableFileException $e) {
return false;
}
// @codeCoverageIgnoreEnd
}

/**
* @codeCoverageIgnore
* @param string $path
* @return array|false|void
*/
Expand All @@ -320,11 +345,13 @@ public function getTimestamp($path)
{
try {
return strtotime($this->getIndividualFileMetadata($path)->LastChanged);
// @codeCoverageIgnoreStart
} catch (FileNotFoundException $e) {
return false;
} catch (UnreadableFileException $e) {
return false;
}
// @codeCoverageIgnoreEnd
}

/**
Expand All @@ -341,9 +368,11 @@ private function normalizePath($path, $isDirectory = NULL)
if (!$this->endsWith($path, '/')) {
$path = $path . "/";
}
// @codeCoverageIgnoreStart
} else if ($this->endsWith($path, '/') && $path !== '/') {
throw new Exception('The requested path is invalid.');
}
// @codeCoverageIgnoreEnd
}

// Remove double slashes
Expand All @@ -360,6 +389,7 @@ private function normalizePath($path, $isDirectory = NULL)
}

/**
* @codeCoverageIgnore
* @param $haystack
* @param $needle
* @return bool
Expand Down
2 changes: 1 addition & 1 deletion tests/BunnyCDNAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function testDelete()
public function testDeleteDir()
{
$adapter = new BunnyCDNAdapter($this->getBunnyCDNMockObject());
$this->assertTrue($adapter->delete('directory'));
$this->assertTrue($adapter->deleteDir('directory'));
}

public function testCopy()
Expand Down

0 comments on commit 0623092

Please sign in to comment.