protected function tearDown() { if ($this->prophet) { $this->prophet->checkPredictions(); } parent::tearDown(); }
/** * @param $id * @return ObjectProphecy */ private function createCategoryDouble($id) { $prophet = new Prophet(); $categoryDouble = $prophet->prophesize('Prh\\BlogBundle\\Entity\\Category'); $categoryDouble->getId()->willReturn($id); return $categoryDouble; }
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(); }
/** * @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'); } }
/** * 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()); }
protected function getAnnotationsExtractorResults() { $extractorResultProphecy = $this->prophet->prophesize('Team3\\PayU\\PropertyExtractor\\ExtractorResult'); $extractorResultProphecy->getPropertyName()->willReturn($this->getPropertyName()); $extractorResultProphecy->getValue()->willReturn($this->getValue()); return [$extractorResultProphecy]; }
/** * @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); }
/** * Create a binary mock. * * @param $name * @param $supported * @param $exists */ public function createBinary($name, $supported, $exists) { $binary = $this->prophet->prophesize('Peridot\\WebDriverManager\\Binary\\BinaryInterface'); $binary->isSupported()->willReturn($supported); $binary->getName()->willReturn($name); $binary->exists(Argument::any())->willReturn($exists); return $binary; }
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'); }
/** * 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; }
/** * 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(); }
/** * 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); }
public function it_should_not_replace_request_param_if_format_is_not_supported() { $requestParam = $this->prophet->prophesize('Symfony\\Component\\HttpFoundation\\ParameterBag'); $request = Request::create('/'); $request->request = $requestParam->reveal(); $requestParam->replace(Argument::any())->shouldNotBeCalled(); $this->decoderProvider->supports(Argument::any())->willReturn(false); $this->__invoke($request); }
/** * @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); }
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(); }
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()); }
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(); }
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'); }
/** * 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; }
private function countProphecyAssertions() { $this->prophecyAssertionsCounted = true; foreach ($this->prophet->getProphecies() as $objectProphecy) { foreach ($objectProphecy->getMethodProphecies() as $methodProphecies) { foreach ($methodProphecies as $methodProphecy) { $this->addToAssertionCount(count($methodProphecy->getCheckedPredictions())); } } } }
/** * @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); }
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'))); }
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); }
/** * @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(); }
/** * @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; }
public function it_is_initializable() { $prophet = new Prophet(); $httpProphecy = $prophet->prophesize('Zend\\Uri\\Http'); $httpProphecy->getPath()->willReturn('/b'); $requestProphecy = $prophet->prophesize('Zend\\Http\\PhpEnvironment\\Request'); $requestProphecy->getUri()->willReturn($httpProphecy->reveal()); $partProphecy = $prophet->prophesize('Tohmua\\RepeatingSegment\\Part\\Part'); $parts = [$partProphecy->reveal(), $partProphecy->reveal(), $partProphecy->reveal()]; $this->beConstructedWith($requestProphecy, $parts); $this->shouldHaveType('Tohmua\\RepeatingSegment\\RegexGenerator\\RegexGenerator'); }
/** * @param CollaboratorManager $collaborators * @param \ReflectionMethod $beforeMethod */ private function createMissingCollabolators(CollaboratorManager $collaborators, \ReflectionMethod $beforeMethod) { foreach ($beforeMethod->getParameters() as $parameter) { if (!$collaborators->has($parameter->getName())) { $collaborator = new Collaborator($this->prophet->prophesize()); if (null !== ($class = $parameter->getClass())) { $collaborator->beADoubleOf($class->getName()); } $collaborators->set($parameter->getName(), $collaborator); } } }
/** * @param array $config */ protected function mockConfig($config) { // Create mocks $prophet = new Prophet(); $helperSet = $prophet->prophesize('\\Symfony\\Component\\Console\\Helper\\HelperSet'); $helper = $prophet->prophesize('\\Phpro\\SmartCrud\\Console\\Helper\\ConfigHelper'); // Add logic $helper->getConfig()->willReturn($config); $helper->getApplicationConfig()->willReturn($config); $helperSet->get('Config')->willReturn($helper); $this->setHelperSet($helperSet); }
protected function mockApplicationConfig($configKey, $config) { // Create mocks $prophet = new Prophet(); $helperSet = $prophet->prophesize('\\Symfony\\Component\\Console\\Helper\\HelperSet'); $helper = $prophet->prophesize('\\Phpro\\SmartCrud\\Console\\Helper\\ServiceManagerHelper'); $serviceManager = $prophet->prophesize('\\Zend\\ServiceManager\\ServiceManager'); // Add logic $serviceManager->get($configKey)->willReturn($config); $helper->getServiceManager()->willReturn($serviceManager); $helperSet->get('serviceManager')->willReturn($helper); $this->setHelperSet($helperSet); }
/** * Get the mocked delivery execution * * @param string $executionStateUri the state of the delivery execution * @return DeliveryExecution the mocked delivery execution */ protected function getDeliveryExecution($executionStateUri = ProctoredDeliveryExecution::STATE_AUTHORIZED) { $prophet = new Prophet(); $prophecy = $prophet->prophesize(); $prophecy->willImplement(DeliveryExecution::class); $prophecy->getDelivery()->willReturn(new \core_kernel_classes_Resource('fakeDelivery')); $prophecy->getState()->willReturn(new \core_kernel_classes_Resource($executionStateUri)); $prophecy->getIdentifier()->willReturn('fakeDeliveryExecution'); $prophecy->setState(Argument::any())->will(function ($args) use($prophecy) { $prophecy->getState()->willReturn(new \core_kernel_classes_Resource($args[0])); }); return $prophecy->reveal(); }