From 1c5c694196f8ad8ba12b48cdc939d60e8012c4df Mon Sep 17 00:00:00 2001 From: Julien Pauli Date: Wed, 25 Jun 2014 18:49:15 +0200 Subject: [PATCH] Fix mocks to support >=5.5.14 and >=5.4.30 --- .../HttpFoundationRequestHandlerTest.php | 5 +-- .../Resources/stubs/FakeFile.php | 45 +++++++++++++++++++ .../Tests/BinaryFileResponseTest.php | 14 +----- 3 files changed, 49 insertions(+), 15 deletions(-) create mode 100644 src/Symfony/Component/HttpFoundation/Resources/stubs/FakeFile.php diff --git a/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php b/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php index b25380aea7..cf5d63d90e 100644 --- a/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php @@ -14,6 +14,7 @@ namespace Symfony\Component\Form\Tests\Extension\HttpFoundation; use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler; use Symfony\Component\Form\Tests\AbstractRequestHandlerTest; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\File\UploadedFile; /** * @author Bernhard Schussek @@ -47,8 +48,6 @@ class HttpFoundationRequestHandlerTest extends AbstractRequestHandlerTest protected function getMockFile() { - return $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile') - ->setConstructorArgs(array(__DIR__.'/../../Fixtures/foo', 'foo')) - ->getMock(); + return new UploadedFile(__DIR__.'/../../Fixtures/foo', 'foo'); } } diff --git a/src/Symfony/Component/HttpFoundation/Resources/stubs/FakeFile.php b/src/Symfony/Component/HttpFoundation/Resources/stubs/FakeFile.php new file mode 100644 index 0000000000..0aecc20b08 --- /dev/null +++ b/src/Symfony/Component/HttpFoundation/Resources/stubs/FakeFile.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\HttpFoundation\Resources\stubs; + +use Symfony\Component\HttpFoundation\File\File as OrigFile; + +class FakeFile extends OrigFile +{ + private $realpath; + + public function __construct($realpath, $path) + { + $this->realpath = $realpath; + parent::__construct($path, false); + } + + public function isReadable() + { + return true; + } + + public function getRealpath() + { + return $this->realpath; + } + + public function getSize() + { + return 42; + } + + public function getMTime() + { + return time(); + } +} diff --git a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php index d7d1b03c3c..397192b885 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php @@ -14,6 +14,7 @@ namespace Symfony\Component\HttpFoundation\Tests; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\ResponseHeaderBag; +use Symfony\Component\HttpFoundation\Resources\stubs\FakeFile; class BinaryFileResponseTest extends ResponseTestCase { @@ -179,18 +180,7 @@ class BinaryFileResponseTest extends ResponseTestCase $request->headers->set('X-Sendfile-Type', 'X-Accel-Redirect'); $request->headers->set('X-Accel-Mapping', $mapping); - $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File') - ->setConstructorArgs(array(__DIR__.'/File/Fixtures/test')) - ->getMock(); - $file->expects($this->any()) - ->method('getRealPath') - ->will($this->returnValue($realpath)); - $file->expects($this->any()) - ->method('isReadable') - ->will($this->returnValue(true)); - $file->expects($this->any()) - ->method('getMTime') - ->will($this->returnValue(time())); + $file = new FakeFile($realpath, __DIR__.'/File/Fixtures/test'); BinaryFileResponse::trustXSendFileTypeHeader(); $response = new BinaryFileResponse($file);