本文整理汇总了PHP中PHPUnit_Framework_TestCase::getMockBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_TestCase::getMockBuilder方法的具体用法?PHP PHPUnit_Framework_TestCase::getMockBuilder怎么用?PHP PHPUnit_Framework_TestCase::getMockBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_TestCase
的用法示例。
在下文中一共展示了PHPUnit_Framework_TestCase::getMockBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: getArgumentMock
/**
* @param \ReflectionParameter $parameter
* @return mixed
*/
private function getArgumentMock(\ReflectionParameter $parameter)
{
if ($parameter->getClass() !== null) {
return $this->testCase->getMockBuilder($parameter->getClass()->getName())->disableOriginalConstructor()->getMock();
}
throw new \Mocktainer\UnmockableMethodArgumentException($parameter->getDeclaringClass()->getName(), $parameter->getDeclaringFunction()->getName(), $parameter->getName());
}
示例3: getMock
public function getMock()
{
$mock = $this->testCase->getMockBuilder('stdClass')->setMethods($this->functions)->setMockClassName('PHPUnit_Extension_FunctionMocker_' . uniqid())->getMock();
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;
}
示例4: getArgumentMock
/**
* @param string $className
* @param string $argumentName
* @param \ReflectionParameter $parameter
* @return mixed
*/
private function getArgumentMock(string $className, string $argumentName, \ReflectionParameter $parameter)
{
if ($parameter->getClass() !== null) {
return $this->testCase->getMockBuilder($parameter->getClass()->name)->disableOriginalConstructor()->getMock();
}
throw new \Mocktainer\UnmockableConstructorArgumentException($className, $argumentName);
}
示例5: 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];
}
示例6: __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);
}
示例7: getMock
/**
* Returns the mock object.
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function getMock()
{
$mock = $this->testCase->getMockBuilder('stdClass')->setMethods($this->functions)->setMockClassName('BluePsyduckTests_MultiCurl_Assets_FunctionMocker_' . uniqid())->getMock();
foreach ($this->functions as $function) {
if (!isset(self::$mockedFunctions[$this->namespace][$function])) {
$code = $this->generateCode($this->namespace, $function);
eval($code);
self::$mockedFunctions[$this->namespace][$function] = $function;
}
}
self::$currentMocks[$this->namespace] = $mock;
return $mock;
}
示例8: getPHPUnitMockObjectFor
public function getPHPUnitMockObjectFor($className, array $methods)
{
$rc = new \ReflectionClass($className);
$mockObject = null;
if ($rc->isInterface()) {
$mockObject = $this->testCase->getMockBuilder($className)->getMock();
} elseif ($rc->isAbstract()) {
$mockObject = $this->testCase->getMockBuilder($className)->disableOriginalConstructor()->setMethods($methods)->getMockForAbstractClass();
} elseif ($rc->isTrait()) {
$mockObject = $this->testCase->getMockBuilder($className)->disableOriginalConstructor()->setMethods($methods)->getMockForTrait();
} else {
$mockObject = $this->testCase->getMockBuilder($className)->disableOriginalConstructor()->disableOriginalClone()->disableArgumentCloning()->disallowMockingUnknownTypes()->getMock();
}
return $mockObject;
}
示例9: getReaderMock
/**
* @param \PHPUnit_Framework_TestCase $testCase
* @param array $results
* @return XmlReader
*/
public function getReaderMock(\PHPUnit_Framework_TestCase $testCase, array $results)
{
$result = new PHPUnit_Framework_MockObject_Stub_ConsecutiveCalls(array_merge($results, []));
$reader = $testCase->getMockBuilder('\\DataSource\\XmlReader')->disableOriginalConstructor()->getMock();
$reader->expects(static::any())->method('getRows')->will($result);
return $reader;
}
示例10: fromFixture
/**
* @param string $path
* @param TestCase $testCase
* @return RequestInterface
*/
public static function fromFixture($path, TestCase $testCase)
{
$content = file_get_contents($path);
$lines = explode("\n", $content);
$request = $testCase->getMockBuilder(RequestInterface::class)->getMock();
$line = array_shift($lines);
list($method, $uri, $ver) = explode(' ', $line);
$request->expects(TestCase::any())->method('getMethod')->willReturn($method);
$headerValues = [];
$headers = [];
while (($line = array_shift($lines)) != "") {
list($key, $value) = explode(': ', $line);
$headers[$key] = $value;
$headerValues[$key] = explode(', ', $value);
}
$request->expects(TestCase::any())->method('getHeaders')->willReturn($headerValues);
$request->expects(TestCase::any())->method('getHeaderLine')->willReturnCallback(function ($key) use($headers) {
return isset($headers[$key]) ? $headers[$key] : null;
});
$request->expects(TestCase::any())->method('hasHeader')->willReturnCallback(function ($key) use($headers) {
return isset($headers[$key]);
});
$request->expects(TestCase::any())->method('getBody')->willReturn($body = join("\n", $lines));
return $request;
}
示例11: 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;
}
示例12: 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;
}
示例13: _getTranslatorMock
/**
* Retrieve mock of core translator model
*
* @param string $className
* @return \Magento\Framework\TranslateInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected function _getTranslatorMock($className)
{
$translator = $this->_testObject->getMockBuilder($className)->disableOriginalConstructor()->getMock();
$translateCallback = function ($arguments) {
return is_array($arguments) ? vsprintf(array_shift($arguments), $arguments) : '';
};
$translator->expects($this->_testObject->any())->method('translate')->will($this->_testObject->returnCallback($translateCallback));
return $translator;
}
示例14: mockDriver
function mockDriver(PHPUnit_Framework_TestCase $testcase, $exists = true)
{
$driver = $testcase->getMockBuilder('BapCat\\Interfaces\\Persist\\Driver')->getMockForAbstractClass();
$driver->method('exists')->willReturn($exists);
$driver->method('size')->willReturn(100);
$driver->method('isLink')->willReturn(true);
$driver->method('isReadable')->willReturn(true);
$driver->method('isWritable')->willReturn(true);
return $driver;
}
示例15: 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;
}