本文整理汇总了PHP中PHPUnit_Framework_TestCase::returnSelf方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_TestCase::returnSelf方法的具体用法?PHP PHPUnit_Framework_TestCase::returnSelf怎么用?PHP PHPUnit_Framework_TestCase::returnSelf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_TestCase
的用法示例。
在下文中一共展示了PHPUnit_Framework_TestCase::returnSelf方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
/**
* Create a new mock of the curlbuilder and return
* the given filename as content
*
* @access public
* @param PHPUnit_Framework_TestCase $instance
* @return mock
*/
public static function create($instance)
{
$reflection = new \ReflectionMethod($instance, $instance->getName());
$doc_block = $reflection->getDocComment();
$responsefile = self::parseDocBlock($doc_block, '@responsefile');
$responsecode = self::parseDocBlock($doc_block, '@responsecode');
$defaultheaders = array("X-Ratelimit-Limit" => "1000", "X-Ratelimit-Remaining" => "998", "X-Varnish" => "4059929980");
$skipmock = self::parseDocBlock($doc_block, '@skipmock');
if (empty($responsecode)) {
$responsecode = [201];
}
if (empty($responsefile)) {
$responsefile = [$instance->getName()];
}
// Setup Curlbuilder mock
$curlbuilder = $instance->getMockBuilder("\\DirkGroenen\\Pinterest\\Utils\\CurlBuilder")->getMock();
$curlbuilder->expects($instance->any())->method('create')->will($instance->returnSelf());
// Build response file path
$responseFilePath = __DIR__ . '/../responses/' . (new \ReflectionClass($instance))->getShortName() . '/' . $responsefile[0] . ".json";
if (file_exists($responseFilePath)) {
$curlbuilder->expects($instance->once())->method('execute')->will($instance->returnValue(file_get_contents($responseFilePath)));
}
$curlbuilder->expects($instance->any())->method('getInfo')->will($instance->returnValue($responsecode[0]));
return $curlbuilder;
}
示例2: getBuilder
/**
* Get data object builder
*
* @param string $className
* @param array $arguments
* @return object
*/
protected function getBuilder($className, array $arguments)
{
$objectFactory = $this->_testObject->getMock('Magento\\Framework\\Api\\ObjectFactory', [], [], '', false);
if (!isset($arguments['objectFactory'])) {
$arguments['objectFactory'] = $objectFactory;
}
$constructArguments = $this->getConstructArguments($className, $arguments);
$reflectionClass = new \ReflectionClass($className);
$builderObject = $reflectionClass->newInstanceArgs($constructArguments);
$objectFactory->expects($this->_testObject->any())->method('populateWithArray')->will($this->_testObject->returnSelf());
$objectFactory->expects($this->_testObject->any())->method('populate')->will($this->_testObject->returnSelf());
$objectFactory->expects($this->_testObject->any())->method('create')->will($this->_testObject->returnCallback(function ($className, $arguments) {
$reflectionClass = new \ReflectionClass($className);
$constructorMethod = $reflectionClass->getConstructor();
$parameters = $constructorMethod->getParameters();
$args = [];
foreach ($parameters as $parameter) {
$parameterName = $parameter->getName();
if (isset($arguments[$parameterName])) {
$args[] = $arguments[$parameterName];
} else {
if ($parameter->isArray()) {
$args[] = [];
} elseif ($parameter->allowsNull()) {
$args[] = null;
} else {
$mock = $this->_getMockWithoutConstructorCall($parameter->getClass()->getName());
$args[] = $mock;
}
}
}
return $reflectionClass->newInstanceArgs($args);
}));
return $builderObject;
}
示例3: getPlainMock
/**
* Get a plain command-object mock
*
* @param string $sReturn
*
* @return \Testy\Util\Command
*/
public static function getPlainMock($sReturn = '')
{
$oMockBuilder = new \PHPUnit_Framework_MockObject_Generator();
$oCommandMock = $oMockBuilder->getMock('\\Testy\\Util\\Command');
$oCommandMock->expects(\PHPUnit_Framework_TestCase::any())->method('execute')->will(\PHPUnit_Framework_TestCase::returnSelf());
$oCommandMock->expects(\PHPUnit_Framework_TestCase::any())->method('reset')->will(\PHPUnit_Framework_TestCase::returnSelf());
$oCommandMock->expects(\PHPUnit_Framework_TestCase::any())->method('setCommand')->will(\PHPUnit_Framework_TestCase::returnSelf());
$oCommandMock->expects(\PHPUnit_Framework_TestCase::any())->method('get')->will(\PHPUnit_Framework_TestCase::returnValue($sReturn));
return $oCommandMock;
}
示例4: getBuilder
/**
* Get data object builder
*
* @param string $className
* @param array $arguments
* @return object
*/
protected function getBuilder($className, array $arguments)
{
$objectFactory = $this->_testObject->getMock('Magento\\Framework\\Api\\ObjectFactory', [], [], '', false);
if (!isset($arguments['objectFactory'])) {
$arguments['objectFactory'] = $objectFactory;
}
$constructArguments = $this->getConstructArguments($className, $arguments);
$reflectionClass = new \ReflectionClass($className);
$builderObject = $reflectionClass->newInstanceArgs($constructArguments);
$objectFactory->expects($this->_testObject->any())->method('populateWithArray')->will($this->_testObject->returnSelf());
$objectFactory->expects($this->_testObject->any())->method('populate')->will($this->_testObject->returnSelf());
$objectFactory->expects($this->_testObject->any())->method('create')->will($this->_testObject->returnCallback(function ($className, $arguments) {
$reflectionClass = new \ReflectionClass($className);
return $reflectionClass->newInstanceArgs($arguments);
}));
return $builderObject;
}
示例5: create
/**
* Create a new mock of the curlbuilder and return
* the given filename as content
*
* @access public
* @param PHPUnit_Framework_TestCase $instance
* @return mock
*/
public static function create($instance)
{
$reflection = new \ReflectionMethod($instance, $instance->getName());
$doc_block = $reflection->getDocComment();
$responsefile = self::parseDocBlock($doc_block, '@responsefile');
$responsecode = self::parseDocBlock($doc_block, '@responsecode');
if (empty($responsecode)) {
$responsecode = [201];
}
if (empty($responsefile)) {
$responsefile = [$instance->getName()];
}
// Setup Curlbuilder mock
$curlbuilder = $instance->getMockBuilder("\\DirkGroenen\\Pinterest\\Utils\\CurlBuilder")->getMock();
$curlbuilder->expects($instance->once())->method('create')->will($instance->returnSelf());
$curlbuilder->expects($instance->once())->method('execute')->will($instance->returnValue(file_get_contents(__DIR__ . '/../responses/' . (new \ReflectionClass($instance))->getShortName() . '/' . $responsefile[0] . ".json")));
$curlbuilder->expects($instance->any())->method('getInfo')->will($instance->returnValue($responsecode[0]));
return $curlbuilder;
}
示例6: returnSelf
/**
* Returns the current object.
*
* This method is useful when mocking a fluent interface.
*
* @return PHPUnit_Framework_MockObject_Stub_ReturnSelf
* @since Method available since Release 3.6.0
*/
function returnSelf()
{
return PHPUnit_Framework_TestCase::returnSelf();
}