From 0dc623b62510351236abb1c43a1a00aa671aa553 Mon Sep 17 00:00:00 2001 From: ytetsuro Date: Fri, 5 Oct 2018 01:58:05 +0900 Subject: [PATCH] refacotr: update the exception style. Signed-off-by: ytetsuro --- system/HTTP/DownloadResponse.php | 12 +++++------- tests/system/HTTP/DownloadResponseTest.php | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/system/HTTP/DownloadResponse.php b/system/HTTP/DownloadResponse.php index 921055d9402f..42be850713eb 100644 --- a/system/HTTP/DownloadResponse.php +++ b/system/HTTP/DownloadResponse.php @@ -36,8 +36,7 @@ * @filesource */ use CodeIgniter\HTTP\Exceptions\HTTPException; -use BadMethodCallException; -use LogicException; +use CodeIgniter\Exceptions\DownloadException; use CodeIgniter\Files\File; use Config\Mimes; @@ -107,7 +106,7 @@ public function setBinary(string $binary) { if ($this->file !== null) { - throw new BadMethodCallException('When setting filepath can not set binary.'); + throw DownloadException::forCannotSetBinary(); } $this->binary = $binary; @@ -122,7 +121,7 @@ public function setFilePath(string $filepath) { if ($this->binary !== null) { - throw new BadMethodCallException('When setting binary can not set filepath.'); + throw DownloadException::forCannotSetFilePath($filepath); } $this->file = new File($filepath, true); @@ -368,8 +367,7 @@ public function noCache(): self */ public function setCache(array $options = []) { - // @todo: Should I make exceptions? - throw new BadMethodCallException('It does not supported caching for downloading.'); + throw DownloadException::forCannotSetCache(); } //-------------------------------------------------------------------- @@ -489,7 +487,7 @@ public function sendBody() return $this->sendBodyByFilePath(); } - throw new LogicException('Not found download body source.'); + throw DownloadException::forNotFoundDownloadSource(); } /** diff --git a/tests/system/HTTP/DownloadResponseTest.php b/tests/system/HTTP/DownloadResponseTest.php index b434f96d550e..c12989f708c2 100644 --- a/tests/system/HTTP/DownloadResponseTest.php +++ b/tests/system/HTTP/DownloadResponseTest.php @@ -4,9 +4,7 @@ use CodeIgniter\Files\Exceptions\FileNotFoundException; use DateTime; use DateTimeZone; -use BadMethodCallException; -use InvalidArgumentException; -use LogicException; +use CodeIgniter\Exceptions\DownloadException; class DownloadResponseTest extends \CIUnitTestCase { @@ -119,7 +117,7 @@ public function testCantSetCache() { $response = new DownloadResponse('unit-test.txt', true); - $this->expectException(BadMethodCallException::class); + $this->expectException(DownloadException::class); $response->setCache(); } @@ -127,7 +125,7 @@ public function testWhenFilepathIsSetBinaryCanNotBeSet() { $response = new DownloadResponse('unit-test.txt', true); - $this->expectException(BadMethodCallException::class); + $this->expectException(DownloadException::class); $response->setFilePath(__FILE__); $response->setBinary('test'); } @@ -136,7 +134,7 @@ public function testWhenBinaryIsSetFilepathCanNotBeSet() { $response = new DownloadResponse('unit-test.txt', true); - $this->expectException(BadMethodCallException::class); + $this->expectException(DownloadException::class); $response->setBinary('test'); $response->setFilePath(__FILE__); } @@ -248,7 +246,7 @@ public function testThrowExceptionWhenNoSetDownloadSource() { $response = new DownloadResponse('unit-test.php', false); - $this->expectException(LogicException::class); + $this->expectException(DownloadException::class); $response->sendBody(); } }