/** * Binds the interfaces and implementations of the Tactician Command Bus */ public function make() { $this->container->add(HandlerLocator::class, InMemoryLocator::class); $this->container->add(MethodNameInflector::class, HandleInflector::class); $this->container->add(CommandNameExtractor::class, ClassNameExtractor::class); $this->container->add(CommandBusInterface::class, CommandBus::class)->withArgument(MethodNameInflector::class)->withArgument(CommandNameExtractor::class)->withArgument(HandlerLocator::class)->withArgument($this->container); }
public function __construct() { $request = \Biome\Biome::getService('request'); $container = new Container(); $container->add('Symfony\\Component\\HttpFoundation\\Request', $request); $container->add('Symfony\\Component\\HttpFoundation\\Response', 'Biome\\Core\\HTTP\\Response'); parent::__construct($container); }
/** * @param string $vendor * @param string|integer $apiVersion * @param string $acceptHeader */ protected function setRequestParameters($vendor, $apiVersion, $acceptHeader) { $this->container->add(Application::CONTAINER_ID_VENDOR, $vendor); $this->container->add(Application::CONTAINER_ID_API_VERSION, $apiVersion); (new Service\Hateoas\Service())->register($this->container, new Service\Hateoas\Config(true)); $request = new Request(); $request->headers->set('Accept', $acceptHeader, true); $this->container->add('Symfony\\Component\\HttpFoundation\\Request', $request); }
public function setUp() { $configFile = __DIR__ . "/../mock/config/testSettings.php"; $this->container = new Container(); $this->container->delegate(new ReflectionContainer()); $this->container->add("config", 'Playground\\Framework\\Config\\Config', true)->withArgument($configFile); $this->container->addServiceProvider('Playground\\Framework\\Toybox\\Twig\\TwigServiceProvider'); $this->view = new View($this->container); }
protected function prepareRequest(Request $request) { $session = $this->container->get(Session::class); $request->setSession($session); if ($request->getContentType() == 'json') { if ($data = json_decode($request->getContent(), true)) { $request->request->replace($data); } } $this->container->add(Request::class, $request); }
public function testApplication() { $this->expectOutputString('Hello World'); $emitter = $this->getMock('Laasti\\Http\\EmitterInterface'); $emitter->expects($this->once())->method('emit')->will($this->returnCallback(function ($response) { echo $response->getBody(); })); $container = new Container(); $container->add('config', []); $container->add('kernel', new HttpKernel(function ($request, $response) { return $response; }, $emitter)); $container->addServiceProvider(new \Laasti\Log\MonologProvider()); $app = new Application($container); $app->run(new Request(), new Response\TextResponse('Hello World')); }
/** * Offset to set * * @param mixed $offset The offset to assign the value to. * @param mixed $value The value to set. * @return void */ public function offsetSet($offset, $value) { $builder = $this->container->add($offset, $value, true); if ($builder && is_callable($value)) { $builder->withArgument($this); } }
public function setUp() { $this->router = new RouteCollection(); $container = new Container(); $container->add(Application::CONTAINER_ID_ROUTER, $this->router); $this->controller = new RoutedController($container); }
public function testProvider() { $container = new Container(); $container->add('config.session', ['storage_class' => 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\MockArraySessionStorage', 'storage_args' => ['SESSMOCK_LAASTI']]); $container->addServiceProvider(new SymfonySessionProvider()); $session = $container->get('Symfony\\Component\\HttpFoundation\\Session\\SessionInterface'); $this->assertTrue(\PHPUnit_Framework_Assert::readAttribute($session, 'storage') instanceof MockArraySessionStorage); }
public function testStrictNonStaticMethods() { $container = new Container(); $container->add('SomeClass', 'Softius\\ResourcesResolver\\Test\\Resource\\SomeClass'); $resolver = new CallableResolver($container); $resolver->setMode(CallableResolver::MODE_STRICT); $callable = $resolver->resolve('SomeClass::someStaticMethod'); $this->assertTrue(is_callable($callable)); }
public function testConfig() { $container = new Container(); $container->add('config', ['translation' => ['locale' => 'fr', 'resources' => ['fr' => [['array', ['okay' => 'correct']]], 'en' => [['array', ['scared' => 'scaredy cat', 'okay' => 'okay']]]]]]); $container->addServiceProvider(new SymfonyTranslationProvider()); $translator = $container->get('Symfony\\Component\\Translation\\Translator'); $this->assertTrue($translator->trans('okay') === 'correct'); $this->assertTrue($translator->trans('scared') === 'scaredy cat'); }
public function testProvider() { $container = new Container(); $container->add('config.gregwarImage', ['cache_dir' => __DIR__ . '/cache']); $container->addServiceProvider(new GregwarImageProvider()); $image = $container->get('Gregwar\\Image\\Image'); $cache = \PHPUnit_Framework_Assert::readAttribute($image, 'cache'); $this->assertTrue(\PHPUnit_Framework_Assert::readAttribute($cache, 'cacheDirectory') === __DIR__ . '/cache'); }
public function testDelete() { $site_data = ['site_id' => '123']; $container = new Container(); $site = $this->getMockBuilder(Site::class)->disableOriginalConstructor()->getMock(); $site->method('get')->with('id')->willReturn('123'); $container->add(Site::class, $site); $container->add(Tags::class); $org = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock(); $workflows = $this->getMockBuilder(Workflows::class)->disableOriginalConstructor()->getMock(); $wf = $this->getMockBuilder(Workflow::class)->disableOriginalConstructor()->getMock(); $workflows->expects($this->once())->method('create')->with('remove_organization_site_membership', ['params' => ['site_id' => '123']])->willReturn($wf); $org->method('getWorkflows')->willReturn($workflows); $org_site = new OrganizationSiteMembership((object) ['site' => (object) $site_data, 'tags' => (object) []], ['collection' => (object) ['organization' => $org]]); $org_site->setContainer($container); $out = $org_site->delete(); $this->assertEquals($wf, $out); }
protected function _createModel($params = ['id' => 'dev']) { $this->site = $this->getMockBuilder(Site::class)->disableOriginalConstructor()->getMock(); $this->site->id = "abc"; $this->site->method('getName')->willReturn('abc'); $environments = new Environments(['site' => $this->site]); $model = new Environment((object) $params, ['collection' => $environments]); $this->container = new Container(); $this->workflow = $this->getMockBuilder(Workflow::class)->disableOriginalConstructor()->getMock(); $this->workflows = $this->getMockBuilder(Workflows::class)->disableOriginalConstructor()->getMock(); $this->lock = $this->getMockBuilder(Lock::class)->disableOriginalConstructor()->getMock(); $this->container->add(Workflows::class, $this->workflows); $this->container->add(Lock::class, $this->lock); $model->setContainer($this->container); $model->setRequest($this->request); $model->setConfig($this->config); return $model; }
public function testCanProperlyLocateHandler() { $handler = Mockery::mock(); $handler->shouldReceive('handle')->once(); $container = new Container(); $container->add(DummyHandler::class, $handler); $bus = new CommandBus([new CommandHandlerMiddleware(new ClassNameExtractor(), new ContainerLocator($container), new HandleInflector())]); $bus->handle(new DummyCommand()); }
public function testCanStartRepl() { $container = new Container(); $container->add(ConfigurationInterface::class, 'foobar'); $repl = Mockery::mock(Shell::class); $repl->shouldReceive('run')->once(); $repl->shouldReceive('setScopeVariables')->once()->with(['app' => $container, 'config' => 'foobar']); $tinker = new TinkerCommand($container, $repl); $tinker->run(new ArrayInput([]), new NullOutput()); }
/** * @param string $vendor * @param string|integer $apiVersion * @param string $acceptHeader * * @return Request */ protected function setRequestParameters($vendor, $apiVersion, $acceptHeader) { $this->container->add(Application::CONTAINER_ID_VENDOR, $vendor); $this->container->add(Application::CONTAINER_ID_API_VERSION, $apiVersion); (new Service())->register($this->container, new Config(true)); $request = new Request(); $request->headers->set('Accept', $acceptHeader, true); $this->container->add('Orno\\Http\\Request', $request); return $request; }
public function register(Container $app) { $app->share('commands', function () use($app) { $paths = $app->get('paths'); $commands = $this->getCommands($paths['commands']); return array_map(function ($commandName) use($app) { $app->add($commandName); return $app->get($commandName)->setContainer($app); }, $commands); }); }
public function testContainerFactoryConfig() { $container = new Container(); $container->addServiceProvider(new PaginationProvider()); $container->add('Laasti\\Pagination\\Tests\\FakePaginationAware')->withMethodCall('setContainer', ['League\\Container\\ContainerInterface']); $paginationAware = $container->get('Laasti\\Pagination\\Tests\\FakePaginationAware'); $pagination = $paginationAware->createPagination(1, 15, 5, 'http://acme.com/pages/', 1); $this->assertTrue(count($pagination) === 2); $this->assertTrue($pagination->getTotalPages() === 3); $this->assertTrue($pagination->next()->link() === 'http://acme.com/pages/2'); }
/** * Tests Site::getOrganizations() */ public function testGetOrganizations() { $org_membership = $this->getMockBuilder(SiteOrganizationMembership::class)->disableOriginalConstructor()->getMock(); $org_membership->organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock(); $org_membership->organization->id = 'organization_id'; $this->org_memberships = $this->getMockBuilder(SiteOrganizationMemberships::class)->disableOriginalConstructor()->getMock(); $this->org_memberships->expects($this->once())->method('all')->with()->willReturn([$org_membership]); $this->container->add(SiteOrganizationMemberships::class, $this->org_memberships); $data = [$org_membership->organization->id => $org_membership->organization]; $orgs = $this->model->getOrganizations(); $this->assertEquals($data, $orgs); }
/** * @return void * @throws NotFoundException */ public function play() { $this->container->get('sessionHandler'); $this->router = new Router("/", $this->config->get("routes.dir")); try { $dispatchRoute = $this->router->match($this->request); $this->container->add('currentRoute', $dispatchRoute, true); Dispatcher::handle($dispatchRoute, $this->request, $this->container); } catch (NotFoundException $exception) { $this->notFound($exception); } }
public function testProvider() { $container = new Container(); $container->add('config', ['flysystem' => ['file' => ['League\\Flysystem\\Adapter\\Local', [__DIR__]], 'null' => ['League\\Flysystem\\Adapter\\NullAdapter']]]); $container->addServiceProvider(new FlysystemProvider()); $default = $container->get('League\\Flysystem\\FilesystemInterface'); $manager = $container->get('League\\Flysystem\\MountManager'); $byName = $container->get('flysystem.adapter.null'); $this->assertTrue($default instanceof FilesystemInterface); $this->assertTrue($manager instanceof MountManager); $this->assertTrue($byName instanceof NullAdapter); $this->assertTrue($manager->getAdapter('file://') instanceof Local); $this->assertTrue($manager->getAdapter('null://') instanceof NullAdapter); }
public function testProvider() { $container = new Container(); $container->add('config', ['connections' => [['name' => 'default', 'dsn' => 'mysql://root:@localhost/nodb'], ['name' => 'mysql2', 'dsn' => 'mysql://root:@localhost/nodb2']]]); $container->addServiceProvider(new SpotProvider()); $config = $container->get('Spot\\Config'); $locator = $container->get('Spot\\Locator'); $config2 = $container->get('spot.config.default'); $locator2 = $container->get('spot.locator.default'); $this->assertTrue($locator instanceof \Spot\Locator); $this->assertTrue($locator2 instanceof \Spot\Locator); $this->assertTrue($config instanceof \Spot\Config); $this->assertTrue($config2 instanceof \Spot\Config); }
function getContainer() { static $container; if (!isset($container)) { $container = new Container(); //. Attempt to autowire class constructor dependencies $container->delegate(new ReflectionContainer()); // register default config file $container->add('configFile', SOVEREIGN_CONFIG_FILE); // Add the default system service provider $container->addServiceProvider(\Sovereign\Service\SystemServiceProvider::class); } return $container; }
/** * Load the DI container and return it * * @return Container */ private function loadContainer() { $container = new Container(); $objects = (require_once __DIR__ . '/../config/container.php'); $container->share('response', Response::class); $container->share('request', function () { return ServerRequestFactory::fromGlobals($_SERVER, $_GET, $_POST, $_COOKIE, $_FILES); }); $container->share('emitter', SapiEmitter::class); foreach ($objects as $object) { $container->add($object['name'], $object['concrete'], isset($object['shared']) ? $object['shared'] : false); } $container->share('events', $this->loadEvents($container)); return $container; }
/** * @inheritdoc */ public function setUp() { parent::setUp(); $org_site_membership = $this->getMockBuilder(OrganizationSiteMembership::class)->disableOriginalConstructor()->getMock(); $this->collection = new Tags(compact('org_site_membership')); $container = new Container(); $container->add(Tag::class); $this->collection->setRequest($this->request); $this->collection->setContainer($container); $this->collection->org_site_membership = $org_site_membership; $this->site = $this->getMockBuilder(Site::class)->disableOriginalConstructor()->getMock(); $this->site->id = 'site_uuid'; $this->collection->org_site_membership->method('getSite')->willReturn($this->site); $this->collection->org_site_membership->organization = $this->getMockBuilder(Organization::class)->disableOriginalConstructor()->getMock(); }
public function __construct(EmitterInterface $emitter = null, ContainerInterface $container = null) { if ($container === null) { $container = new Container(); } if ($emitter === null) { $emitter = new Emitter(); // Since we are creating the default emitter, make sure the same instance is in the container $container->add(EmitterInterface::class, $emitter); } $this->container = $container; $this->router = new Router($this->container); // TODO: Don't force RestfulStrategy, move this to AbstractJsonService $this->router->setStrategy(new RestfulStrategy()); $this->emitter = $emitter; $this->services = []; }
public function testCustomRequestParameter() { $container = new Container(); $fakeController = $this->getMockBuilder('FakeController')->setMethods(array('display'))->getMock(); $fakeController->expects($this->any())->method('display')->will($this->returnValue(new Response())); $container->add('Controller', $fakeController); $routes = new RouteCollection($container); $routes->setStrategy(new ControllerDefinitionStrategy()); $middleware = new DefineControllerMiddleware($routes, 'customRequestParameter'); $routes->get('test/{name}', 'Controller::display'); $request = $middleware->prepare(Request::create('test/george')); $definition = $request->attributes->get('customRequestParameter'); $this->assertInstanceOf('Laasti\\Route\\ControllerDefinition', $definition); $this->assertInstanceOf('FakeController', $definition->getInstance()); $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Request', $request); $this->assertEquals('george', $definition->getArguments()['name']); }
private function loadConfig() { $this->container->add('config', require $this->container->get('baseDir') . '/config/config.php'); }
* Error handler */ $whoops = new \Whoops\Run(); if (getenv('MODE') === 'dev') { $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); } else { $whoops->pushHandler(function () { Response::create('Something broke', Response::HTTP_INTERNAL_SERVER_ERROR)->send(); }); } $whoops->register(); /** * Container setup */ $container = new Container(); $container->add('PDO')->withArgument(getenv('DB_CONN'))->withArgument(getenv('DB_USER'))->withArgument(getenv('DB_PASS')); /** * Routes */ $dispatcher = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $r) { $routes = (require __DIR__ . '/routes.php'); foreach ($routes as $route) { $r->addRoute($route[0], $route[1], $route[2]); } }); /** * Dispatch */ $request = Request::createFromGlobals(); $route_info = $dispatcher->dispatch($request->getMethod(), $request->getPathInfo()); switch ($route_info[0]) {