From 06230922357337ab3cc05c170aafe110bd7eadd7 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 8 Dec 2019 21:59:35 +1100 Subject: [PATCH] Code Coverage --- src/BunnyCDNAdapter.php | 30 ++++++++++++++++++++++++++++++ tests/BunnyCDNAdapterTest.php | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/BunnyCDNAdapter.php b/src/BunnyCDNAdapter.php index fa7ea25..2bd98c5 100644 --- a/src/BunnyCDNAdapter.php +++ b/src/BunnyCDNAdapter.php @@ -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 @@ -82,6 +85,7 @@ public function update($path, $contents, Config $config) } /** + * @codeCoverageIgnore * @param string $path * @param resource $resource * @param Config $config @@ -108,6 +112,7 @@ public function rename($path, $newpath) * @param string $path * @param string $newpath * @return bool + * @throws Exception */ public function copy($path, $newpath) { @@ -123,9 +128,11 @@ public function delete($path) { try { return !$this->bunnyCDNStorage->deleteObject($path); + // @codeCoverageIgnoreStart } catch (BunnyCDNStorageException $e) { return false; } + // @codeCoverageIgnoreEnd } /** @@ -136,9 +143,11 @@ public function deleteDir($dirname) { try { return !$this->bunnyCDNStorage->deleteObject($dirname); + // @codeCoverageIgnoreStart } catch (BunnyCDNStorageException $e) { return false; } + // @codeCoverageIgnoreEnd } /** @@ -159,9 +168,11 @@ public function createDir($dirname, Config $config) $url, $this->bunnyCDNStorage->storageZoneName . '/' . $dirname ); + // @codeCoverageIgnoreStart } catch (BunnyCDNStorageException $e) { return false; } + // @codeCoverageIgnoreEnd return true; } @@ -186,9 +197,11 @@ public function has($path) $file === null ); }, ARRAY_FILTER_USE_BOTH)) === 1; + // @codeCoverageIgnoreStart } catch (BunnyCDNStorageException $e) { return false; } + // @codeCoverageIgnoreEnd } /** @@ -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 */ @@ -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]; @@ -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 } /** @@ -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 */ @@ -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 } /** @@ -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 @@ -360,6 +389,7 @@ private function normalizePath($path, $isDirectory = NULL) } /** + * @codeCoverageIgnore * @param $haystack * @param $needle * @return bool diff --git a/tests/BunnyCDNAdapterTest.php b/tests/BunnyCDNAdapterTest.php index 2f55417..209604c 100644 --- a/tests/BunnyCDNAdapterTest.php +++ b/tests/BunnyCDNAdapterTest.php @@ -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()