本文整理汇总了PHP中PHPUnit_Framework_TestCase::getMock方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_TestCase::getMock方法的具体用法?PHP PHPUnit_Framework_TestCase::getMock怎么用?PHP PHPUnit_Framework_TestCase::getMock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_TestCase
的用法示例。
在下文中一共展示了PHPUnit_Framework_TestCase::getMock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getMock
public function getMock()
{
$mock = $this->testCase->getMock('stdClass', $this->functions, array(), 'PHPUnit_Extension_FunctionMocker_' . uniqid());
foreach ($this->functions as $function) {
$fqFunction = $this->namespace . '\\' . $function;
if (in_array($fqFunction, static::$mockedFunctions, true)) {
continue;
}
if (!extension_loaded('runkit') || !ini_get('runkit.internal_override')) {
PHPUnit_Extension_FunctionMocker_CodeGenerator::defineFunction($function, $this->namespace);
} elseif (!function_exists('__phpunit_function_mocker_' . $function)) {
runkit_function_rename($function, '__phpunit_function_mocker_' . $function);
error_log($function);
runkit_method_redefine($function, function () use($function) {
if (!isset($GLOBALS['__PHPUNIT_EXTENSION_FUNCTIONMOCKER'][$this->namespace])) {
return call_user_func_array('__phpunit_function_mocker_' . $function, func_get_args());
}
return call_user_func_array(array($GLOBALS['__PHPUNIT_EXTENSION_FUNCTIONMOCKER'][$this->namespace], $function), func_get_args());
});
var_dump(strlen("foo"));
}
static::$mockedFunctions[] = $fqFunction;
}
if (!isset($GLOBALS['__PHPUNIT_EXTENSION_FUNCTIONMOCKER'])) {
$GLOBALS['__PHPUNIT_EXTENSION_FUNCTIONMOCKER'] = array();
}
$GLOBALS['__PHPUNIT_EXTENSION_FUNCTIONMOCKER'][$this->namespace] = $mock;
return $mock;
}
示例2: create
/**
* @param \PHPUnit_Framework_TestCase $test
* @param \Closure $qbCallback
* @param array $fields
*
* @return \Doctrine\ORM\EntityManagerInterface
*/
public static function create(\PHPUnit_Framework_TestCase $test, \Closure $qbCallback, $fields)
{
$query = $test->getMockForAbstractClass('Doctrine\\ORM\\AbstractQuery', [], '', false, true, true, ['execute']);
$query->expects($test->any())->method('execute')->will($test->returnValue(true));
if (Version::compare('2.5.0') < 1) {
$entityManager = $test->getMock('Doctrine\\ORM\\EntityManagerInterface');
$qb = $test->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->setConstructorArgs([$entityManager])->getMock();
} else {
$qb = $test->getMockBuilder('Doctrine\\ORM\\QueryBuilder')->disableOriginalConstructor()->getMock();
}
$qb->expects($test->any())->method('select')->will($test->returnValue($qb));
$qb->expects($test->any())->method('getQuery')->will($test->returnValue($query));
$qb->expects($test->any())->method('where')->will($test->returnValue($qb));
$qb->expects($test->any())->method('orderBy')->will($test->returnValue($qb));
$qb->expects($test->any())->method('andWhere')->will($test->returnValue($qb));
$qb->expects($test->any())->method('leftJoin')->will($test->returnValue($qb));
$qbCallback($qb);
$repository = $test->getMockBuilder('Doctrine\\ORM\\EntityRepository')->disableOriginalConstructor()->getMock();
$repository->expects($test->any())->method('createQueryBuilder')->will($test->returnValue($qb));
$metadata = $test->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
$metadata->expects($test->any())->method('getFieldNames')->will($test->returnValue($fields));
$metadata->expects($test->any())->method('getName')->will($test->returnValue('className'));
$em = $test->getMockBuilder('Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
$em->expects($test->any())->method('getRepository')->will($test->returnValue($repository));
$em->expects($test->any())->method('getClassMetadata')->will($test->returnValue($metadata));
return $em;
}
示例3: getLayoutFromFixture
/**
* Retrieve new layout model instance with layout updates from a fixture file
*
* @param string|array $layoutUpdatesFile
* @param array $args
* @return \Magento\Framework\View\Layout|\PHPUnit_Framework_MockObject_MockObject
*/
public function getLayoutFromFixture($layoutUpdatesFile, array $args = [])
{
$layout = $this->_testCase->getMock('Magento\\Framework\\View\\Layout', ['getUpdate'], $args);
$layoutUpdate = $this->getLayoutUpdateFromFixture($layoutUpdatesFile);
$layoutUpdate->asSimplexml();
$layout->expects(\PHPUnit_Framework_TestCase::any())->method('getUpdate')->will(\PHPUnit_Framework_TestCase::returnValue($layoutUpdate));
return $layout;
}
示例4: getAuthorization
public function getAuthorization($result, $resolved = true)
{
$authorizationMockup = $this->object->getMock("ResolveAuth\\Authorization\\Resolvable\\ResolvableAuthorization", ['value', 'state', 'resolve', 'afterResolve', 'resolved'], [], '', false);
$authorizationMockup->method('value')->willReturn($result);
$authorizationMockup->method('resolved')->willReturn($resolved);
$authorizationMockup->method('state')->willReturn($result);
return $authorizationMockup;
}
示例5: getLayoutFromFixture
/**
* Retrieve new layout model instance with layout updates from a fixture file
*
* @param string $layoutUpdatesFile
* @param array $args
* @return Mage_Core_Model_Layout|PHPUnit_Framework_MockObject_MockObject
*/
public function getLayoutFromFixture($layoutUpdatesFile, array $args = array())
{
$layout = $this->_testCase->getMock('Mage_Core_Model_Layout', array('getUpdate'), $args);
$layoutUpdate = $this->getLayoutUpdateFromFixture($layoutUpdatesFile);
$layoutUpdate->asSimplexml();
$layout->expects(PHPUnit_Framework_TestCase::any())->method('getUpdate')->will(PHPUnit_Framework_TestCase::returnValue($layoutUpdate));
return $layout;
}
示例6: mockQuoteIdMask
/**
* Return mocks with expected invokes
*
* First element is quoteIdMaskFactoryMock, second one is quoteIdMaskMock
*
* @param $maskedCartId
* @param $cartId
* @return array
*/
public function mockQuoteIdMask($maskedCartId, $cartId)
{
$quoteIdMaskMock = $this->testCase->getMock('Magento\\Quote\\Model\\QuoteIdMask', ['load', 'getQuoteId', 'getMaskedId'], [], '', false);
$quoteIdMaskFactoryMock = $this->testCase->getMockBuilder('Magento\\Quote\\Model\\QuoteIdMaskFactory')->setMethods(['create'])->disableOriginalConstructor()->getMock();
$quoteIdMaskFactoryMock->expects($this->testCase->once())->method('create')->willReturn($quoteIdMaskMock);
$quoteIdMaskMock->expects($this->testCase->once())->method('load')->with($maskedCartId)->willReturnSelf();
$quoteIdMaskMock->expects($this->testCase->once())->method('getQuoteId')->willReturn($cartId);
return [$quoteIdMaskFactoryMock, $quoteIdMaskMock];
}
示例7: createMockItem
/**
* Creates and instance of a mock Joomla\Cache\Item object.
*
* @return object
*
* @since 1.0
*/
public function createMockItem()
{
// Collect all the relevant methods in JDatabase.
$methods = array('getKey', 'getValue', 'isHit', 'setValue');
// Create the mock.
$mockObject = $this->test->getMock('Joomla\\Cache\\Item', $methods, array(), '', false);
TestHelper::assignMockCallbacks($mockObject, $this->test, array('getValue' => array(is_callable(array($this->test, 'mockCacheItemGetValue')) ? $this->test : $this, 'mockCacheItemGetValue'), 'isHit' => array(is_callable(array($this->test, 'mockCacheItemIsHit')) ? $this->test : $this, 'mockCacheItemIsHit')));
return $mockObject;
}
示例8: mockAggregate
/**
* @param Identifies $id
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function mockAggregate(Identifies $id)
{
$class = 'SimpleES\\EventSourcing\\Aggregate\\TracksEvents';
$aggregate = $this->testCase->getMock($class);
$aggregate->expects($this->testCase->any())->method('aggregateId')->will($this->testCase->returnValue($id));
return $aggregate;
}
示例9: createInput
/**
* Creates an instance of a mock JInput object.
*
* @param array $options An associative array of options to configure the mock.
* * methods => an array of additional methods to mock
*
* @return PHPUnit_Framework_MockObject_MockObject
*
* @since 3.4
*/
public function createInput(array $options = null)
{
// Collect all the relevant methods in JInput.
$methods = array('count', 'def', 'get', 'getArray', 'getInt', 'getMethod', 'set', 'serialize', 'unserialize');
// Add custom methods if required for derived application classes.
if (isset($options['methods']) && is_array($options['methods'])) {
$methods = array_merge($methods, $options['methods']);
}
// Create the mock.
$mockObject = self::$test->getMock('JInput', $methods, array(), '', false);
self::$test->assignMockCallbacks($mockObject, array('get' => array(is_callable(array(self::$test, 'mockInputGet')) ? self::$test : $this, 'mockInputGet'), 'getArray' => array(is_callable(array(self::$test, 'mockInputGetArray')) ? self::$test : $this, 'mockInputGetArray'), 'getInt' => array(is_callable(array(self::$test, 'mockInputGetInt')) ? self::$test : $this, 'mockInputGetInt'), 'set' => array(is_callable(array(self::$test, 'mockInputSet')) ? self::$test : $this, 'mockInputSet')));
$mockObject->get = $mockObject;
$mockObject->post = $mockObject;
$mockObject->request = $mockObject;
return $mockObject;
}
示例10: 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;
}
示例11: create
/**
* Creates and instance of the mock AbstractModel object.
*
* @param \PHPUnit_Framework_TestCase $test A test object.
*
* @return object
*
* @since 1.0
*/
public static function create(\PHPUnit_Framework_TestCase $test)
{
// Collect all the relevant methods in AbstractModel.
$methods = array('getState', 'loadState', 'setState');
// Create the mock.
$mockObject = $test->getMock('Joomla\\Model\\ModelInterface', $methods, array(), '', false);
return $mockObject;
}
示例12: create
/**
* Creates an instance of the mock JAccessRules object.
*
* @param PHPUnit_Framework_TestCase $test A test object.
*
* @return PHPUnit_Framework_MockObject_MockObject
*
* @since 11.3
*/
public static function create($test)
{
// Mock all the public methods.
$methods = array('allow');
// Create the mock.
$mockObject = $test->getMock('JAccessRules', $methods, array(), '', false);
$test->assignMockCallbacks($mockObject, array('allow' => array(get_called_class(), 'mockAllow')));
return $mockObject;
}
示例13: getCollectionMock
/**
* Get collection mock
*
* @param string $className
* @param array $data
* @return \PHPUnit_Framework_MockObject_MockObject
* @throws \InvalidArgumentException
*/
public function getCollectionMock($className, array $data)
{
if (!is_subclass_of($className, '\\Magento\\Framework\\Data\\Collection')) {
throw new \InvalidArgumentException($className . ' does not instance of \\Magento\\Framework\\Data\\Collection');
}
$mock = $this->_testObject->getMock($className, [], [], '', false, false);
$iterator = new \ArrayIterator($data);
$mock->expects($this->_testObject->any())->method('getIterator')->will($this->_testObject->returnValue($iterator));
return $mock;
}
示例14: create
/**
* Creates and instance of the mock JLanguage object.
*
* @param PHPUnit_Framework_TestCase $test A test object.
*
* @return PHPUnit_Framework_MockObject_MockObject
*
* @since 11.3
*/
public static function create($test)
{
// Collect all the relevant methods in JDatabase.
$methods = array('parse', 'render', 'test');
// Create the mock.
$mockObject = $test->getMock('JDocument', $methods, array(), '', false);
// Mock selected methods.
$test->assignMockReturns($mockObject, array('parse' => $mockObject, 'test' => 'ok'));
return $mockObject;
}
示例15: __construct
/**
* @param \PHPUnit_Framework_TestCase $testCase
*
* @param array $classes
*/
public function __construct(\PHPUnit_Framework_TestCase $testCase, array $classes = [])
{
$configProvider = $testCase->getMockBuilder('Oro\\Bundle\\EntityConfigBundle\\Provider\\ConfigProvider')->disableOriginalConstructor()->getMock();
$entityClassResolver = $testCase->getMockBuilder('Oro\\Bundle\\EntityBundle\\ORM\\EntityClassResolver')->disableOriginalConstructor()->getMock();
$entityClassResolver->expects($testCase->any())->method('getEntityClass')->willReturnArgument(0);
$container = $testCase->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
$container->expects($testCase->any())->method('get')->will($testCase->returnValueMap([['oro_entity_config.provider.ownership', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $configProvider], ['oro_entity.orm.entity_class_resolver', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $entityClassResolver]]));
parent::__construct(array_merge(['organization' => 'Oro\\Bundle\\SecurityBundle\\Tests\\Unit\\Acl\\Domain\\Fixtures\\Entity\\Organization', 'business_unit' => 'Oro\\Bundle\\SecurityBundle\\Tests\\Unit\\Acl\\Domain\\Fixtures\\Entity\\BusinessUnit', 'user' => 'Oro\\Bundle\\SecurityBundle\\Tests\\Unit\\Acl\\Domain\\Fixtures\\Entity\\User'], $classes));
$this->setContainer($container);
}