minor #11118 fix test src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php (1emming)

This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11118).

Discussion
----------

fix test src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php

src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php

| Q             | A
| ------------- | ---
| Bug fix?      | [no]
| New feature?  | [no]
| BC breaks?    | [no]
| Deprecations? | [no]
| Tests pass?   | [yes]
| Fixed tickets | []
| License       | MIT
| Doc PR        | []

When running the tests in the HTTPFoundation package these failed. I felt like fixen these so I can start working with all tests green in the package.

Commits
-------

9247ef5 fix test src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php
This commit is contained in:
Fabien Potencier 2014-06-15 10:49:34 +02:00
commit dd6c6a304d

View File

@ -19,14 +19,15 @@ class BinaryFileResponseTest extends ResponseTestCase
{ {
public function testConstruction() public function testConstruction()
{ {
$response = new BinaryFileResponse('README.md', 404, array('X-Header' => 'Foo'), true, null, true, true); $file = __DIR__ . '/../README.md';
$response = new BinaryFileResponse($file, 404, array('X-Header' => 'Foo'), true, null, true, true);
$this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(404, $response->getStatusCode());
$this->assertEquals('Foo', $response->headers->get('X-Header')); $this->assertEquals('Foo', $response->headers->get('X-Header'));
$this->assertTrue($response->headers->has('ETag')); $this->assertTrue($response->headers->has('ETag'));
$this->assertTrue($response->headers->has('Last-Modified')); $this->assertTrue($response->headers->has('Last-Modified'));
$this->assertFalse($response->headers->has('Content-Disposition')); $this->assertFalse($response->headers->has('Content-Disposition'));
$response = BinaryFileResponse::create('README.md', 404, array(), true, ResponseHeaderBag::DISPOSITION_INLINE); $response = BinaryFileResponse::create($file, 404, array(), true, ResponseHeaderBag::DISPOSITION_INLINE);
$this->assertEquals(404, $response->getStatusCode()); $this->assertEquals(404, $response->getStatusCode());
$this->assertFalse($response->headers->has('ETag')); $this->assertFalse($response->headers->has('ETag'));
$this->assertEquals('inline; filename="README.md"', $response->headers->get('Content-Disposition')); $this->assertEquals('inline; filename="README.md"', $response->headers->get('Content-Disposition'));
@ -37,13 +38,13 @@ class BinaryFileResponseTest extends ResponseTestCase
*/ */
public function testSetContent() public function testSetContent()
{ {
$response = new BinaryFileResponse('README.md'); $response = new BinaryFileResponse(__FILE__);
$response->setContent('foo'); $response->setContent('foo');
} }
public function testGetContent() public function testGetContent()
{ {
$response = new BinaryFileResponse('README.md'); $response = new BinaryFileResponse(__FILE__);
$this->assertFalse($response->getContent()); $this->assertFalse($response->getContent());
} }
@ -160,7 +161,7 @@ class BinaryFileResponseTest extends ResponseTestCase
$request->headers->set('X-Sendfile-Type', 'X-Sendfile'); $request->headers->set('X-Sendfile-Type', 'X-Sendfile');
BinaryFileResponse::trustXSendfileTypeHeader(); BinaryFileResponse::trustXSendfileTypeHeader();
$response = BinaryFileResponse::create('README.md'); $response = BinaryFileResponse::create(__DIR__ . '/../README.md');
$response->prepare($request); $response->prepare($request);
$this->expectOutputString(''); $this->expectOutputString('');
@ -187,9 +188,12 @@ class BinaryFileResponseTest extends ResponseTestCase
$file->expects($this->any()) $file->expects($this->any())
->method('isReadable') ->method('isReadable')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$file->expects($this->any())
->method('getMTime')
->will($this->returnValue(time()));
BinaryFileResponse::trustXSendFileTypeHeader(); BinaryFileResponse::trustXSendFileTypeHeader();
$response = new BinaryFileResponse('README.md'); $response = new BinaryFileResponse($file);
$reflection = new \ReflectionObject($response); $reflection = new \ReflectionObject($response);
$property = $reflection->getProperty('file'); $property = $reflection->getProperty('file');
$property->setAccessible(true); $property->setAccessible(true);
@ -209,6 +213,6 @@ class BinaryFileResponseTest extends ResponseTestCase
protected function provideResponse() protected function provideResponse()
{ {
return new BinaryFileResponse('README.md'); return new BinaryFileResponse(__DIR__ . '/../README.md');
} }
} }