Skip to content

Commit

Permalink
Fix deprecated method use in AssetFilter.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Nov 16, 2017
1 parent 8e746c6 commit 019f0d4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions src/Routing/Filter/AssetFilter.php
Expand Up @@ -82,7 +82,7 @@ public function beforeDispatch(Event $event)
$response = $event->getData('response');
$event->stopPropagation();

$response->modified(filemtime($assetFile));
$response = $response->withModified(filemtime($assetFile));
if ($response->checkNotModified($request)) {
return $response;
}
Expand Down Expand Up @@ -131,19 +131,19 @@ protected function _getAssetFile($url)
protected function _deliverAsset(ServerRequest $request, Response $response, $assetFile, $ext)
{
$compressionEnabled = $response->compress();
if ($response->type($ext) === $ext) {
if ($response->getType($ext) === $ext) {
$contentType = 'application/octet-stream';
$agent = $request->getEnv('HTTP_USER_AGENT');
if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent)) {
$contentType = 'application/octetstream';
}
$response->type($contentType);
$response = $response->withType($contentType);
}
if (!$compressionEnabled) {
$response->header('Content-Length', filesize($assetFile));
$response = $response->withHeader('Content-Length', filesize($assetFile));
}
$response->cache(filemtime($assetFile), $this->_cacheTime);
$response->file($assetFile);
$response = $response->withCache(filemtime($assetFile), $this->_cacheTime)
->withFile($assetFile);

return $response;
}
Expand Down
13 changes: 6 additions & 7 deletions tests/TestCase/Routing/Filter/AssetFilterTest.php
Expand Up @@ -72,10 +72,10 @@ public function testNotModified()
$event = new Event('DispatcherTest', $this, compact('request', 'response'));

ob_start();
$this->assertSame($response, $filter->beforeDispatch($event));
$response = $filter->beforeDispatch($event);
ob_end_clean();
$this->assertEquals(200, $response->statusCode());
$this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified());
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->getHeaderLine('Last-Modified'));

$response = $this->getMockBuilder('Cake\Http\Response')
->setMethods(['_sendHeader', 'checkNotModified', 'send'])
Expand All @@ -88,8 +88,8 @@ public function testNotModified()
$response->expects($this->never())->method('send');
$event = new Event('DispatcherTest', $this, compact('request', 'response'));

$this->assertSame($response, $filter->beforeDispatch($event));
$this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->modified());
$response = $filter->beforeDispatch($event);
$this->assertEquals($time->format('D, j M Y H:i:s') . ' GMT', $response->getHeaderLine('Last-Modified'));
}

/**
Expand Down Expand Up @@ -253,7 +253,6 @@ public function testAsset($url, $file)
$this->assertEquals($file, $result->read());

$expected = filesize($path);
$headers = $response->header();
$this->assertEquals($expected, $headers['Content-Length']);
$this->assertEquals($expected, $response->getHeaderLine('Content-Length'));
}
}

0 comments on commit 019f0d4

Please sign in to comment.