Skip to content

Commit

Permalink
refacotr: update the exception style.
Browse files Browse the repository at this point in the history
Signed-off-by: ytetsuro <phper.0o0@gmail.com>
  • Loading branch information
ytetsuro committed Oct 4, 2018
1 parent df83c7e commit 0dc623b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
12 changes: 5 additions & 7 deletions system/HTTP/DownloadResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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();
}

//--------------------------------------------------------------------
Expand Down Expand Up @@ -489,7 +487,7 @@ public function sendBody()
return $this->sendBodyByFilePath();
}

throw new LogicException('Not found download body source.');
throw DownloadException::forNotFoundDownloadSource();
}

/**
Expand Down
12 changes: 5 additions & 7 deletions tests/system/HTTP/DownloadResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -119,15 +117,15 @@ public function testCantSetCache()
{
$response = new DownloadResponse('unit-test.txt', true);

$this->expectException(BadMethodCallException::class);
$this->expectException(DownloadException::class);
$response->setCache();
}

public function testWhenFilepathIsSetBinaryCanNotBeSet()
{
$response = new DownloadResponse('unit-test.txt', true);

$this->expectException(BadMethodCallException::class);
$this->expectException(DownloadException::class);
$response->setFilePath(__FILE__);
$response->setBinary('test');
}
Expand All @@ -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__);
}
Expand Down Expand Up @@ -248,7 +246,7 @@ public function testThrowExceptionWhenNoSetDownloadSource()
{
$response = new DownloadResponse('unit-test.php', false);

$this->expectException(LogicException::class);
$this->expectException(DownloadException::class);
$response->sendBody();
}
}

0 comments on commit 0dc623b

Please sign in to comment.