From 2c726b8988cf0fe53f9e46c066dce7990d72ec9b Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Fri, 20 Jun 2014 15:25:51 +0200 Subject: [PATCH] don't disable constructor calls to mockups of classes that extend internal PHP classes --- .../Constraints/UniqueValidatorTest.php | 6 +++- .../Extension/Core/Type/FileTypeTest.php | 2 +- .../HttpFoundationRequestHandlerTest.php | 2 +- .../Tests/BinaryFileResponseTest.php | 8 ++--- .../Handler/MongoDbSessionHandlerTest.php | 32 +++++++++++-------- .../Tests/Constraints/FileValidatorTest.php | 8 ++--- .../Validator/Tests/Constraints/Fixtures/foo | 0 7 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 src/Symfony/Component/Validator/Tests/Constraints/Fixtures/foo diff --git a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueValidatorTest.php b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueValidatorTest.php index 9d0a75af5e..9980802642 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueValidatorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueValidatorTest.php @@ -76,8 +76,12 @@ class UniqueValidatorTest extends \PHPUnit_Framework_TestCase ->method('hasField') ->will($this->returnValue(true)) ; - $refl = $this->getMockBuilder('Doctrine\Common\Reflection\StaticReflectionProperty') + $reflParser = $this->getMockBuilder('Doctrine\Common\Reflection\StaticReflectionParser') ->disableOriginalConstructor() + ->getMock() + ; + $refl = $this->getMockBuilder('Doctrine\Common\Reflection\StaticReflectionProperty') + ->setConstructorArgs(array($reflParser, 'property-name')) ->setMethods(array('getValue')) ->getMock() ; diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php index 63556eb5a6..ed38ab2886 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/Type/FileTypeTest.php @@ -59,7 +59,7 @@ class FileTypeTest extends \Symfony\Component\Form\Test\TypeTestCase { $file = $this ->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile') - ->disableOriginalConstructor() + ->setConstructorArgs(array(__DIR__.'/../../../Fixtures/foo', 'foo')) ->getMock() ; $file diff --git a/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php b/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php index 2d5cf7764b..b25380aea7 100644 --- a/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/HttpFoundation/HttpFoundationRequestHandlerTest.php @@ -48,7 +48,7 @@ class HttpFoundationRequestHandlerTest extends AbstractRequestHandlerTest protected function getMockFile() { return $this->getMockBuilder('Symfony\Component\HttpFoundation\File\UploadedFile') - ->disableOriginalConstructor() + ->setConstructorArgs(array(__DIR__.'/../../Fixtures/foo', 'foo')) ->getMock(); } } diff --git a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php index 69b099885a..d7d1b03c3c 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/BinaryFileResponseTest.php @@ -180,16 +180,16 @@ class BinaryFileResponseTest extends ResponseTestCase $request->headers->set('X-Accel-Mapping', $mapping); $file = $this->getMockBuilder('Symfony\Component\HttpFoundation\File\File') - ->disableOriginalConstructor() - ->getMock(); + ->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') + $file->expects($this->any()) + ->method('getMTime') ->will($this->returnValue(time())); BinaryFileResponse::trustXSendFileTypeHeader(); diff --git a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php index d168ce6379..9577d52478 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/Session/Storage/Handler/MongoDbSessionHandlerTest.php @@ -34,7 +34,6 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase $mongoClass = (version_compare(phpversion('mongo'), '1.3.0', '<')) ? 'Mongo' : 'MongoClient'; $this->mongo = $this->getMockBuilder($mongoClass) - ->disableOriginalConstructor() ->getMock(); $this->options = array( @@ -76,9 +75,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase public function testWrite() { - $collection = $this->getMockBuilder('MongoCollection') - ->disableOriginalConstructor() - ->getMock(); + $collection = $this->createMongoCollectionMock(); $this->mongo->expects($this->once()) ->method('selectCollection') @@ -105,9 +102,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase public function testReplaceSessionData() { - $collection = $this->getMockBuilder('MongoCollection') - ->disableOriginalConstructor() - ->getMock(); + $collection = $this->createMongoCollectionMock(); $this->mongo->expects($this->once()) ->method('selectCollection') @@ -130,9 +125,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase public function testDestroy() { - $collection = $this->getMockBuilder('MongoCollection') - ->disableOriginalConstructor() - ->getMock(); + $collection = $this->createMongoCollectionMock(); $this->mongo->expects($this->once()) ->method('selectCollection') @@ -148,9 +141,7 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase public function testGc() { - $collection = $this->getMockBuilder('MongoCollection') - ->disableOriginalConstructor() - ->getMock(); + $collection = $this->createMongoCollectionMock(); $this->mongo->expects($this->once()) ->method('selectCollection') @@ -168,4 +159,19 @@ class MongoDbSessionHandlerTest extends \PHPUnit_Framework_TestCase $this->assertTrue($this->storage->gc(-1)); } + + private function createMongoCollectionMock() + { + + $mongoClient = $this->getMockBuilder('MongoClient') + ->getMock(); + $mongoDb = $this->getMockBuilder('MongoDB') + ->setConstructorArgs(array($mongoClient, 'database-name')) + ->getMock(); + $collection = $this->getMockBuilder('MongoCollection') + ->setConstructorArgs(array($mongoDb, 'collection-name')) + ->getMock(); + + return $collection; + } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php index 0ca98067d3..fcbbb04b83 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/FileValidatorTest.php @@ -165,7 +165,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase { $file = $this ->getMockBuilder('Symfony\Component\HttpFoundation\File\File') - ->disableOriginalConstructor() + ->setConstructorArgs(array(__DIR__.'/Fixtures/foo')) ->getMock() ; $file @@ -193,7 +193,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase { $file = $this ->getMockBuilder('Symfony\Component\HttpFoundation\File\File') - ->disableOriginalConstructor() + ->setConstructorArgs(array(__DIR__.'/Fixtures/foo')) ->getMock() ; $file @@ -221,7 +221,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase { $file = $this ->getMockBuilder('Symfony\Component\HttpFoundation\File\File') - ->disableOriginalConstructor() + ->setConstructorArgs(array(__DIR__.'/Fixtures/foo')) ->getMock() ; $file @@ -255,7 +255,7 @@ abstract class FileValidatorTest extends \PHPUnit_Framework_TestCase { $file = $this ->getMockBuilder('Symfony\Component\HttpFoundation\File\File') - ->disableOriginalConstructor() + ->setConstructorArgs(array(__DIR__.'/Fixtures/foo')) ->getMock() ; $file diff --git a/src/Symfony/Component/Validator/Tests/Constraints/Fixtures/foo b/src/Symfony/Component/Validator/Tests/Constraints/Fixtures/foo new file mode 100644 index 0000000000..e69de29bb2