/** * @test */ public function it_does_not_fail_if_the_synthetic_service_has_been_provided_already() { $this->containerBuilder->setDefinition('synthetic_service', $this->createSyntheticDefinition()); $this->containerBuilder->set('synthetic_service', new \stdClass()); $constraint = new ContainerBuilderHasSyntheticServiceConstraint('synthetic_service'); $this->assertConstraintPasses($constraint); }
protected function setUp() { $this->extension = new GGTeamBreadcrumbExtension(); $this->container = new ContainerBuilder(); $this->container->registerExtension($this->extension); $this->container->set('templating', $this->getMockTemplatingEngine()); }
/** * @return mixed */ protected function buildContainer(ContainerBuilder $container) { $cacheDir = THELIA_CACHE_DIR . "test"; if (!is_dir($cacheDir)) { mkdir($cacheDir); } $archiveBuilders = [new ZipArchiveBuilder(), new TarArchiveBuilder(), new TarBz2ArchiveBuilder(), new TarGzArchiveBuilder()]; $archiveBuilderManager = new ArchiveBuilderManager("test"); /** * @var \Thelia\Core\FileFormat\Archive\AbstractArchiveBuilder $archiveBuilder */ foreach ($archiveBuilders as $key => $archiveBuilder) { if (!$archiveBuilder->isAvailable()) { unset($archiveBuilders[$key]); } else { $archiveBuilderManager->add($archiveBuilder); } } if (empty($archiveBuilders)) { $this->markTestSkipped("You don't have any archive builder, you can't run this test"); } $container->set("thelia.manager.archive_builder_manager", $archiveBuilderManager); $formatterManager = (new FormatterManager())->add(new XMLFormatter())->add(new JsonFormatter())->add(new CSVFormatter()); $container->set("thelia.manager.formatter_manager", $formatterManager); }
protected function getContainer() { $container = new ContainerBuilder(); $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../../../Resources/config')); $loader->load('monolog.xml'); $definition = $container->getDefinition('monolog.logger_prototype'); $container->set('monolog.handler.test', new Definition('%monolog.handler.null.class%', array(100, false))); $definition->addMethodCall('pushHandler', array(new Reference('monolog.handler.test'))); // Handlers $container->set('monolog.handler.a', new Definition('%monolog.handler.null.class%', array(100, false))); $container->set('monolog.handler.b', new Definition('%monolog.handler.null.class%', array(100, false))); $container->set('monolog.handler.c', new Definition('%monolog.handler.null.class%', array(100, false))); // Channels foreach (array('test', 'foo', 'bar') as $name) { $service = new Definition('TestClass', array('false', new Reference('logger'))); $service->addTag('monolog.logger', array('channel' => $name)); $container->setDefinition($name, $service); } $container->setParameter('monolog.handlers_to_channels', array('monolog.handler.a' => array('type' => 'inclusive', 'elements' => array('test')), 'monolog.handler.b' => null, 'monolog.handler.c' => array('type' => 'exclusive', 'elements' => array('foo')))); $container->getCompilerPassConfig()->setOptimizationPasses(array()); $container->getCompilerPassConfig()->setRemovingPasses(array()); $container->addCompilerPass(new LoggerChannelPass()); $container->compile(); return $container; }
protected function setUp() { if (!class_exists('Assetic\\AssetManager')) { $this->markTestSkipped('Assetic is not available.'); } if (!class_exists('Twig_Environment')) { $this->markTestSkipped('Twig is not available.'); } $this->kernel = $this->getMockBuilder('Symfony\\Component\\HttpKernel\\KernelInterface')->getMock(); $this->container = new ContainerBuilder(); // Symfony 2.3 BC if (!method_exists('Symfony\\Component\\DependencyInjection\\Definition', 'setShared')) { $this->container->addScope(new Scope('request')); $this->container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request'); } // Symfony <2.7 BC if (class_exists('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\AssetsHelper')) { $this->container->register('assets.packages', $this->getMockClass('Symfony\\Component\\Asset\\Packages')); $this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\AssetsHelper'))->addArgument(new Reference('assets.packages')); } elseif (class_exists('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')) { $this->container->register('templating.helper.assets', $this->getMockClass('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Templating\\Asset\\PackageInterface'))); } $this->container->register('templating.helper.router', $this->getMockClass('Symfony\\Bundle\\FrameworkBundle\\Templating\\Helper\\RouterHelper'))->addArgument(new Definition($this->getMockClass('Symfony\\Component\\Routing\\RouterInterface'))); $this->container->register('twig', 'Twig_Environment')->addArgument(new Definition($this->getMockClass('Twig_LoaderInterface'))); $this->container->setParameter('kernel.bundles', array()); $this->container->setParameter('kernel.cache_dir', __DIR__); $this->container->setParameter('kernel.debug', false); $this->container->setParameter('kernel.root_dir', __DIR__); $this->container->setParameter('kernel.charset', 'UTF-8'); $this->container->set('kernel', $this->kernel); $this->container->addCompilerPass(new StaticAsseticHelperPass()); }
public function testLoad() { $container = new ContainerBuilder(); // fake entity manager and security context services $container->set('doctrine.orm.entity_manager', $this->getSqliteEntityManager()); $container->set('security.authorization_checker', $this->getMockAuthorizationChecker()); $container->set('event_dispatcher', new EventDispatcher()); $container->set('next_state_condition', new \stdClass()); // simple config $extension = new WorkflowExtension(); $extension->load(array($this->getSimpleConfig()), $container); $this->assertTrue($container->getDefinition('lexik_workflow.process.document_proccess') instanceof Definition); // config with a process $extension = new WorkflowExtension(); $extension->load(array($this->getConfig()), $container); $this->assertTrue($container->getDefinition('lexik_workflow.process.document_proccess') instanceof Definition); $this->assertTrue($container->getDefinition('lexik_workflow.process.document_proccess.step.step_create_doc') instanceof Definition); $this->assertTrue($container->getDefinition('lexik_workflow.process.document_proccess.step.step_validate_doc') instanceof Definition); $this->assertTrue($container->getDefinition('lexik_workflow.process.document_proccess.step.step_remove_doc') instanceof Definition); $this->assertTrue($container->getDefinition('lexik_workflow.handler.document_proccess') instanceof Definition); $processHandlerFactory = $container->get('lexik_workflow.process_aggregator'); $this->assertTrue($processHandlerFactory instanceof ProcessAggregator); $this->assertTrue($processHandlerFactory->getProcess('document_proccess') instanceof Process); $processHandler = $container->get('lexik_workflow.handler.document_proccess'); $this->assertTrue($processHandler instanceof ProcessHandler); }
/** * Create a new container. * * @return ContainerInterface */ protected function createContainer() { $container = new ContainerBuilder(); // Default configuration. $container->set('application', $this); $container->set('configuration.loader', $this->configurationLoader); $container->set('extension_manager', $this->extensionManager); // Initialize extensions. $this->extensionManager->initialize($container); // Load configuration. try { $rawConfigs = $this->configurationLoader->loadConfiguration(); $this->extensionManager->load($rawConfigs, $container); } catch (ConfigurationLoadingException $e) { // No configuration file found. // Continue with restricted services if `ignoreMissingConfiguration` // has been specified. if (!$this->ignoreMissingConfiguration) { throw $e; } } // Process compiler pass & compile container $container->compile(); return $container; }
public static function createContainer() { $logDir = __DIR__ . '/../data/logs'; if (!file_exists($logDir)) { mkdir($logDir); } $container = new ContainerBuilder(); $container->set('doctrine_phpcr.default_session', self::createSession()); $logger = new Logger('test'); $logger->pushHandler(new StreamHandler($logDir . '/test.log')); $dispatcher = new ContainerAwareEventDispatcher($container); $container->set('sulu_document_manager.event_dispatcher', $dispatcher); $config = ['sulu_document_manager.default_locale' => 'en', 'sulu_document_manager.mapping' => ['full' => ['alias' => 'full', 'phpcr_type' => 'mix:test', 'class' => 'Sulu\\Component\\DocumentManager\\Tests\\Functional\\Model\\FullDocument']], 'sulu_document_manager.namespace_mapping' => ['system' => 'nsys', 'system_localized' => 'lsys', 'content' => 'ncont', 'content_localized' => 'lcont']]; foreach ($config as $parameterName => $parameterValue) { $container->setParameter($parameterName, $parameterValue); } $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../symfony-di')); $loader->load('core.xml'); $loader->load('subscribers.xml'); foreach (array_keys($container->findTaggedServiceIds('sulu_document_manager.event_subscriber')) as $subscriberId) { $def = $container->get($subscriberId); $dispatcher->addSubscriberService($subscriberId, get_class($def)); } return $container; }
public function testConfigLoad() { $builder = new ContainerBuilder(); // external services $builder->set('doctrine.orm.entity_manager', new \stdClass()); $builder->set('security.token_storage', new \stdClass()); $bundle = new ModeraBackendDashboardBundle(); $bundle->build($builder); $ext = new ModeraBackendDashboardExtension(); $ext->load(array(), $builder); $builder->compile(); $this->assertTrue($builder->has('modera_backend_dashboard.contributions.menu_items_provider')); $menuProvider = $builder->getDefinition('modera_backend_dashboard.contributions.menu_items_provider'); $this->assertEquals('Modera\\BackendDashboardBundle\\Contributions\\MenuItemsProvider', $menuProvider->getClass()); $this->assertTrue($menuProvider->hasTag('modera_mjr_integration.menu.menu_items_provider')); // service provided by Expander bundle $this->assertTrue($builder->has('modera_backend_dashboard.dashboard_provider')); $this->assertTrue($builder->has('modera_backend_dashboard.dashboard_service')); $arg = $builder->getDefinition('modera_backend_dashboard.dashboard_service')->getArgument(0); $this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Reference', $arg); /* @var \Symfony\Component\DependencyInjection\Reference $arg */ $this->assertEquals('modera_backend_dashboard.dashboard_provider', $arg->__toString()); $this->assertTrue($builder->has('modera_backend_dashboard.contributions.config_mergers_provider')); $configProvider = $builder->getDefinition('modera_backend_dashboard.contributions.config_mergers_provider'); $this->assertTrue($configProvider->hasTag('modera_mjr_integration.config.config_mergers_provider')); }
protected function createContainer() { $container = new ContainerBuilder(); $container->set('config', $this->config); $container->set('client', $this->client); return $container; }
/** * {@inheritdoc} */ protected function setUp() { $container = new ContainerBuilder(); $bin_dir = dirname(__DIR__) . '/'; $loader = new YamlFileLoader($container, new FileLocator($bin_dir)); $loader->load('services.yml'); $test_directory = sys_get_temp_dir() . '/' . uniqid('tl'); mkdir($test_directory); file_put_contents($test_directory . '/.tl.yml', Yaml::dump(['url' => 'http://example.com'])); $container->setParameter('directory', $test_directory); $mock_connector = $this->getMock(Connector::class); $container->set('connector', $mock_connector); $configuration_processor = $this->getMock(Processor::class); $configuration_processor->expects($this->any())->method('processConfiguration')->willReturn([]); $container->set('config.processor', $configuration_processor); $this->container = $container; $this->application = new Application('Time logger', 'testing', $container); if ($this->installSchema) { $install = $container->get('app.command.install'); $install->setApplication($this->application); $input = new ArrayInput(['command' => 'install']); $output = $this->getMock(OutputInterface::class); $install->run($input, $output); } }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->container = new ContainerBuilder(); $cache_contexts_manager = $this->prophesize(CacheContextsManager::class)->reveal(); $this->container->set('cache_contexts_manager', $cache_contexts_manager); \Drupal::setContainer($this->container); }
public function setUp() { parent::setUp(); global $auth, $cache, $config, $db, $phpbb_container, $phpbb_dispatcher, $user, $request, $phpEx, $phpbb_root_path, $user_loader; // Database $this->db = $this->new_dbal(); $db = $this->db; // Auth $auth = $this->getMock('\\phpbb\\auth\\auth'); $auth->expects($this->any())->method('acl_get')->with($this->stringContains('_'), $this->anything())->will($this->returnValueMap(array(array('f_noapprove', 1, true), array('f_postcount', 1, true), array('m_edit', 1, false)))); // Config $config = new \phpbb\config\config(array('num_topics' => 1, 'num_posts' => 1, 'allow_board_notifications' => true)); $cache_driver = new \phpbb\cache\driver\dummy(); $cache = new \phpbb\cache\service($cache_driver, $config, $db, $phpbb_root_path, $phpEx); // Event dispatcher $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); // User $user = $this->getMock('\\phpbb\\user', array(), array(new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)), '\\phpbb\\datetime')); $user->ip = ''; $user->data = array('user_id' => 2, 'username' => 'user-name', 'is_registered' => true, 'user_colour' => ''); // Request $type_cast_helper = $this->getMock('\\phpbb\\request\\type_cast_helper_interface'); $request = $this->getMock('\\phpbb\\request\\request'); $phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $user_loader = new \phpbb\user_loader($db, $phpbb_root_path, $phpEx, USERS_TABLE); // Container $phpbb_container = new ContainerBuilder(); $loader = new YamlFileLoader($phpbb_container, new FileLocator(__DIR__ . '/fixtures')); $loader->load('services_notification.yml'); $phpbb_container->set('user_loader', $user_loader); $phpbb_container->set('user', $user); $phpbb_container->set('config', $config); $phpbb_container->set('dbal.conn', $db); $phpbb_container->set('auth', $auth); $phpbb_container->set('cache.driver', $cache_driver); $phpbb_container->set('cache', $cache); $phpbb_container->set('text_formatter.utils', new \phpbb\textformatter\s9e\utils()); $phpbb_container->set('dispatcher', $phpbb_dispatcher); $phpbb_container->setParameter('core.root_path', $phpbb_root_path); $phpbb_container->setParameter('core.php_ext', $phpEx); $phpbb_container->setParameter('tables.notifications', 'phpbb_notifications'); $phpbb_container->setParameter('tables.user_notifications', 'phpbb_user_notifications'); $phpbb_container->setParameter('tables.notification_types', 'phpbb_notification_types'); $phpbb_container->set('content.visibility', new \phpbb\content_visibility($auth, $config, $phpbb_dispatcher, $db, $user, $phpbb_root_path, $phpEx, FORUMS_TABLE, POSTS_TABLE, TOPICS_TABLE, USERS_TABLE)); $phpbb_container->compile(); // Notification Types $notification_types = array('quote', 'bookmark', 'post', 'post_in_queue', 'topic', 'topic_in_queue', 'approve_topic', 'approve_post'); $notification_types_array = array(); foreach ($notification_types as $type) { $class = $phpbb_container->get('notification.type.' . $type); $notification_types_array['notification.type.' . $type] = $class; } // Methods Types $notification_methods_array = array('notification.method.board' => $phpbb_container->get('notification.method.board')); // Notification Manager $phpbb_notifications = new \phpbb\notification\manager($notification_types_array, $notification_methods_array, $phpbb_container, $user_loader, $phpbb_dispatcher, $db, $cache, $user, NOTIFICATION_TYPES_TABLE, USER_NOTIFICATIONS_TABLE); $phpbb_container->set('notification_manager', $phpbb_notifications); }
public function testLoadServicesWithDefaults() { $this->extension->load(array('alter_ego' => array('app_id' => '123456')), $this->container); $this->container->set('buzz', $this->getMockBuilder('Buzz\\Browser')->disableOriginalConstructor()->getMock()); $this->container->set('router', $this->getMock('Symfony\\Component\\Routing\\Generator\\UrlGeneratorInterface')); $this->assertService('AlterEgo\\Symfony\\Authorization', 'alter_ego.auth'); $this->assertService('AlterEgo\\Client', 'alter_ego.client'); $this->assertAlias('alter_ego.client', 'alter_ego'); }
public function testSplitDriver() { $this->container->setParameter('kernel.debug', false); // Mock channel, otherwise php-amqplib will try to connect to AMQP server $this->container->set('seven_service_bus.amqp_channel', $this->createMock(AMQPChannel::class)); $this->load(['service' => ['name' => 'phpunit'], 'jsonrpc' => [], 'amqp' => []]); $driver = $this->container->get('seven_service_bus.driver'); $this->assertInstanceOf(SplitDriver::class, $driver); }
public function getContainer() { $container = new ContainerBuilder(); $container->set("event_dispatcher", $this->getDispatcher()); $request = new Request(); $request->setSession($this->session); $container->set("request", $request); return $container; }
/** * @param string $id * @param mixed $service */ public static function set($id, $service) { if (self::$container === null || self::$container->isFrozen()) { self::load(); } self::$container->set($id, $service); $definition = new Definition(get_class($service)); self::$container->setDefinition($id, $definition); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $container = new ContainerBuilder(); $config_factory = $this->getConfigFactoryStub(array()); $container->set('config.factory', $config_factory); $container->set('app.root', $this->root); \Drupal::setContainer($container); $this->container = $container; }
/** * {@inheritdoc} */ protected function setUp() { $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $this->breadcrumbManager = new BreadcrumbManager($this->moduleHandler); $this->breadcrumb = new Breadcrumb(); $this->container = new ContainerBuilder(); $cache_contexts_manager = $this->prophesize(CacheContextsManager::class)->reveal(); $this->container->set('cache_contexts_manager', $cache_contexts_manager); \Drupal::setContainer($this->container); }
public function set($id, $service, $scope = self::SCOPE_CONTAINER) { if (!in_array($id, $this->ownServiceIds)) { if ($this->delegate->has($id)) { throw new \LogicException('forbidden'); } else { $this->ownServiceIds[] = $id; } } $this->delegate->set($id, $service, $scope); }
/** * {@inheritdoc} */ protected function setUp() { $this->requestMock = $this->getMock('Symfony\\Component\\HttpFoundation\\Request'); $this->container = new ContainerBuilder(); $this->container->addScope(new Scope('request')); $this->container->setParameter('templating.engines', array('php', 'twig')); $this->container->set('request', $this->requestMock); $this->container->registerExtension(new IvoryGoogleMapExtension()); $this->container->registerExtension($httpAdapterExtension = new WidopHttpAdapterExtension()); $this->container->loadFromExtension($httpAdapterExtension->getAlias()); }
protected function createContainerMock() { $container = new ContainerBuilder(); $container->addScope(new Scope('request')); $container->register('request', 'Symfony\\Component\\HttpFoundation\\Request')->setScope('request'); $container->enterScope('request'); $container->set('templating', $this->createTemplatingMock()); $container->set('router', $this->createRouterMock()); $container->setParameter('thrace_media.jwplayer.options', array('key' => '123', 'html5player' => 'path_to_file', 'flashplayer' => 'path_to_file')); return $container; }
/** * {@inheritdoc} */ protected function setUp() { $this->assetsHelperMock = $this->getMockBuilder('Symfony\\Component\\Templating\\Helper\\CoreAssetsHelper')->disableOriginalConstructor()->getMock(); $this->routerMock = $this->getMock('Symfony\\Component\\Routing\\RouterInterface'); $this->container = new ContainerBuilder(); $this->container->set('templating.helper.assets', $this->assetsHelperMock); $this->container->set('router', $this->routerMock); $this->container->setParameter('templating.engines', array('php', 'twig')); $this->container->registerExtension($extension = new IvoryCKEditorExtension()); $this->container->loadFromExtension($extension->getAlias()); }
/** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->container = new ContainerBuilder(); $cache_contexts_manager = $this->prophesize(CacheContextsManager::class); $cache_contexts_manager->assertValidTokens()->willReturn(TRUE); $cache_contexts_manager->reveal(); $this->container->set('cache_contexts_manager', $cache_contexts_manager); \Drupal::setContainer($this->container); $this->accessCheck = new PermissionAccessCheck(); }
/** * {@inheritdoc} */ protected function setUp() { $this->menuFactory = $this->createMenuFactoryMock(); $this->eventDispatcher = $this->createEventDispatcherMock(); $this->extension = new LugUiExtension(); $this->container = new ContainerBuilder(); $this->container->set('knp_menu.factory', $this->menuFactory); $this->container->set('event_dispatcher', $this->eventDispatcher); $this->container->registerExtension($this->extension); $this->container->loadFromExtension($this->extension->getAlias()); }
/** * Constructor. * * @param string $name * App name. * @param string $version * App version. * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container * DI Container. */ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN', ContainerBuilder $container) { parent::__construct($name, $version); $this->container = $container; $this->container->setParameter('version', $this->getVersion()); $this->container->setParameter('configurable_service_ids', array_keys($this->container->findTaggedServiceIds('configurable'))); // Logger. $log = new Logger('tl'); $logger_file = $this->container->getParameter('directory') . '/.tl.log'; $log->pushHandler(new StreamHandler($logger_file, Logger::INFO)); $this->container->set('logger', $log); }
public function getContainer() { $container = new ContainerBuilder(); $dispatcher = $this->getMock("Symfony\\Component\\EventDispatcher\\EventDispatcherInterface"); $container->set("event_dispatcher", $dispatcher); $fileManager = new FileManager(["document.product" => "Thelia\\Model\\ProductDocument", "image.product" => "Thelia\\Model\\ProductImage", "document.category" => "Thelia\\Model\\CategoryDocument", "image.category" => "Thelia\\Model\\CategoryImage", "document.content" => "Thelia\\Model\\ContentDocument", "image.content" => "Thelia\\Model\\ContentImage", "document.folder" => "Thelia\\Model\\FolderDocument", "image.folder" => "Thelia\\Model\\FolderImage", "document.brand" => "Thelia\\Model\\BrandDocument", "image.brand" => "Thelia\\Model\\BrandImage"]); $container->set("thelia.file_manager", $this->getFileManager()); $request = new Request(); $request->setSession($this->session); $container->set("request", $request); return $container; }
private function getContainer() { $container = new ContainerBuilder(); $container->addScope(new Scope('request')); $container->set('request', $this->request); $container->set('templating', $this->templating); $container->setParameter('kernel.bundles', array()); $container->setParameter('kernel.cache_dir', __DIR__); $container->setParameter('kernel.root_dir', __DIR__); $container->set('kernel', $this->kernel); return $container; }
/** * {@inheritdoc} */ protected function setUp() { $this->eventDispatcher = $this->createEventDispatcherMock(); $this->logger = $this->createLoggerMock(); $this->producer = $this->createProducerMock(); $this->container = new ContainerBuilder(); $this->container->set('event_dispatcher', $this->eventDispatcher); $this->container->set('logger', $this->logger); $this->container->set('old_sound_rabbit_mq.webhook_producer', $this->producer); $this->container->registerExtension($this->extension = new LugWebhookExtension()); $this->container->loadFromExtension($this->extension->getAlias()); }
/** * {@inheritDoc} */ public function setUp() { $this->annotationReader = $this->createMock(Reader::class); $this->logger = $this->createMock(LoggerInterface::class); $this->entityManagerRegistry = $this->createMock(RegistryInterface::class); $this->extension = new InneairTransactionExtension(); $this->container = new ContainerBuilder(); $this->container->set('annotation_reader', $this->annotationReader); $this->container->set('logger', $this->logger); $this->container->set('doctrine', $this->entityManagerRegistry); $this->container->registerExtension($this->extension); }