php Prophecy-Prophet类(方法)实例源码

下面列出了php Prophecy-Prophet 类(方法)源码代码实例,从而了解它的用法。

作者:prevuelta    项目:blog-bundl   
/**
  * @param $id
  * @return ObjectProphecy
  */
 private function createCategoryDouble($id)
 {
     $prophet = new Prophet();
     $categoryDouble = $prophet->prophesize('Prh\\BlogBundle\\Entity\\Category');
     $categoryDouble->getId()->willReturn($id);
     return $categoryDouble;
 }

作者:phpr    项目:grumph   
function it_should_be_able_to_run_processes()
 {
     $prophet = new Prophet();
     $processes = [];
     for ($i = 0; $i < 20; $i++) {
         $process = $prophet->prophesize(Process::class);
         $process->started = false;
         $process->terminated = false;
         $process->start()->will(function () use($process) {
             $process->started = true;
         })->shouldBeCalledTimes(1);
         $process->isTerminated()->will(function () use($process) {
             if (!$process->terminated) {
                 $process->terminated = true;
                 return false;
             }
             return true;
         })->shouldBeCalledTimes(2);
         // The number of times isStarted() is called starts at 3
         // and increases by 2 after each chunk of five processes.
         $process->isStarted()->will(function () use($process) {
             return $process->started;
         })->shouldBeCalledTimes(floor($i / 5) * 2 + 3);
         $processes[] = $process->reveal();
     }
     $this->run($processes);
     $prophet->checkPredictions();
 }

作者:checkdomai    项目:telecas   
/**
  * @param Payment            $payment
  * @param TransactionDetails $transactionDetails
  *
  * @dataProvider dataProvider
  */
 public function testXMLGeneration($payment, $transactionDetails)
 {
     $prophet = new Prophet();
     $orderService = $prophet->prophesize('Checkdomain\\TeleCash\\IPG\\API\\Service\\OrderService');
     $sellHosted = new SellHostedData($orderService->reveal(), $payment, $transactionDetails);
     $document = $sellHosted->getDocument();
     $document->appendChild($sellHosted->getElement());
     $elementCCType = $document->getElementsByTagName('ns1:CreditCardTxType');
     $this->assertEquals(1, $elementCCType->length, 'Expected element CreditCardTxType not found');
     $children = [];
     /** @var \DOMNode $child */
     foreach ($elementCCType->item(0)->childNodes as $child) {
         $children[$child->nodeName] = $child->nodeValue;
     }
     $this->assertArrayHasKey('ns1:Type', $children, 'Expected element Type not found');
     $this->assertEquals('sale', $children['ns1:Type'], 'Type did not match');
     $elementPayment = $document->getElementsByTagName('ns1:Payment');
     $this->assertEquals(1, $elementPayment->length, 'Expected element Payment not found');
     if ($transactionDetails !== null) {
         $elementDetails = $document->getElementsByTagName('ns2:TransactionDetails');
         $this->assertEquals(1, $elementDetails->length, 'Expected element TransactionDetails not found');
     } else {
         $elementDetails = $document->getElementsByTagName('ns2:TransactionDetails');
         $this->assertEquals(0, $elementDetails->length, 'Unexpected element TransactionDetails was found');
     }
 }

作者:phpr    项目:zf-smartcru   
/**
  * Mock the authorization service
  *
  * @param bool $isAllowed
  */
 protected function mockAuthorizeService($isAllowed = true)
 {
     $prophet = new Prophet();
     $authorizeService = $prophet->prophesize('\\BjyAuthorize\\Service\\Authorize');
     $authorizeService->isAllowed(Argument::cetera())->willReturn($isAllowed);
     $this->mockListenerFactory($authorizeService->reveal());
 }

作者:steflieken    项目:zf-apigility-doctrine-bul   
/**
  * @param \Doctrine\Common\Persistence\ObjectManager $objectManager
  */
 protected function stubMetaData($objectManager)
 {
     $prophet = new Prophet();
     $meta = $prophet->prophesize('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
     $meta->getIdentifierFieldNames()->willReturn(['id']);
     $meta->getIdentifierValues(Argument::any())->willReturn([1]);
     $objectManager->getClassMetadata('stdClass')->willReturn($meta);
 }

作者:phantsan    项目:1u0U39rjwJO4Vmnt99uk9j   
function it_should_throw_exception_when_buildpath_not_exist()
 {
     $prophet = new Prophet();
     $file = $prophet->prophesize('Illuminate\\Filesystem\\Filesystem');
     $file->makeDirectory('dir_bar', 0775, true)->willReturn(false);
     $this->beConstructedWith(null, null, $file);
     $this->shouldThrow('Devfactory\\Minify\\Exceptions\\DirNotExistException')->duringMake('dir_bar');
 }

作者:Sarfaraa    项目:d   
/**
  * Add a mock driver
  * 
  * @param string $name
  * @return string
  */
 protected static function addMockDriver($name)
 {
     $prophet = new Prophet();
     $prophecy = $prophet->prophesize('Jasny\\DB\\Connection');
     $class = get_class($prophecy->reveal());
     DB::$drivers[$name] = $class;
     return $class;
 }

作者:php-moc    项目:php-mock-prophec   
/**
  * Calling no optional parameter
  *
  * @test
  * @see https://github.com/php-mock/php-mock-prophecy/issues/1
  */
 public function expectingWithoutOptionalParameter()
 {
     $prophet = new Prophet();
     $prophecy = $prophet->prophesize(OptionalParameterHolder::class);
     $prophecy->call("arg1")->willReturn("mocked");
     $mock = $prophecy->reveal();
     $this->assertEquals("mocked", $mock->call("arg1"));
     $prophet->checkPredictions();
 }

作者:phpr    项目:zf-smartcru   
/**
  * Mock the flashmessenger
  *
  * @param $flashMessenger
  */
 protected function mockFlashMessenger($flashMessenger)
 {
     $prophet = new Prophet();
     $serviceManager = $prophet->prophesize('\\Zend\\ServiceManager\\ServiceManager');
     $pluginManager = $prophet->prophesize('\\Zend\\Mvc\\Controller\\PluginManager');
     $serviceManager->get('ControllerPluginManager')->willReturn($pluginManager);
     $pluginManager->get('flashmessenger')->willReturn($flashMessenger->getWrappedObject());
     $this->createService($serviceManager);
 }

作者:phpr    项目:zf-smartcru   
/**
  * @param \Zend\ServiceManager\ServiceLocatorInterface $serviceLocator
  */
 protected function mockConfiguration($serviceLocator)
 {
     $serviceLocator->has('Config')->willReturn(true);
     $serviceLocator->get('Config')->willReturn(array('phpro-smartcrud-gateway' => array('custom-gateway' => array('type' => 'smartcrud.base.gateway', 'options' => array('object_manager' => 'ObjectManager')), 'fault-gateway' => array('type' => 'fault-gateway'))));
     $prophet = new Prophet();
     $objectManager = $prophet->prophesize('Doctrine\\Common\\Persistence\\ObjectManager');
     $serviceLocator->has('ObjectManager')->willReturn(true);
     $serviceLocator->get('ObjectManager')->willReturn($objectManager);
 }

作者:hunslate    项目:grumph   
protected function mockFile($name, $isRename = false, $isDelete = false)
 {
     $prophet = new Prophet();
     $file = $prophet->prophesize('Gitonomy\\Git\\Diff\\File');
     $file->getName()->willReturn($name);
     $file->getNewName()->willReturn($name);
     $file->isRename()->willReturn($isRename);
     $file->isDeletion()->willReturn($isDelete);
     return $file->reveal();
 }

作者:rickymathe    项目:TYPO3.CM   
public function setUp()
 {
     unset($GLOBALS['TYPO3_CONF_VARS']['INSTALL']['wizardDone']);
     $prophet = new Prophet();
     $this->packageManagerProphecy = $prophet->prophesize(PackageManager::class);
     $this->dbProphecy = $prophet->prophesize(\TYPO3\CMS\Core\Database\DatabaseConnection::class);
     $GLOBALS['TYPO3_DB'] = $this->dbProphecy->reveal();
     $this->updateWizard = new UpdateWizard();
     ExtensionManagementUtility::setPackageManager($this->packageManagerProphecy->reveal());
 }

作者:phpr    项目:grumph   
protected function mockFile($name, $isRename = false, $isDelete = false)
 {
     $prophet = new Prophet();
     $file = $prophet->prophesize(File::class);
     $file->getName()->willReturn($name);
     $file->getNewName()->willReturn($name);
     $file->isRename()->willReturn($isRename);
     $file->isDeletion()->willReturn($isDelete);
     return $file->reveal();
 }

作者:Tohmu    项目:RepeatingSegmen   
public function it_can_match_repeating_multiple_segments()
 {
     $prophet = new Prophet();
     $httpProphecy = $prophet->prophesize('Zend\\Uri\\Http');
     $httpProphecy->getPath()->willReturn('/a/foo/bar/b/c/bar/bass/d');
     $requestProphecy = $prophet->prophesize('Zend\\Http\\PhpEnvironment\\Request');
     $requestProphecy->getUri()->willReturn($httpProphecy->reveal());
     $this->beConstructedWith('/a[section]/b/c[other_section]/d', ['section' => '/[a-zA-Z][a-zA-Z0-9_-]+', 'other_section' => '/[a-zA-Z][a-zA-Z0-9_-]+'], ['controller' => 'Controller', 'action' => 'create']);
     $this->match($requestProphecy->reveal())->shouldReturnAnInstanceOf('Zend\\Mvc\\Router\\Http\\RouteMatch');
 }

作者:oat-s    项目:extension-tao-tes   
/**
  * Get the service with the stubbed registry
  * @return TestPluginService
  */
 protected function getTestPluginService()
 {
     $testPluginService = new TestPluginService();
     $prophet = new Prophet();
     $prophecy = $prophet->prophesize();
     $prophecy->willExtend(PluginRegistry::class);
     $prophecy->getMap()->willReturn(self::$pluginData);
     $testPluginService->setRegistry($prophecy->reveal());
     return $testPluginService;
 }

作者:phpr    项目:zf-mvc-auth-toke   
/**
  * @param \Phpro\MvcAuthToken\TokenServer $tokenServer
  */
 protected function mockTokenServer($tokenServer)
 {
     $prophet = new Prophet();
     $token = $prophet->prophesize('Phpro\\MvcAuthToken\\Token');
     $token->getToken()->willReturn('token');
     $tokenServer->setAdapter(Argument::any())->willReturn(null);
     $tokenServer->setRequest(Argument::any())->willReturn(null);
     $tokenServer->setResponse(Argument::any())->willReturn(null);
     $tokenServer->getUserId()->willReturn('token');
     $tokenServer->getToken()->willReturn($token);
 }

作者:visualtur    项目:phpspec-larave   
function it_matches_a_belongs_to_many_relationship()
 {
     $p = new Prophet();
     $related = $p->prophesize('PhpSpec\\Laravel\\Test\\Example');
     $belongsTo = $p->prophesize('Illuminate\\Database\\Eloquent\\Relations\\BelongsToMany');
     $belongsTo->getRelated()->willReturn($related->reveal());
     $this->positiveMatch('name', $belongsTo->reveal(), array('belongsToMany', 'PhpSpec\\Laravel\\Test\\Example'));
     $this->shouldThrow('PhpSpec\\Exception\\Example\\FailureException')->during('positiveMatch', array('name', $belongsTo->reveal(), array('belongsToMany', 'PhpSpec\\Laravel\\Test\\OtherExample')));
     $this->negativeMatch('name', $belongsTo->reveal(), array('belongsToMany', 'PhpSpec\\Laravel\\Test\\OtherExample'));
     $this->shouldThrow('PhpSpec\\Exception\\Example\\FailureException')->during('negativeMatch', array('name', $belongsTo->reveal(), array('belongsToMany', 'PhpSpec\\Laravel\\Test\\Example')));
 }

作者:litph    项目:nim   
public function testNoopNext()
 {
     $prophet = new Prophet();
     $reqProphecy = $prophet->prophesize(ServerRequestInterface::class);
     $resProphecy = $prophet->prophesize(ResponseInterface::class);
     $req = $reqProphecy->reveal();
     $res = $resProphecy->reveal();
     /** @noinspection PhpParamsInspection */
     $returnValue = NimoUtility::noopNext($req, $res);
     $this->assertSame($res, $returnValue);
 }

作者:phpr    项目:zf-mail-manage   
/**
  * @return \Phpro\MailManager\Mail\RenderableMailInterface
  */
 protected function getMailStub()
 {
     $prophet = new Prophet();
     /** @var \Phpro\MailManager\Mail\RenderableMailInterface $mail */
     $mail = $prophet->prophesize('Phpro\\MailManager\\Mail\\RenderableMailInterface');
     $mail->getParams()->willReturn(['param1' => 'value1']);
     $mail->getViewFile()->willReturn('view-file');
     $mail->getLayoutFile()->willReturn('layout-file');
     $mail->getAttachments()->willReturn([]);
     return $mail->reveal();
 }

作者:phpr    项目:zf-smartcru   
/**
  * @param array $paramsData
  *
  * @return \Phpro\SmartCrud\Service\ParametersService
  */
 protected function mockParams(array $paramsData)
 {
     $prophet = new Prophet();
     /** @var \Phpro\SmartCrud\Service\ParametersService $params  */
     $params = $prophet->prophesize('Phpro\\SmartCrud\\Service\\ParametersService');
     $params->fromRoute()->willReturn($paramsData);
     $params->fromPost()->willReturn($paramsData);
     $params->fromQuery()->willReturn($paramsData);
     $params->fromRoute('id', Argument::any())->willReturn(1);
     $this->setParameters($params->reveal());
     return $params;
 }


问题


面经


文章

微信
公众号

扫码关注公众号