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


PHP PHPUnit_Framework_TestCase::getMockBuilder方法代码示例

本文整理汇总了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;
 }
开发者ID:zapoyok,项目名称:core-bundle,代码行数:34,代码来源:EntityManagerMockFactory.php

示例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());
 }
开发者ID:paranoiq,项目名称:mocktainer,代码行数:11,代码来源:Mocktainer.php

示例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;
 }
开发者ID:lstrojny,项目名称:phpunit-function-mocker,代码行数:29,代码来源:FunctionMocker.php

示例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);
 }
开发者ID:ondrejmirtes,项目名称:mocktainer,代码行数:13,代码来源:Mocktainer.php

示例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];
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:GuestCartTestHelper.php

示例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);
 }
开发者ID:Maksold,项目名称:platform,代码行数:15,代码来源:OwnershipMetadataProviderStub.php

示例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;
 }
开发者ID:bluepsyduck,项目名称:multicurl,代码行数:17,代码来源:FunctionMocker.php

示例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;
 }
开发者ID:lucatume,项目名称:function-mocker,代码行数:15,代码来源:InstanceForger.php

示例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;
 }
开发者ID:apolev,项目名称:fias,代码行数:12,代码来源:TestAbstract.php

示例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;
 }
开发者ID:jeremygiberson,项目名称:psr7-push-notification-middleware,代码行数:30,代码来源:RequestStubFactory.php

示例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;
 }
开发者ID:veksa,项目名称:Pinterest-API-PHP,代码行数:33,代码来源:CurlBuilderMock.php

示例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;
 }
开发者ID:repo2,项目名称:query-builder,代码行数:9,代码来源:Mock.php

示例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;
 }
开发者ID:,项目名称:,代码行数:15,代码来源:

示例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;
}
开发者ID:bapcat,项目名称:interfaces,代码行数:10,代码来源:_mocks.php

示例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;
}
开发者ID:bapcat,项目名称:persist,代码行数:11,代码来源:_mocks.php


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