Skip to content

Commit

Permalink
refactor: remove ResponseInsterface.
Browse files Browse the repository at this point in the history
  • Loading branch information
ytetsuro committed Oct 8, 2018
1 parent 0dc623b commit da37bff
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 167 deletions.
111 changes: 1 addition & 110 deletions system/HTTP/DownloadResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
use CodeIgniter\Files\File;
use Config\Mimes;

class DownloadResponse extends Message implements ResponseInterface
class DownloadResponse extends Message
{
/**
* Download file name
Expand Down Expand Up @@ -220,55 +220,6 @@ public function getStatusCode(): int
{
return 200;
}

//--------------------------------------------------------------------

/**
* Return an instance with the specified status code and, optionally, reason phrase.
*
* If no reason phrase is specified, will default recommended reason phrase for
* the response's status code.
*
* @see http://tools.ietf.org/html/rfc7231#section-6
* @see http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
*
* @param int $code The 3-digit integer result code to set.
* @param string $reason The reason phrase to use with the
* provided status code; if none is provided, will
* default to the IANA name.
*
* @return self
* @throws \InvalidArgumentException For invalid status code arguments.
*/
public function setStatusCode(int $code, string $reason = '')
{
if ($code !== 200)
{
throw HTTPException::forInvalidStatusCode($code);
}

if ( ! empty($reason) && $this->reason !== $reason)
{
$this->reason = $reason;
}
}

//--------------------------------------------------------------------

/**
* Gets the response response phrase associated with the status code.
*
* @see http://tools.ietf.org/html/rfc7231#section-6
* @see http://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml
*
* @return string
*/
public function getReason(): string
{
return $this->reason;
}

//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Convenience Methods
//--------------------------------------------------------------------
Expand Down Expand Up @@ -335,66 +286,6 @@ public function noCache(): self
return $this;
}

//--------------------------------------------------------------------

/**
* A shortcut method that allows the developer to set all of the
* cache-control headers in one method call.
*
* The options array is used to provide the cache-control directives
* for the header. It might look something like:
*
* $options = [
* 'max-age' => 300,
* 's-maxage' => 900
* 'etag' => 'abcde',
* ];
*
* Typical options are:
* - etag
* - last-modified
* - max-age
* - s-maxage
* - private
* - public
* - must-revalidate
* - proxy-revalidate
* - no-transform
*
* @param array $options
*
* @return Response
*/
public function setCache(array $options = [])
{
throw DownloadException::forCannotSetCache();
}

//--------------------------------------------------------------------

/**
* Sets the Last-Modified date header.
*
* $date can be either a string representation of the date or,
* preferably, an instance of DateTime.
*
* @param string|\DateTime $date
*/
public function setLastModified($date)
{
if ($date instanceof \DateTime)
{
$date->setTimezone(new \DateTimeZone('UTC'));
$this->setHeader('Last-Modified', $date->format('D, d M Y H:i:s').' GMT');
}
elseif (is_string($date))
{
$this->setHeader('Last-Modified', $date);
}

return $this;
}

//--------------------------------------------------------------------
//--------------------------------------------------------------------
// Output Methods
Expand Down
57 changes: 0 additions & 57 deletions tests/system/HTTP/DownloadResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,6 @@ public function testCanGetStatusCode()
$this->assertSame(200, $response->getStatusCode());
}

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

$response->setStatusCode(200, 'Not the mama');

$this->assertSame('Not the mama', $response->getReason());
}

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

$this->expectException(HTTPException::class);
$response->setStatusCode(999);
}

public function testSetDateRemembersDateInUTC()
{
$response = new DownloadResponse('unit-test.txt', true);
Expand All @@ -54,38 +37,6 @@ public function testSetDateRemembersDateInUTC()
$this->assertEquals($date->format('D, d M Y H:i:s').' GMT', $header);
}

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

$response->setLastModified(DateTime::createFromFormat('Y-m-d', '2000-03-10'));

$date = DateTime::createFromFormat('Y-m-d', '2000-03-10');
$date->setTimezone(new DateTimeZone('UTC'));

$header = $response->getHeaderLine('Last-Modified');

$this->assertEquals($date->format('D, d M Y H:i:s').' GMT', $header);
}

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

$response->setLastModified('2000-03-10 10:23:45');

$header = $response->getHeaderLine('Last-Modified');

$this->assertEquals('2000-03-10 10:23:45', $header);
}

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

$this->assertInstanceOf(DownloadResponse::class, $response);
}

public function testSetContentType()
{
$response = new DownloadResponse('unit-test.txt', true);
Expand Down Expand Up @@ -113,14 +64,6 @@ public function testNoCache()
$this->assertSame('private, no-transform, no-store, must-revalidate', $response->getHeaderLine('Cache-control'));
}

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

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

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

0 comments on commit da37bff

Please sign in to comment.