function it_handle_handlers(HandlerInterface $handler, RuleInterface $rule) { $configuration = array(); $this->addHandler($handler); $handler->handle(Argument::exact($configuration), Argument::exact($rule->getWrappedObject()))->shouldBeCalled(); $this->handle($configuration, $rule); }
/** * @return CacheItemPoolInterface * @throws \LogicException * * @link https://gist.github.com/scaytrase/3cf9c5ece4218280669c */ private function createCache() { static $items = []; $cache = $this->prophesize(CacheItemPoolInterface::class); $that = $this; $cache->getItem(Argument::type('string'))->will(function ($args) use(&$items, $that) { $key = $args[0]; if (!array_key_exists($key, $items)) { $item = $that->prophesize(CacheItemInterface::class); $item->getKey()->willReturn($key); $item->isHit()->willReturn(false); $item->get()->willReturn(null); $item->set(Argument::any())->will(function ($args) use($item) { $item->get()->willReturn($args[0]); }); $item->expiresAfter(Argument::type('int'))->willReturn($item); $item->expiresAfter(Argument::exact(null))->willReturn($item); $item->expiresAfter(Argument::type(\DateInterval::class))->willReturn($item); $item->expiresAt(Argument::type(\DateTimeInterface::class))->willReturn($item); $items[$key] = $item; } return $items[$key]->reveal(); }); $cache->save(Argument::type(CacheItemInterface::class))->will(function ($args) use(&$items) { $item = $args[0]; $items[$item->getKey()]->isHit()->willReturn(true); }); return $cache->reveal(); }
public function testAcceptVisitorDispatchesToVisitAndPredicateMethod() { $predicate = new AndPredicate(new NullPredicate(), new NullPredicate()); $visitor = $this->prophesize(PredicateVisitor::class); $visitor->visitAndPredicate(Argument::exact($predicate))->shouldBeCalled(); $predicate->acceptPredicateVisitor($visitor->reveal()); }
function it_break_visiting_on_certain_status(VisitorInterface $visitor, TokenPoolInterface $tokenPool, TokenInterface $token, CollatorInterface $collector) { $tokenPool->getIterator()->shouldBeCalledTimes(1)->willReturn(new \ArrayIterator(array($token->getWrappedObject()))); $visitor->accept(Argument::exact($token->getWrappedObject()), Argument::exact($collector->getWrappedObject()))->shouldBeCalledTimes(1)->willReturn(true); $visitor->visit(Argument::exact($token->getWrappedObject()), Argument::exact($collector->getWrappedObject()))->shouldBeCalledTimes(1)->willReturn(VisitorInterface::STATE_FOUND); $this->add($visitor, -255)->shouldReturn(true); $this->visit($tokenPool, $collector)->shouldReturn($this); }
function it_should_create_language(LanguageRepository $languageRepository, EventDispatcherInterface $eventDispatcher, Project $project, Language $language, CreateLanguageAction $action) { $action->getProject()->willReturn($project); $action->getLocale()->willReturn('fr_FR'); $languageRepository->createNew($project, Argument::exact(Locale::parse('fr_FR')))->willReturn($language); $languageRepository->save($language)->shouldBeCalled(); $this->execute($action)->shouldReturn($language); }
function it_detect_device(TokenPoolInterface $tokenPool, CollatorInterface $collator, VisitorManagerInterface $visitorManager) { $visitorManager->visit(Argument::exact($tokenPool->getWrappedObject()), Argument::exact($collator->getWrappedObject()))->shouldBeCalledTimes(1)->willReturn(VisitorInterface::STATE_SEEKING); $collator->removeAll()->shouldBeCalledTimes(1); $collator->getAll()->shouldBeCalledTimes(1)->willReturn(array()); $this->beConstructedWith($visitorManager, $collator); $this->detect($tokenPool)->shouldReturnAnInstanceOf('DeviceDetectorIO\\DeviceDetector\\Device\\Device'); }
function it_should_create_choice_form_definition(ContainerBuilder $container) { $this->mockDefaultBehavior($container); $definition = new Definition('Sylius\\ChoiceFormType'); $definition->setArguments(array('Sylius\\Model', SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM, 'sylius_resource_choice'))->addTag('form.type', array('alias' => 'sylius_resource_choice')); $container->setDefinition('sylius.form.type.resource_choice', Argument::exact($definition))->shouldBeCalled(); $this->configure(array('sylius' => array('driver' => SyliusResourceBundle::DRIVER_DOCTRINE_PHPCR_ODM, 'classes' => array('resource' => array('form' => array('choice' => 'Sylius\\ChoiceFormType'))))), new Configuration(), $container, AbstractResourceExtension::CONFIGURE_FORMS); }
/** * it returns all the modified php files * * @test * @return void */ public function it_returns_all_the_modified_php_files(Shell $shell) { $mock = file_get_contents('spec/support/git.mock'); $command = Argument::exact('git status'); $shell->execute($command)->willReturn($mock); $files = ['UserTest.php', 'User.php']; $this->modified()->shouldReturn($files); }
public function testAcceptVisitorDispatchesCallToVisitLiteralPredicateMethod() { $value = 'test value'; $predicate = new LiteralPredicate($value); $visitor = $this->prophesize(PredicateVisitor::class); $visitor->visitLiteralPredicate(Argument::exact($predicate))->shouldBeCalled(); $predicate->acceptPredicateVisitor($visitor->reveal()); }
function it_match_by_using_finder_and_analyser(FinderInterface $finder, OccurrencesAnalyserInterface $analyser, UserAgentTokenizedToken $token) { $iterator = new \SplObjectStorage(); $occurences = new Occurrences(); $analyser->analyse(Argument::exact($occurences))->shouldBeCalled()->willReturn($iterator); $finder->find($token)->shouldBeCalled()->willReturn($occurences); $this->match($token)->shouldReturn($iterator); }
function it_visit_token(MatcherInterface $matcher, TokenInterface $token, CollatorInterface $collator, MatcherInterface $matcher, MergingStrategyInterface $mergingStrategy, RuleInterface $rule) { $this->beConstructedWith($matcher, $mergingStrategy); $rules = new \ArrayIterator(array($rule->getWrappedObject())); $matcher->match(Argument::exact($token->getWrappedObject()))->shouldBeCalledTimes(1)->willReturn($rules); $mergingStrategy->merge(Argument::exact($rules), Argument::exact($collator->getWrappedObject()))->shouldBeCalledTimes(1); $this->visit($token, $collator)->shouldReturn(VisitorInterface::STATE_SEEKING); }
/** * @param \Doctrine\ORM\EntityManager $em * @param \Symfony\Bundle\FrameworkBundle\Templating\EngineInterface $templating * @param \Newscoop\Entity\Article $article * @param \Newscoop\ArticlesBundle\Entity\Repository\EditorialCommentRepository $repository */ public function let($die, $em, $templating, $article, $repository, Registry $doctrine) { $doctrine->getManager()->willReturn($em); $em->getRepository(Argument::exact('Newscoop\\ArticlesBundle\\Entity\\EditorialComment'))->willReturn($repository); $repository->getAllByArticleNumber(Argument::any(), Argument::any())->willReturn(Argument::any()); $article->getNumber()->willReturn(1); $this->beConstructedWith($em, $templating); }
public function test_it_should_throw_an_exception_after_consecutive_failed() { $processor = $this->prophesize('Swarrot\\Processor\\ProcessorInterface'); $logger = $this->prophesize('Psr\\Log\\LoggerInterface'); $message = new Message('body', array(), 1); $processor->process(Argument::exact($message), Argument::exact(array()))->willThrow('\\BadMethodCallException'); $processor = new ExceptionCatcherProcessor($processor->reveal(), $logger->reveal()); $this->assertNull($processor->process($message, array())); }
function it_return_false_of_regexp_does_not_match(UserAgentToken $token, ConditionInterface $condition, RuleInterface $rule) { $token->__toString()->willReturn('Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.74 Safari/537.36 MRCHROME'); $condition->getValue()->willReturn('#AppleWebKitt(?:/(?P<webkit_version>\\d+[\\.\\d]+))#is'); $condition->getDynamicCapabilities()->shouldNotBeCalled()->willReturn(array('webkit_version')); $rule->getCapabilities()->willReturn(array('applewebkit' => true))->shouldNotBeCalled(); $rule->setCapabilities(Argument::exact(array('applewebkit' => true, 'webkit_version' => '537.36')))->shouldNotBeCalled(); $this->evaluate($token, $condition, $rule)->shouldReturn(false); }
function it_saves_an_attribute_and_flushes_by_default($objectManager, $eventDispatcher, AttributeInterface $attribute) { $attribute->getCode()->willReturn('my_code'); $eventDispatcher->dispatch(Argument::exact(StorageEvents::PRE_SAVE), Argument::type('Symfony\\Component\\EventDispatcher\\GenericEvent'))->shouldBeCalled(); $objectManager->persist($attribute)->shouldBeCalled(); $objectManager->flush()->shouldBeCalled(); $eventDispatcher->dispatch(Argument::exact(StorageEvents::POST_SAVE), Argument::type('Symfony\\Component\\EventDispatcher\\GenericEvent'))->shouldBeCalled(); $this->save($attribute); }
function it_handle_configuration(RuleInterface $rule) { $configuration = array('priority' => 1, 'category' => 'browser', 'capabilities' => array('is_bot' => true), 'conditions' => array(array('type' => 'text', 'value' => 'chrome', 'strategy' => 'sequence', 'capabilities' => array('is_modile' => true)))); $rule->setPriority(Argument::exact($configuration['priority']))->shouldBeCalled(); $rule->setCategory(Argument::exact($configuration['category']))->shouldBeCalled(); $rule->setCapabilities(Argument::exact($configuration['capabilities']))->shouldBeCalled(); $rule->addCondition(Argument::type('DeviceDetectorIO\\DeviceDetector\\Rule\\Condition\\ConditionInterface'))->shouldBeCalled(); $this->handle($configuration, $rule); }
public function testExceptionsAreConvertedToHttpResponses() { $transformer = $this->prophesize('Alchemy\\Rest\\Response\\ExceptionTransformer'); $exception = new \Exception('test', 12); $transformer->transformException(Argument::exact($exception))->willReturn(array('test' => true)); $listener = new ExceptionListener(new ContentTypeMatcher(), $transformer->reveal()); $event = $this->getControllerExceptionEvent($exception); $listener->onKernelException($event); $this->assertHttpJsonResponse($event->getResponse(), 500, array('test' => true)); }
public function testDecoratedExceptionIsCalledWhenRequestMatches() { $event = $this->getControllerExceptionEvent(new \Exception()); $decoratedListener = $this->prophesize('Alchemy\\RestBundle\\EventListener\\ExceptionListener'); $matcher = $this->prophesize('Symfony\\Component\\HttpFoundation\\RequestMatcherInterface'); $decoratedListener->onKernelException(Argument::exact($event))->shouldBeCalled(); $matcher->matches(Argument::any())->willReturn(true); $listener = new RequestMatchingExceptionListener($decoratedListener->reveal(), $matcher->reveal()); $listener->onKernelException($event); }
/** * @dataProvider isGrantedMaskComparisonProvider */ public function testIsGrantedMaskComparison($action, $requiredMask, $mask, $result) { $this->maskBuilder->resolveMask(Argument::exact($action))->willReturn($requiredMask); $this->maskBuilder->get()->willReturn($mask); if ($result) { $this->assertTrue($this->permission->isGranted($action)); } else { $this->assertfalse($this->permission->isGranted($action)); } }
public function test_it_should_throw_an_exception_after_consecutive_failed() { $processor = $this->prophesize('Swarrot\\Processor\\ProcessorInterface'); $logger = $this->prophesize('Psr\\Log\\LoggerInterface'); $message = new Message('body', array(), 1); $processor->process(Argument::type('Swarrot\\Broker\\Message'), Argument::exact(array('instant_retry_attempts' => 3, 'instant_retry_delay' => 1000)))->shouldBeCalledTimes(3)->willThrow('\\BadMethodCallException'); $processor = new InstantRetryProcessor($processor->reveal(), $logger->reveal()); $this->setExpectedException('\\BadMethodCallException'); $processor->process($message, array('instant_retry_attempts' => 3, 'instant_retry_delay' => 1000)); }
function it_passes_the_existing_subject_to_expectation(Wrapper $wrapper, WrappedObject $wrappedObject, Caller $caller, SubjectWithArrayAccess $arrayAccess, ExpectationFactory $expectationFactory, Expectation $expectation) { $existingSubject = new \ArrayObject(); $this->beConstructedWith($existingSubject, $wrapper, $wrappedObject, $caller, $arrayAccess, $expectationFactory); $expectation->match(Argument::cetera())->willReturn(true); $wrappedObject->getClassName()->willReturn('\\ArrayObject'); $expectationFactory->create(Argument::cetera())->willReturn($expectation); $this->callOnWrappedObject('shouldBeAlright'); $expectationFactory->create(Argument::any(), Argument::exact($existingSubject), Argument::any())->shouldHaveBeenCalled(); }
function it_should_have_a_default_success_flash_message_for_event_name($session, $translator, FlashEvent $event, FlashBag $flashBag) { $messages = [SyliusCartEvents::ITEM_ADD_COMPLETED => 'The cart has been successfully updated.']; $event->getMessage()->willReturn(null); $event->getName()->willReturn(SyliusCartEvents::ITEM_ADD_COMPLETED); $session->getBag(Argument::exact('flashes'))->willReturn($flashBag); $translator->trans(Argument::cetera())->willReturn($messages[SyliusCartEvents::ITEM_ADD_COMPLETED]); $flashBag->add('success', $messages[SyliusCartEvents::ITEM_ADD_COMPLETED])->willReturn(null); $this->addSuccessFlash($event); }
public function it_does_not_create_requirement_without_family($eventArgs, $entityManager, $repository, $family) { $eventArgs->getEntityManager()->shouldBeCalled(); $entityManager->getRepository(Argument::exact('PimCatalogBundle:Family'))->shouldBeCalled(); $repository->findAll()->willReturn([])->shouldBeCalled(); $family->getAttributes()->shouldNotBeCalled(); $entityManager->persist(Argument::any())->shouldNotBeCalled(); $entityManager->persist(Argument::any())->shouldNotBeCalled(); $this->prePersist($eventArgs)->shouldReturn(null); }
function it_increment_line_strategy(OccurrenceInterface $current, ConditionInterface $currentCondition, NodeInterface $currentNode, OccurrenceInterface $previous, NodeInterface $previousNode) { $current->getCondition()->shouldBeCalled()->willReturn($currentCondition); $current->getNode()->shouldBeCalled()->willReturn($currentNode); $previous->getNode()->shouldBeCalled()->willReturn($previousNode); $currentCondition->isStrategy(Argument::exact(ConditionInterface::STRATEGY_NEXT))->shouldBeCalled()->willReturn(false); $currentNode->getPosition()->shouldBeCalled()->willReturn(3); $previousNode->getPosition()->shouldBeCalled()->willReturn(1); $this->oughtToBeIncrement($current, $previous)->shouldReturn(true); }
function it_return_true_if_text_types_not_correspond(NodeInterface $node, ConditionInterface $condition) { $node->isType(Argument::exact(NodeInterface::TYPE_SPACE))->willReturn(false); $condition->isType(Argument::exact(ConditionInterface::TYPE_SPACE))->willReturn(false); $condition->isType(Argument::exact(ConditionInterface::TYPE_PLACEHOLDER))->willReturn(false); $node->isType(Argument::exact(NodeInterface::TYPE_TEXT))->willReturn(true)->shouldBeCalledTimes(1); $condition->isType(Argument::exact(ConditionInterface::TYPE_TEXT))->willReturn(true)->shouldBeCalledTimes(1); $node->getValue()->willReturn('value')->shouldBeCalledTimes(1); $condition->getValue()->willReturn('value')->shouldBeCalledTimes(1); $this->areEquals($node, $condition)->shouldReturn(true); }
function it_is_serializable(UserAgentTokenizer $tokenizer) { $userAgent = 'Mozilla/5.0 (Linux; U; Android 1.0; en-us; generic) AppleWebKit/525.10 (KHTML, like Gecko) Version/3.0.4 Mobile Safari/523.12.2'; $tokenizer->tokenize(Argument::exact($userAgent))->shouldBeCalledTimes(1)->willReturn(array('mozilla', 'linux')); $token = new UserAgentToken($userAgent); $this->beConstructedWith($token, $tokenizer); $this->serialize()->shouldReturn(serialize(array('tokens' => array('mozilla', 'linux'), 'token' => $token))); $data = array('tokens' => array('mozilla', 'windows'), 'token' => $token); $this->unserialize(serialize($data)); $this->getData()->shouldReturn($data['tokens']); }
function it_should_create_project(ProjectRepository $projectRepository, EventDispatcherInterface $eventDispatcher, Project $project, CreateProjectAction $action) { $action->getName()->willReturn('Foo bar'); $action->getSlug()->willReturn('foobar'); $action->getDefaultLocale()->willReturn('fr_FR'); $action->getDescription()->willReturn(''); $projectRepository->createNew(Argument::exact(new Slug('foobar')))->willReturn($project); $projectRepository->save($project)->shouldBeCalled(); $eventDispatcher->dispatch(CreateProjectEvent::NAME, Argument::type('Openl10n\\Domain\\Project\\Application\\Event\\CreateProjectEvent'))->shouldBeCalled(); $this->execute($action)->shouldReturn($project); }
public function test_publish_with_valid_message() { $channel = $this->prophesize('PhpAmqpLib\\Channel\\AMQPChannel'); $channel->basic_publish(Argument::that(function (AMQPMessage $message) { $properties = $message->get_properties(); return 'body' === $message->body && empty($properties); }), Argument::exact('swarrot'), Argument::exact(''))->shouldBeCalledTimes(1); $provider = new PhpAmqpLibMessagePublisher($channel->reveal(), 'swarrot'); $return = $provider->publish(new Message('body')); $this->assertNull($return); }
public function test_write_when_session_is_locked() { $client = $this->prophet->prophesize('Blablacar\\Redis\\Test\\Client'); $client->set(Argument::exact('session:lock_fail.lock'), Argument::exact(1), Argument::type('array'))->willReturn(false); $client->get(Argument::type('string'))->willReturn(true)->shouldBeCalledTimes(1); $client->ttl(Argument::type('string'))->willReturn(true)->shouldBeCalledTimes(1); $client->del(Argument::type('string'))->willReturn(true)->shouldBeCalledTimes(1); $handler = new SessionHandler($client->reveal(), 'session', 3600, 150000, 450000); $this->setExpectedException('Blablacar\\Redis\\Exception\\LockException'); $handler->write('lock_fail', 'value'); }
/** * @expectedException \PSU\Exception\HttpClientException */ public function testGetJsonResponseFailure() { // test values $url = 'http://foo.com'; //mock methods $this->responseInterface->getStatusCode()->willReturn(500)->shouldBeCalledTimes(1); $this->clientInterface->get(Argument::exact($url))->willReturn($this->responseInterface->reveal())->shouldBeCalledTimes(1); // init object $guzzlAdapter = new GuzzlApapter($this->clientInterface->reveal()); // test $this->assertNull($guzzlAdapter->getJsonResponse($url)); }