/** * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container * @param \Doctrine\Common\Annotations\AnnotationReader $annotationReader * @param \FSi\Bundle\AdminBundle\Finder\AdminClassFinder $adminClassFinder */ function it_registers_annotated_admin_classes_as_services($container, $annotationReader, $adminClassFinder) { $container->getParameter('kernel.bundles')->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\MyBundle', 'FSi\\Bundle\\AdminBundle\\FSiAdminBundle', 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle')); $baseDir = __DIR__ . '/../../../../../..'; $adminClassFinder->findClasses(array(realpath($baseDir . '/spec/fixtures/Admin'), realpath($baseDir . '/Admin')))->willReturn(array('FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement')); $annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\CRUDElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(null); $annotationReader->getClassAnnotation(Argument::allOf(Argument::type('ReflectionClass'), Argument::which('getName', 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement')), 'FSi\\Bundle\\AdminBundle\\Annotation\\Element')->willReturn(new Element(array())); $container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/spec/fixtures/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled(); $container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\DirectoryResource'), Argument::which('getResource', realpath($baseDir . '/Admin')), Argument::which('getPattern', '/\\.php$/')))->shouldBeCalled(); $container->addDefinitions(Argument::that(function ($definitions) { if (count($definitions) !== 1) { return false; } /** @var \Symfony\Component\DependencyInjection\Definition $definition */ $definition = $definitions[0]; if ($definition->getClass() !== 'FSi\\Bundle\\AdminBundle\\spec\\fixtures\\Admin\\SimpleAdminElement') { return false; } if (!$definition->hasTag('admin.element')) { return false; } return true; }))->shouldBeCalled(); $this->process($container); }
function it_render_template_with_paginator(EngineInterface $templating, Response $response, GalleryManagerInterface $galleryManager, AdapterInterface $adapter) { $galleryManager->createPagerfantaAdapter()->willReturn($adapter); $adapter->getNbResults()->willReturn(5); $templating->renderResponse('FSiGalleryBundle:Gallery:list.html.twig', Argument::allOf(Argument::withEntry('galleries', Argument::type('Pagerfanta\\Pagerfanta')), Argument::withEntry('preview_photos_count', 4)))->willReturn($response); $this->listAction(2)->shouldReturn($response); }
public function testShouldDispatchEvents() { $notification = Email::create(); $notifyArg = Argument::allOf(Argument::type(Email::class), Argument::that(function ($arg) use($notification) { return $arg !== $notification; })); $handler = $this->prophesize(NotificationHandlerInterface::class); $handler->getName()->willReturn('default'); $handler->supports(Argument::any())->willReturn(true); $handler->notify($notifyArg)->willReturn(); $handler2 = $this->prophesize(NotificationHandlerInterface::class); $handler2->getName()->willReturn('default'); $handler2->supports(Argument::any())->willReturn(true); $handler2->notify($notifyArg)->willReturn(); $this->dispatcher->dispatch('notifire.pre_notify', Argument::type(PreNotifyEvent::class))->shouldBeCalled(); $this->dispatcher->dispatch('notifire.notify', Argument::that(function ($arg) use($notification) { if (!$arg instanceof NotifyEvent) { return false; } $not = $arg->getNotification(); return $not !== $notification; }))->shouldBeCalledTimes(2); $this->dispatcher->dispatch('notifire.post_notify', Argument::type(PostNotifyEvent::class))->shouldBeCalled(); $this->manager->addHandler($handler->reveal()); $this->manager->addHandler($handler2->reveal()); $this->manager->notify($notification); }
public function it_set_controller_if_init_return_response(FilterControllerEvent $event, Request $request, SampleInitController $controller) { $event->getRequest()->willReturn($request); $event->getController()->willReturn(array($controller)); $controller->init($request)->willReturn(new Response('http://example.com/')); $event->setController(Argument::allOf(Argument::withEntry('0', Argument::type('Yavin\\Symfony\\Controller\\InitControllerSubscriber')), Argument::withEntry('1', 'responseAction')))->shouldBeCalled(); $this->onKernelController($event); }
function it_adds_new_entity_with_field_set(MapBuilder $builder, ResourceRepository $repository, TextType $resource) { $resource->getName()->willReturn('resources_group.resource_a.en'); $repository->get('resources_group.resource_a.en')->willReturn(null); $builder->getResource(Argument::type('string'))->willReturn($resource); $resource->getResourceProperty()->willReturn('textValue'); $repository->add(Argument::allOf(Argument::type('spec\\FSi\\Bundle\\ResourceRepositoryBundle\\Repository\\ResourceEntity'), Argument::which('getTextValue', 'text')))->shouldBeCalled(); $this->set('resources_group.resource_a', 'text'); }
public function testUseNameAsAttributeIfServiceAndIdentIsGiven() { $serviceName = 'some-service'; $identAttribute = 'source'; $client = $this->getRiemannClient(); $logger = new Logger($client->reveal(), $serviceName, $identAttribute); $logger->log(['service' => 'foo']); $client->sendEvent(Argument::allOf(Argument::withEntry('service', 'foo'), Argument::withEntry('attributes', [['key' => $identAttribute, 'value' => $serviceName]])))->shouldHaveBeenCalled(); }
/** * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container * @param \Symfony\Component\DependencyInjection\ParameterBag\ParameterBag $bag */ public function it_loads_resources_config_only_if_resource_repository_extension_exists($container, $bag) { $container->hasExtension(Argument::type('string'))->willReturn(false); $container->hasExtension('fsi_resource_repository')->willReturn(true); $container->addResource(Argument::allOf(Argument::type('Symfony\\Component\\Config\\Resource\\FileResource'), Argument::that(function ($value) { return $value instanceof FileResource && preg_match('/context\\/resource\\.xml$/', $value->getResource()); })))->shouldBeCalled(); $container->getParameterBag()->willReturn($bag); $container->setDefinition(Argument::type('string'), Argument::type('Symfony\\Component\\DependencyInjection\\Definition'))->shouldBeCalled(); $this->process($container); }
public function testTagging() { $definitionObserver = $this->prophesize('\\Symfony\\Component\\DependencyInjection\\Definition'); $definitionObserver->addMethodCall("addHelper", Argument::allOf(Argument::containing('test'), Argument::containing(new Reference('handlebars.helper.test'))))->shouldBeCalled(); $containerObserver = $this->prophesize('\\Symfony\\Component\\DependencyInjection\\ContainerBuilder'); $containerObserver->has('handlebars.helper')->willReturn(true)->shouldBeCalled(); $containerObserver->findDefinition('handlebars.helper')->willReturn($definitionObserver->reveal())->shouldBeCalled(); $taggedServices = ['handlebars.helper.test' => [['id' => 'test']]]; $containerObserver->findTaggedServiceIds('handlebars.helper')->willReturn($taggedServices)->shouldBeCalled(); $helperPass = new HelperPass(); $helperPass->process($containerObserver->reveal()); }
/** * @param \FSi\Bundle\AdminSecurityBundle\Model\UserPasswordResetInterface $user * @param \Twig_Environment $twig * @param \Twig_Template $template * @param \Swift_Mailer $mailer * @param \Symfony\Component\HttpFoundation\RequestStack $requestStack */ function it_should_render_template($user, $twig, $template, $mailer, $requestStack) { $request = new Request(array(), array(), array(), array(), array(), array('HTTP_USER_AGENT' => 'user agent', 'REMOTE_ADDR' => '192.168.99.99')); $requestStack->getMasterRequest()->willReturn($request); $templateParameters = array('user' => $user, 'ip' => '192.168.99.99', 'user_agent' => 'user agent'); $twig->mergeGlobals($templateParameters)->willReturn($templateParameters); $twig->loadTemplate('mailer-template.html.twig')->willReturn($template); $template->renderBlock('subject', $templateParameters)->willReturn('subject string'); $template->renderBlock('body_html', $templateParameters)->willReturn('body string'); $user->getEmail()->willReturn('*****@*****.**'); $mailer->send(Argument::allOf(Argument::type('\\Swift_Message'), Argument::which('getSubject', 'subject string'), Argument::which('getTo', array('*****@*****.**' => null)), Argument::which('getFrom', array('*****@*****.**' => null)), Argument::which('getReplyTo', array('*****@*****.**' => null)), Argument::which('getBody', 'body string')))->willReturn(1); $this->sendPasswordResetMail($user)->shouldReturn(1); }
/** * @test */ public function preConsume_should_log_debug_message() { $body = 'payload-body'; $messageName = 'message-name'; $methodName = 'MyClass::myMethod'; /** @var ConsumerContainer $consumerContainer */ $consumerContainer = $this->prophesize(ConsumerContainer::class); $consumerContainer->getRoutingKey()->willReturn($messageName); $consumerContainer->getMethodName()->willReturn($methodName); $event = new ConsumerEvent(new AMQPMessage($body), $consumerContainer->reveal()); $this->subscriber->preConsume($event); $this->logger->debug(Argument::allOf(Argument::containingString($messageName), Argument::containingString($methodName), Argument::containingString($body)))->shouldHaveBeenCalled(); }
/** * @test */ public function handle_should_log_message_with_payload() { $exceptionMessage = "Fatal error"; $baseException = new Exception($exceptionMessage); $payloadMessage = $this->prophesize(MessageInterface::class); $exception = new ConsumerContainerException($this->consumerContainer->reveal(), new AMQPMessage(), $payloadMessage->reveal(), $baseException); $this->handler->handle($exception); $this->logger->warning(Argument::allOf(Argument::containingString(self::MESSAGE_CLASS), Argument::containingString($exceptionMessage)), Argument::that(function ($context) use($baseException) { verify($context['exception'])->isInstanceOf(ConsumerContainerException::class); verify($context['exception']->getPrevious())->equals($baseException); return $context; }))->shouldHaveBeenCalled(); }
public function testLoadTemplateAndCompileWithoutAutoReload() { $loader = $this->prophesize('JaySDe\\HandlebarsBundle\\Loader\\FilesystemLoader'); $loader->getCacheKey('test')->willReturn(__DIR__ . '/Fixtures/Resources/views/main.hbs'); $loader->getSource('test')->willReturn(__DIR__ . '/Fixtures/Resources/views/main.hbs'); $helper = $this->prophesize('JaySDe\\HandlebarsBundle\\HandlebarsHelperService'); $profiler = $this->prophesize('JaySDe\\HandlebarsBundle\\HandlebarsProfileExtension'); $cache = $this->prophesize('JaySDe\\HandlebarsBundle\\Cache\\Filesystem'); $cache->generateKey('test')->willReturn('test'); $cache->write('test', Argument::type('string'), Argument::allOf(Argument::containing(new FileResource(__DIR__ . '/Fixtures/Resources/views/main.hbs'))))->shouldBeCalled(); $cache->load('test')->shouldBeCalled(); $environment = new HandlebarsEnvironment($loader->reveal(), $helper->reveal(), ['auto_reload' => false], $cache->reveal(), $profiler->reveal()); $environment->loadTemplate('test'); }
function let(RouterInterface $router, IdentityResolver $identityResolver, DefinitionInterface $definition, \stdClass $object) { $this->beConstructedWith($router, $identityResolver); $router->generate('bravesheep_crudify.index', Argument::withKey('mapping'))->will(function ($args) { return '/' . $args[1]['mapping'] . '/index'; }); $router->generate('bravesheep_crudify.new', Argument::withKey('mapping'))->will(function ($args) { return '/' . $args[1]['mapping'] . '/new'; }); $router->generate('bravesheep_crudify.create', Argument::withKey('mapping'))->will(function ($args) { return '/' . $args[1]['mapping'] . '/create'; }); $router->generate('bravesheep_crudify.edit', Argument::allOf(Argument::withKey('mapping'), Argument::withKey('id')))->will(function ($args) { return '/' . $args[1]['mapping'] . '/edit/' . $args[1]['id']; }); $router->generate('bravesheep_crudify.update', Argument::allOf(Argument::withKey('mapping'), Argument::withKey('id')))->will(function ($args) { return '/' . $args[1]['mapping'] . '/update/' . $args[1]['id']; }); $router->generate('bravesheep_crudify.delete', Argument::allOf(Argument::withKey('mapping'), Argument::withKey('id')))->will(function ($args) { return '/' . $args[1]['mapping'] . '/delete/' . $args[1]['id']; }); $definition->getName()->willReturn('test'); $identityResolver->getId($definition, $object)->willReturn(42); }
/** * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver */ function it_should_set_default_options($resolver) { $resolver->setDefaults(Argument::allOf(Argument::withEntry('data_class', 'FSi\\DoctrineExtensions\\Uploadable\\File'), Argument::withEntry('constraints', Argument::withEntry(0, Argument::type('\\FSi\\Bundle\\DoctrineExtensionsBundle\\Validator\\Constraints\\File')))))->shouldBeCalled(); $this->setDefaultOptions($resolver); }
private function isAnArrayContainingAReferenceAndAPriority($service, $priority) { return Argument::allOf(Argument::withEntry(0, Argument::allOf(Argument::type('Symfony\\Component\\DependencyInjection\\Reference'), Argument::which('__toString', $service)))); }
function it_should_return_inventory($client, $logger) { $this->getInventory()->shouldReturn(array()); $client->GetInventory(Argument::allOf(Argument::withEntry('ControlReference', Argument::type('YellowCube\\ControlReference'))))->shouldHaveBeenCalled(); $logger->info(Argument::type('string'), Argument::any())->shouldHaveBeenCalled(); }
/** * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */ public function it_should_emit_proper_event($dispatcher) { $dispatcher->dispatch('fsi_admin.menu.tools', Argument::allOf(Argument::type('FSi\\Bundle\\AdminBundle\\Event\\MenuEvent')))->shouldBeCalled(); $this->buildMenu()->shouldReturnAnInstanceOf('FSi\\Bundle\\AdminBundle\\Menu\\Item\\Item'); }
function it_applies_more_than_date_range_filter(FilterDatasourceAdapterInterface $datasource, \DateTime $start, \DateTime $end, $utility) { $start->setTimezone(Argument::allOf(Argument::type('\\DateTimeZone'), Argument::which('getName', 'UTC')))->shouldBeCalled(); $end->setTimezone(Argument::allOf(Argument::type('\\DateTimeZone'), Argument::which('getName', 'UTC')))->shouldBeCalled(); $start->format('Y-m-d')->willReturn('1987-05-14'); $end->format('Y-m-d')->willReturn('2014-01-23'); $utility->applyFilter($datasource, 'data_name_key', '>', '1987-05-14')->shouldBeCalled(); $this->apply($datasource, ['value' => ['start' => $start, 'end' => $end], 'type' => DateRangeFilterType::TYPE_MORE_THAN]); }