10000 minor #11230 Fix mocks to support >=5.5.14 and >=5.4.30 (jpauli) · symfony/symfony@84be8de · GitHub
[go: up one dir, main page]

Skip to content

Commit 84be8de

Browse files
committed
minor #11230 Fix mocks to support >=5.5.14 and >=5.4.30 (jpauli)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11230). Discussion ---------- Fix mocks to support >=5.5.14 and >=5.4.30 PHP 5.5.14 and PHP 5.4.30 disallow unseriliazing hand made strings for internal classes that forbids that (using zend_class_unserialize_deny) There was a bug before, PHP did not filter those strings, which could lead to security problems. Starting from 5.5.14 and 5.4.30 , PHP now reports an error when trying to unserialize such strings. php/php-src@2c88ae5 PHPUnit relies on this (wrong) behavior to create mock objects. This is a problem for SPlFileInfo. This PR fixes that. Commits ------- 1c5c694 Fix mocks to support >=5.5.14 and >=5.4.30
2 parents 803b06b + 1c5c694 commit 84be8de

File tree

3 files changed

+49
-15
lines changed

3 files changed

+49
-15
lines changed

src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
1515
use Symfony\Component\Form\Tests\AbstractRequestHandlerTest;
1616
use Symfony\Component\HttpFoundation\Request;
17+
use Symfony\Component\HttpFoundation\File\UploadedFile;
1718

1819
/**
1920
* @author Bernhard Schussek <bschussek@gmail.com>
@@ -47,8 +48,6 @@ protected function getRequestHandler()
4748

4849
protected function getMockFile()
4950
{
50-
return $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile')
51-
->setConstructorArgs(array(__DIR__.'/../../Fixtures/foo', 'foo'))
52-
->getMock();
51+
return new UploadedFile(__DIR__.'/../../Fixtures/foo', 'foo');
5352
}
5453
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\HttpFoundation\Resources\stubs;
13+
14+
use Symfony\Component\HttpFoundation\File\File as OrigFile;
15+
16+
class FakeFile extends OrigFile
17+
{
18+
private $realpath;
19+
20+
public function __construct($realpath, $path)
21+
{
22+
$this->realpath = $realpath;
23+
parent::__construct($path, false);
24+
}
25+
26+
public function isReadable()
27+
{
28+
return true;
29+
}
30+
31+
public function getRealpath()
32+
{
33+
return $this->realpath;
34+
}
35+
36+
public function getSize()
37+
{
38+
return 42;
39+
}
40+
41+
public function getMTime()
42+
{
43+
return time();
44+
}
45+
}

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\HttpFoundation\BinaryFileResponse;
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
17+
use Symfony\Component\HttpFoundation\Resources\stubs\FakeFile;
1718

1819
class BinaryFileResponseTest extends ResponseTestCase
1920
{
@@ -179,18 +180,7 @@ public function testXAccelMapping($realpath, $mapping, $virtual)
179180
$request->headers->set('X-Sendfile-Type', 'X-Accel-Redirect');
180181
$request->headers->set('X-Accel-Mapping', $mapping);
181182

182-
$file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File')
183-
->setConstructorArgs(array(__DIR__.'/File/Fixtures/test'))
184-
->getMock();
185-
$file->expects($this->any())
186-
->method('getRealPath')
187-
->will($this->returnValue($realpath));
188-
$file->expects($this->any())
189-
->method('isReadable')
190-
->will($this->returnValue(true));
191-
$file->expects($this->any())
192-
->method('getMTime')
193-
->will($this->returnValue(time()));
183+
$file = new FakeFile($realpath, __DIR__.'/File/Fixtures/test');
194184

195185
BinaryFileResponse::trustXSendFileTypeHeader();
196186
$response = new BinaryFileResponse($file);

0 commit comments

Comments
 (0)
0