public function setUp() { $this->dataDirectory = __DIR__ . '/tmp'; $this->mkdir($this->dataDirectory . '/entities'); $container = new Container(); $container->set('ConfigDirectory', JPATH_ROOT); $container->registerServiceProvider(new StorageServiceProvider(), 'repository'); $container->registerServiceProvider(new EventDispatcherServiceProvider(), 'dispatcher'); $container->registerServiceProvider(new ExtensionFactoryServiceProvider(), 'extension_factory'); $this->installer = new Installer($this->dataDirectory, $container); }
public function RendererAddsTheEventDecorator(UnitTester $I) { $container = new Container(); $container->set('ConfigDirectory', JPATH_ROOT); $container->registerServiceProvider(new StorageServiceProvider(), 'repository'); $container->registerServiceProvider(new EventDispatcherServiceProvider(), 'dispatcher'); $container->registerServiceProvider(new ExtensionFactoryServiceProvider(), 'extension_factory'); $app = new Application([new RendererMiddleware(new Dispatcher(), $container), function (ServerRequestInterface $request, ResponseInterface $response, callable $next) use($I) { $body = $response->getBody(); $I->assertEquals(EventDecorator::class, get_class($body)); return $next($request, $response); }]); $app->run(new ServerRequest()); }
/** * Init this component. * * @return void */ public function init() { $dispatcher = $this->container->get('event.dispatcher'); // Event $dispatcher->trigger('onComponentBeforeInit', array($this->name, $this, $this->input)); // We build component path constant, helpe us get path easily. $this->path['self'] = JPATH_BASE . '/components/' . strtolower($this->option); $this->path['site'] = JPATH_ROOT . '/components/' . strtolower($this->option); $this->path['administrator'] = JPATH_ROOT . '/administrator/components/' . strtolower($this->option); define(strtoupper($this->name) . '_SELF', $this->path['self']); define(strtoupper($this->name) . '_SITE', $this->path['site']); define(strtoupper($this->name) . '_ADMIN', $this->path['administrator']); // Register some useful object for this component. $this->container->registerServiceProvider(new ComponentProvider($this->name, $this)); $task = $this->input->getWord('task'); $controller = $this->input->getWord('controller'); // Prepare default controller if (!$task && !$controller) { // If we got view, set it to display controller. $view = $this->input->get('view'); $task = $view ? $view . '.display' : $this->defaultController; $this->input->set('task', $task); $this->input->set('controller', $task); } // Register form and fields \JForm::addFieldPath(WINDWALKER_SOURCE . '/Form/Fields'); \JForm::addFormPath(WINDWALKER_SOURCE . '/Form/Forms'); $this->registerEventListener(); // Register elFinder controllers // @TODO: Should use event listener $this->registerTask('finder.elfinder.display', '\\Windwalker\\Elfinder\\Controller\\DisplayController'); $this->registerTask('finder.elfinder.connect', '\\Windwalker\\Elfinder\\Controller\\ConnectController'); // Event $dispatcher->trigger('onComponentAfterInit', array($this->name, $this, $this->input)); }
/** * Test registering a service provider. Make sure register get's called. * * @return void * * @since 1.0 */ public function testRegisterServiceProvider() { $mock = $this->getMock('Joomla\\DI\\ServiceProviderInterface'); $mock->expects($this->once())->method('register'); $returned = $this->fixture->registerServiceProvider($mock); $this->assertSame($returned, $this->fixture, 'When registering a service provider, the container instance should be returned.'); }
/** * Instantiate the controller. * * @param \Joomla\DI\Container $container DI Container. * @param IOInterface $io The Controller object. */ public function __construct(JoomlaContainer $container = null, IOInterface $io = null) { $this->container = $container ?: $this->getContainer(); // Set provider $container->registerServiceProvider(new ServiceProvider()); parent::__construct($io); }
/** * @testdox The modified command bus has an execute method that takes a Query as a parameter */ public function testTheCommandBusHasAnExecuteMethodThatTakesAQueryAsAParameter() { $this->expectOutputString(sprintf("LOG: Starting %1\$s\nLOG: Ending %1\$s\n", "Joomla\\Tests\\Unit\\Service\\Stubs\\SimpleQuery")); $container = new Container(); $container->set('EventDispatcher', $this->getMockBuilder(DispatcherInterface::class)->getMock()); $container->set('CommandBusMiddleware', [new LoggingMiddleware(new Logger())]); $container->registerServiceProvider(new CommandBusServiceProvider()); $commandBus = $container->get('CommandBus'); $this->assertEquals('XSome contentY', $commandBus->handle(new SimpleQuery('Some content'))); }
/** * Custom initialisation method. * * Called at the end of the Base::__construct method. This is for developers to inject initialisation code for their application classes. * * @return void * * @codeCoverageIgnore * @since 1.0 */ protected function initialise() { // New DI stuff! $container = new Container(); $input = $this->input; $container->share('input', function (Container $c) use($input) { return $input; }, true); $container->registerServiceProvider(new Providers\ConfigServiceProvider(TAGALISER_CONFIG)); $container->registerServiceProvider(new Providers\GithubServiceProvider()); $container->registerServiceProvider(new Providers\LoggerServiceProvider()); $container->registerServiceProvider(new Providers\MustacheServiceProvider()); $this->container = $container; }
/** * @testdox The database service provider is registered to the DI container * * @covers Stats\Providers\DatabaseServiceProvider::register */ public function testTheDatabaseServiceProviderIsRegisteredToTheContainer() { $container = new Container(); $container->registerServiceProvider(new DatabaseServiceProvider()); $this->assertTrue($container->exists('Joomla\\Database\\DatabaseDriver')); }
/** * @testdox The application service provider is registered to the DI container * * @covers Stats\Providers\ApplicationServiceProvider::register */ public function testTheApplicationServiceProviderIsRegisteredToTheContainer() { $container = new Container(); $container->registerServiceProvider(new ApplicationServiceProvider()); $this->assertTrue($container->exists('Stats\\Application')); }
/** * @testdox The config service provider is registered to the DI container * * @covers Stats\Providers\ConfigServiceProvider::__construct * @covers Stats\Providers\ConfigServiceProvider::register */ public function testTheConfigServiceProviderIsRegisteredToTheContainer() { $container = new Container(); $container->registerServiceProvider(new ConfigServiceProvider(APPROOT . '/etc/config.dist.json')); $this->assertTrue($container->exists('config')); }