当前位置: 首页>>代码示例>>PHP>>正文


PHP PHPUnit_Framework_TestCase::returnCallback方法代码示例

本文整理汇总了PHP中PHPUnit_Framework_TestCase::returnCallback方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_TestCase::returnCallback方法的具体用法?PHP PHPUnit_Framework_TestCase::returnCallback怎么用?PHP PHPUnit_Framework_TestCase::returnCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PHPUnit_Framework_TestCase的用法示例。


在下文中一共展示了PHPUnit_Framework_TestCase::returnCallback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mockLocalDriver

function mockLocalDriver(PHPUnit_Framework_TestCase $testcase, $root)
{
    $driver = $testcase->getMockBuilder(LocalDriver::class)->setConstructorArgs([$root])->setMethods(['instantiateFile', 'instantiateDir'])->getMockForAbstractClass();
    $driver->method('instantiateFile')->will($testcase->returnCallback(function ($path) use($driver) {
        return new LocalFile($driver, $path);
    }));
    $driver->method('instantiateDir')->will($testcase->returnCallback(function ($path) use($driver) {
        return new LocalDirectory($driver, $path);
    }));
    return $driver;
}
开发者ID:bapcat,项目名称:persist,代码行数:11,代码来源:_mocks.php

示例2: getAuthenticationSubject

 /**
  *
  * @param string $username
  * @return \Nethgui\Authorization\UserInterface
  */
 public static function getAuthenticationSubject(\PHPUnit_Framework_TestCase $testcase, $username = FALSE, $groups = array())
 {
     $subject = $testcase->getMock('Nethgui\\Authorization\\User', array('authenticate', 'isAuthenticated', 'getCredential', 'hasCredential', 'getLanguageCode', 'asAuthorizationString', 'getAuthorizationAttribute'));
     $subject->expects($testcase->any())->method('isAuthenticated')->will($testcase->returnValue(is_string($username)));
     $subject->expects($testcase->any())->method('getCredential')->with('username')->will($testcase->returnValue(is_string($username) ? $username : NULL));
     $subject->expects($testcase->any())->method('hasCredential')->with('username')->will($testcase->returnValue(is_string($username)));
     $getAttribute = function ($attName) use($username, $groups) {
         if ($attName === 'username') {
             return is_string($username) ? $username : NULL;
         } elseif ($attName === 'authenticated') {
             return is_string($username) ? TRUE : FALSE;
         } elseif ($attName == 'groups') {
             return $groups;
         }
         return NULL;
     };
     $subject->expects($testcase->any())->method('getAuthorizationAttribute')->withAnyParameters()->will($testcase->returnCallback($getAttribute));
     $subject->expects($testcase->any())->method('asAuthorizationString')->will($testcase->returnValue(is_string($username) ? $username : 'Anonymous'));
     $subject->hasCredential('username');
     $subject->getCredential('username');
     $subject->isAuthenticated();
     $subject->getAuthorizationAttribute('username');
     $subject->asAuthorizationString();
     return $subject;
 }
开发者ID:SystemEd-Jacob,项目名称:nethgui,代码行数:30,代码来源:MockFactory.php

示例3: buildMethod

 /**
  * @param string $methodName
  */
 private function buildMethod($methodName)
 {
     $self = $this;
     $callBackFunction = function () use($self, $methodName) {
         $inputParams = func_get_args();
         $return = $self->getReturn($methodName);
         $returnValue = $return['value'];
         $returnType = $return['type'];
         $self->addInvocation($methodName, $inputParams);
         switch ($returnType) {
             case 'exception':
                 throw $returnValue;
                 break;
             case 'value':
                 return $returnValue;
                 break;
             case 'self':
                 return $self->getMock();
                 break;
             case 'argument':
                 return isset($inputParams[$returnValue]) ? $inputParams[$returnValue] : null;
                 break;
             case 'callback':
                 $inputParams[] = count($self->getInvocations($methodName));
                 return call_user_func_array($returnValue, $inputParams);
                 break;
             default:
                 throw new Exception("unknown method return type {$returnType}");
                 break;
         }
     };
     $method = $this->mock->expects($this->testCase->any());
     $method->method($methodName);
     $method->will($this->testCase->returnCallback($callBackFunction));
 }
开发者ID:jelito,项目名称:devstack,代码行数:38,代码来源:Builder.php

示例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);
         $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;
 }
开发者ID:IlyaGluschenko,项目名称:test001,代码行数:42,代码来源:ObjectManager.php

示例5: mockFileWriter

function mockFileWriter(PHPUnit_Framework_TestCase $testcase, File $file)
{
    $in = $testcase->getMockForAbstractClass(FileWriter::class, [$file]);
    $in->method('write')->will($testcase->returnCallback(function ($data) {
        return strlen($data);
    }));
    return $in;
}
开发者ID:bapcat,项目名称:persist,代码行数:8,代码来源:_mocks.php

示例6: mockFileOutputStream

function mockFileOutputStream(PHPUnit_Framework_TestCase $testcase, File $file)
{
    $in = $testcase->getMockForAbstractClass('BapCat\\Interfaces\\Persist\\FileOutputStream', [$file]);
    $in->method('write')->will($testcase->returnCallback(function ($data) {
        return strlen($data);
    }));
    return $in;
}
开发者ID:bapcat,项目名称:interfaces,代码行数:8,代码来源:_mocks.php

示例7: getMysqli

 public static function getMysqli(\PHPUnit_Framework_TestCase $testCase)
 {
     $mysqli = $testCase->getMockBuilder('\\mysqli')->disableOriginalConstructor()->getMock();
     $mysqli->method('real_escape_string')->will($testCase->returnCallback(function ($v) {
         return addcslashes($v, "\"\n\r\\'");
         // not safe implementation!!!
     }));
     return $mysqli;
 }
开发者ID:repo2,项目名称:query-builder,代码行数:9,代码来源:Mock.php

示例8: addMethodExpectation

 protected function addMethodExpectation(\ReflectionClass $reflection, MockObject $mock, array $expectation)
 {
     if (is_null($expectation['will'])) {
         return;
     }
     $expect = $reflection->hasMethod($expectation['method']) && $reflection->getMethod($expectation['method'])->isStatic() ? $mock::staticExpects($expectation['expects']) : $mock->expects($expectation['expects']);
     $expect->method($expectation['method'])->will($expectation['will'] instanceof \Closure ? PhpUnitTestCase::returnCallback(version_compare(PHP_VERSION, '5.4.0', '>=') ? $expectation['will']->bindTo($mock, $reflection->getName()) : $expectation['will']) : $expectation['will']);
     if (!is_null($expectation['with'])) {
         call_user_func_array(array($expect, 'with'), $expectation['with']);
     }
 }
开发者ID:ptrofimov,项目名称:xpmock,代码行数:11,代码来源:Base.php

示例9: assignMockCallbacks

 /**
  * Assigns mock callbacks to methods.
  *
  * This method assumes that the mock callback is named {mock}{method name}.
  *
  * @param   \PHPUnit_Framework_MockObject_MockObject  $mockObject  The mock object that the callbacks are being assigned to.
  * @param   \PHPUnit_Framework_TestCase               $test        The test.
  * @param   array                                     $array       An array of methods names to mock with callbacks.
  *
  * @return  void
  *
  * @since   2.0
  */
 public static function assignMockCallbacks(\PHPUnit_Framework_MockObject_MockObject $mockObject, \PHPUnit_Framework_TestCase $test, $array)
 {
     foreach ($array as $index => $method) {
         if (is_array($method)) {
             $methodName = $index;
             $callback = $method;
         } else {
             $methodName = $method;
             $callback = array(get_called_class(), 'mock' . $method);
         }
         $mockObject->expects($test->any())->method($methodName)->will($test->returnCallback($callback));
     }
 }
开发者ID:lyrasoft,项目名称:lyrasoft.github.io,代码行数:26,代码来源:TestHelper.php

示例10: init

 public function init()
 {
     $wikiaAppArgs = array();
     $globalRegistryMock = null;
     $functionWrapperMock = null;
     $globalRegistryMock = $this->testCase->getMock('WikiaGlobalRegistry', array('get', 'set'));
     $globalRegistryMock->expects($this->testCase->any())->method('get')->will($this->testCase->returnCallback(array($this, 'getGlobalCallback')));
     if (in_array('runFunction', $this->methods)) {
         $functionWrapperMock = $this->testCase->getMock('WikiaFunctionWrapper', array_keys($this->mockedFunctions));
         foreach ($this->mockedFunctions as $functionName => $functionData) {
             $functionWrapperMock->expects($this->testCase->exactly($functionData['calls']))->method($functionName)->will($this->testCase->returnValue($functionData['value']));
         }
     }
     $wikiaAppArgs[] = $globalRegistryMock;
     $wikiaAppArgs[] = null;
     // WikiaLocalRegistry
     $wikiaAppArgs[] = null;
     // WikiaHookDispatcher
     $wikiaAppArgs[] = $functionWrapperMock;
     $this->mock = $this->testCase->getMock('WikiaApp', array('ajax'), $wikiaAppArgs, '');
     F::setInstance('App', $this->mock);
 }
开发者ID:schwarer2006,项目名称:wikia,代码行数:22,代码来源:WikiaAppMock.class.php

示例11: 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\\Service\\Data\\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('create')->will($this->_testObject->returnCallback(function ($className, $arguments) {
         $reflectionClass = new \ReflectionClass($className);
         return $reflectionClass->newInstanceArgs($arguments);
     }));
     return $builderObject;
 }
开发者ID:Atlis,项目名称:docker-magento2,代码行数:22,代码来源:ObjectManager.php

示例12: _getTranslatorMock

 /**
  * Retrieve mock of core translator model
  *
  * @return Mage_Core_Model_Translate|PHPUnit_Framework_MockObject_MockObject
  */
 protected function _getTranslatorMock()
 {
     $translator = $this->_testObject->getMockBuilder('Mage_Core_Model_Translate')->disableOriginalConstructor()->setMethods(array('translate'))->getMock();
     $translateCallback = function ($arguments) {
         $result = '';
         if (is_array($arguments) && current($arguments) instanceof Mage_Core_Model_Translate_Expr) {
             /** @var Mage_Core_Model_Translate_Expr $expression */
             $expression = array_shift($arguments);
             $result = vsprintf($expression->getText(), $arguments);
         }
         return $result;
     };
     $translator->expects($this->_testObject->any())->method('translate')->will($this->_testObject->returnCallback($translateCallback));
     return $translator;
 }
开发者ID:,项目名称:,代码行数:20,代码来源:

示例13: create

 /**
  * Creates and instance of the mock object.
  *
  * @param   PHPUnit_Framework_TestCase  $test  A test object.
  *
  * @return  PHPUnit_Framework_MockObject_MockObject
  */
 public static function create($test)
 {
     // Collect all the relevant methods in JDatabase.
     $methods = array('getIssueId', 'setIssueId', 'getIssue', 'getIssueProject', 'getIssues');
     // Create the mock.
     $mockObject = $test->getMock('MonitorModelIssue', $methods, array(), '', false);
     self::createSampleData();
     $setterCallback = function ($id) {
         self::$issueId = $id;
     };
     $mockObject->expects($test->any())->method('setIssueId')->will($test->returnCallback($setterCallback));
     $mockObject->expects($test->any())->method('getIssueId')->will($test->returnValue(self::$issueId));
     $mockObject->expects($test->any())->method('getIssue')->will($test->returnValue(self::$data[self::$issueId]));
     $mockObject->expects($test->any())->method('getIssueProject')->will($test->returnValue(1));
     $mockObject->expects($test->any())->method('getIssues')->will($test->returnValue(self::$data));
     return $mockObject;
 }
开发者ID:Harmageddon,项目名称:com_monitor,代码行数:24,代码来源:issue.php

示例14: create

 /**
  * Creates an instance of the mock JMenu object.
  *
  * @param   PHPUnit_Framework_TestCase  $test  A test object.
  *
  * @return  PHPUnit_Framework_MockObject_MockObject
  *
  * @since   3.4
  */
 public static function create(PHPUnit_Framework_TestCase $test, $setDefault = true, $setActive = false)
 {
     // Collect all the relevant methods in JMenu (work in progress).
     $methods = array('getItem', 'setDefault', 'getDefault', 'setActive', 'getActive', 'getItems', 'getParams', 'getMenu', 'authorise', 'load');
     // Create the mock.
     $mockObject = $test->getMock('JMenu', $methods, array(), '', false);
     self::createMenuSampleData();
     $mockObject->expects($test->any())->method('getItem')->will($test->returnValueMap(self::prepareGetItemData()));
     $mockObject->expects($test->any())->method('getItems')->will($test->returnCallback(array(__CLASS__, 'prepareGetItemsData')));
     $mockObject->expects($test->any())->method('getMenu')->will($test->returnValue(self::$data));
     if ($setDefault) {
         $mockObject->expects($test->any())->method('getDefault')->will($test->returnValueMap(self::prepareDefaultData()));
     }
     if ($setActive) {
         $mockObject->expects($test->any())->method('getActive')->will($test->returnValue(self::$data[$setActive]));
     }
     return $mockObject;
 }
开发者ID:eshiol,项目名称:joomla-cms,代码行数:27,代码来源:menu.php

示例15: mockEnvelope

 /**
  * @param Identifies    $id
  * @param int           $version
  * @param Metadata|null $metadata
  * @return \PHPUnit_Framework_MockObject_MockObject
  */
 public function mockEnvelope(Identifies $id, $version, Metadata $metadata = null)
 {
     $class = 'SimpleES\\EventSourcing\\Event\\EnvelopsEvent';
     $envelope = $this->testCase->getMock($class);
     $envelope->expects($this->testCase->any())->method('eventId')->will($this->testCase->returnValue($this->mockIdentifier()));
     $envelope->expects($this->testCase->any())->method('eventName')->will($this->testCase->returnValue('event_' . ($version + 1)));
     $envelope->expects($this->testCase->any())->method('event')->will($this->testCase->returnValue($this->getEventStreamEventOne($id)));
     $envelope->expects($this->testCase->any())->method('aggregateId')->will($this->testCase->returnValue($id));
     $envelope->expects($this->testCase->any())->method('aggregateVersion')->will($this->testCase->returnValue($version));
     $envelope->expects($this->testCase->any())->method('tookPlaceAt')->will($this->testCase->returnValue(Timestamp::now()));
     if ($metadata === null) {
         $metadata = new Metadata([]);
     }
     $envelope->expects($this->testCase->any())->method('metadata')->will($this->testCase->returnValue($metadata));
     $envelope->expects($this->testCase->any())->method('enrichMetadata')->will($this->testCase->returnCallback(function (Metadata $newMetadata) use($id, $version, $metadata) {
         return $this->mockEnvelope($id, $version, $metadata->merge($newMetadata));
     }));
     return $envelope;
 }
开发者ID:f500,项目名称:event-sourcing,代码行数:25,代码来源:TestHelper.php


注:本文中的PHPUnit_Framework_TestCase::returnCallback方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。