本文整理汇总了PHP中PHPUnit_Framework_MockObject_Generator::generate方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_MockObject_Generator::generate方法的具体用法?PHP PHPUnit_Framework_MockObject_Generator::generate怎么用?PHP PHPUnit_Framework_MockObject_Generator::generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_MockObject_Generator
的用法示例。
在下文中一共展示了PHPUnit_Framework_MockObject_Generator::generate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMock
/**
* Returns a mock object for the specified class.
*
* @param string $originalClassName
* @param array $methods
* @param array $arguments
* @param string $mockClassName
* @param boolean $callOriginalConstructor
* @param boolean $callOriginalClone
* @param boolean $callAutoload
* @return PHPUnit_Framework_MockObject_MockObject
* @throws InvalidArgumentException
* @since Method available since Release 3.0.0
*/
protected function getMock($originalClassName, $methods = array(), array $arguments = array(), $mockClassName = '', $callOriginalConstructor = TRUE, $callOriginalClone = TRUE, $callAutoload = TRUE)
{
if (!is_string($originalClassName)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
}
if (!is_string($mockClassName)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(4, 'string');
}
if (!is_array($methods) && !is_null($methods)) {
throw new InvalidArgumentException();
}
if ($mockClassName != '' && class_exists($mockClassName, FALSE)) {
throw new PHPUnit_Framework_Exception(sprintf('Class "%s" already exists.', $mockClassName));
}
$mock = PHPUnit_Framework_MockObject_Generator::generate($originalClassName, $methods, $mockClassName, $callOriginalClone, $callAutoload);
if (!class_exists($mock['mockClassName'], FALSE)) {
eval($mock['code']);
}
if ($callOriginalConstructor && !interface_exists($originalClassName, $callAutoload)) {
if (count($arguments) == 0) {
$mockObject = new $mock['mockClassName']();
} else {
$mockClass = new ReflectionClass($mock['mockClassName']);
$mockObject = $mockClass->newInstanceArgs($arguments);
}
} else {
// Use a trick to create a new object of a class
// without invoking its constructor.
$mockObject = unserialize(sprintf('O:%d:"%s":0:{}', strlen($mock['mockClassName']), $mock['mockClassName']));
}
$this->mockObjects[] = $mockObject;
return $mockObject;
}
示例2: generateMockClass
private static function generateMockClass($name, $extends)
{
$mock_class = \PHPUnit_Framework_MockObject_Generator::generate($extends, null, $name);
eval($mock_class['code']);
}