diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index 288d5610f99..5cda8ab9f05 100755 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -231,7 +231,7 @@ abstract class PHPUnit_Framework_TestCase extends PHPUnit_Framework_Assert imple /** * @var array */ - private $mockObjectGenerator; + private $mockObjectGenerator = null; /** * @var integer @@ -313,7 +313,6 @@ public function __construct($name = null, array $data = array(), $dataName = '') $this->data = $data; $this->dataName = $dataName; - $this->mockObjectGenerator = new PHPUnit_Framework_MockObject_Generator; } /** @@ -1298,7 +1297,7 @@ protected function setLocale() */ public function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false, $callOriginalMethods = false) { - $mockObject = $this->mockObjectGenerator->getMock( + $mockObject = $this->getMockObjectGenerator()->getMock( $originalClassName, $methods, $arguments, @@ -1379,7 +1378,7 @@ protected function getMockClass($originalClassName, $methods = array(), array $a */ public function getMockForAbstractClass($originalClassName, array $arguments = array(), $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = array(), $cloneArguments = false) { - $mockObject = $this->mockObjectGenerator->getMockForAbstractClass( + $mockObject = $this->getMockObjectGenerator()->getMockForAbstractClass( $originalClassName, $arguments, $mockClassName, @@ -1417,7 +1416,7 @@ protected function getMockFromWsdl($wsdlFile, $originalClassName = '', $mockClas if (!class_exists($originalClassName)) { eval( - $this->mockObjectGenerator->generateClassFromWsdl( + $this->getMockObjectGenerator()->generateClassFromWsdl( $wsdlFile, $originalClassName, $methods, $options ) ); @@ -1453,7 +1452,7 @@ protected function getMockFromWsdl($wsdlFile, $originalClassName = '', $mockClas */ public function getMockForTrait($traitName, array $arguments = array(), $mockClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $mockedMethods = array(), $cloneArguments = false) { - $mockObject = $this->mockObjectGenerator->getMockForTrait( + $mockObject = $this->getMockObjectGenerator()->getMockForTrait( $traitName, $arguments, $mockClassName, @@ -1485,7 +1484,7 @@ public function getMockForTrait($traitName, array $arguments = array(), $mockCla */ protected function getObjectForTrait($traitName, array $arguments = array(), $traitClassName = '', $callOriginalConstructor = true, $callOriginalClone = true, $callAutoload = true, $cloneArguments = false) { - return $this->mockObjectGenerator->getObjectForTrait( + return $this->getMockObjectGenerator()->getObjectForTrait( $traitName, $arguments, $traitClassName, @@ -1920,4 +1919,18 @@ public function hookAfterMethod($name) { $this->afterMethods[] = $name; } + + /** + * Get the mock object generator, creating it if it doesn't exist. + * + * @return PHPUnit_Framework_MockObject_Generator + */ + protected function getMockObjectGenerator() + { + if (null === $this->mockObjectGenerator) { + $this->mockObjectGenerator = new PHPUnit_Framework_MockObject_Generator; + } + + return $this->mockObjectGenerator; + } }