Exemplo n.º 1
0
 public function testInstansiation()
 {
     $service = new Service();
     $service->register($this->container, $this->hateoasConfig);
     $hateoasService = $this->container->get(Config::getServiceName());
     $this->assertInstanceOf('\\Hateoas\\Hateoas', $hateoasService);
 }
Exemplo n.º 2
0
 public function setUp()
 {
     $this->router = new RouteCollection();
     $container = new Container();
     $container->add(Application::CONTAINER_ID_ROUTER, $this->router);
     $this->controller = new RoutedController($container);
 }
Exemplo n.º 3
0
 public function testProvider()
 {
     $container = new Container();
     $container->addServiceProvider(new MailerProvider());
     $container['config.mailer'] = ['server' => 'Laasti\\Mailer\\Servers\\NullServer'];
     $container->get('Laasti\\Mailer\\Mailer');
 }
Exemplo n.º 4
0
 /**
  * This is for the pthreads compatibility - for some reason the DB just goes t**s up when using pthreads
  * and PDO.. Hence the __wakeup() call, that restarts the database.
  * No numbers on it, but it more than likely adds quite a bit of latency.
  */
 public function __wakeup()
 {
     $this->container = getContainer();
     $this->log = $this->container->get('log');
     $this->config = $this->container->get('config');
     $this->pdo = $this->connect();
 }
Exemplo n.º 5
0
 /**
  * Execute a request
  * @param \Symfony\Component\HttpFoundation\Request $request
  */
 public function execute(Request $request = null)
 {
     $this->request = $request ?: $this->getRequest();
     $router = $this->container->get(RouteCollection::class);
     $response = $router->getDispatcher()->dispatch($this->request->getMethod(), $this->request->getPathInfo());
     $response->send();
 }
Exemplo n.º 6
0
 public function testInstansiation()
 {
     $service = new Service();
     $service->register($this->continer, new Config('sampleLoggerName'));
     $loggerService = $this->continer->get(Config::getServiceName());
     $this->assertEquals('sampleLoggerName', $loggerService->getName());
 }
 /**
  * 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 testContainerHasInstantiatedAMailProviderInterface()
 {
     $mailServiceProvider = new MailServiceProvider();
     $mailServiceProvider->setContainer($this->container);
     $mailServiceProvider->register();
     $this->assertInstanceOf('JGimeno\\TaskReporter\\Domain\\Service\\MailProviderInterface', $this->container->get('JGimeno\\TaskReporter\\Domain\\Service\\MailProviderInterface'));
 }
Exemplo n.º 9
0
 /**
  * {@inheritDoc}
  *
  * @throws ClassDoesNotImplementServiceProviderInterfaceException
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $dispatcher = $this->router->getDispatcher();
     $requestUri = parse_url($request->getRequestUri(), PHP_URL_PATH);
     $this->container->singleton(Request::class, $request);
     $this->boot();
     return $dispatcher->dispatch($request->getMethod(), $requestUri);
 }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
 /**
  * @param string $apiUrl
  * @param array  $options
  *
  * @return Container
  */
 private function containerFactory($apiUrl, array $options = [])
 {
     $container = new Container();
     $systemServiceProvider = new ServiceProvider();
     $systemServiceProvider->setApiUrl($apiUrl)->setOptions($options);
     $container->addServiceProvider($systemServiceProvider);
     return $container;
 }
Exemplo n.º 12
0
 public function resolve($handler)
 {
     if (is_array($handler) and is_string($handler[0])) {
         $this->container->share($handler[0])->withArguments([$this->container]);
         $handler[0] = $this->container->get($handler[0]);
     }
     return $handler;
 }
 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);
 }
 /**
  * Gets the default commands that should always be available.
  *
  * @return array An array of default Command instances
  */
 protected function getDefaultCommands()
 {
     // Keep the core default commands to have the HelpCommand
     // which is used when using the --help option
     $defaultCommands = parent::getDefaultCommands();
     $container = new Container();
     $defaultCommands[] = $container->get('Gradcracker\\Console\\Command\\MySQLDumperCommand');
     return $defaultCommands;
 }
 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));
 }
 /** @inheritDoc */
 public function execute(CommandInterface $command)
 {
     $className = get_class($command);
     if (array_key_exists($className, $this->commandNameToHandlerMap) === false) {
         throw new CommandNotFoundException($className);
     }
     $handler = $this->container->get($this->commandNameToHandlerMap[$className]);
     return $handler->execute($command);
 }
 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');
 }
Exemplo n.º 18
0
 /**
  * @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);
 }
Exemplo n.º 19
0
 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);
 }
Exemplo n.º 20
0
 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());
 }
Exemplo n.º 21
0
 public function register(Container $app)
 {
     $app->share('view', function () use($app) {
         $config = $app->get('config');
         $supportView = new ViewSupport($app);
         $view = new View($config->get("environment.host"), $supportView);
         return $view;
     });
 }
Exemplo n.º 22
0
 public function testProvidesSlugifyUsingSharedProvider()
 {
     $container = new Container();
     $ruleProvider = $this->getRuleProviderMock();
     $container->share(RuleProviderInterface::class, $ruleProvider);
     $container->addServiceProvider(new SlugifyServiceProvider());
     $slugify = $container->get(SlugifyInterface::class);
     $this->assertAttributeSame($ruleProvider, 'provider', $slugify);
 }
Exemplo n.º 23
0
 public function register(Container $app)
 {
     $app->share('current_request', function () {
         //$_POST => $request->request->all();
         //$_GET => $request->query->all()
         //$_FILES => $request->files->all()
         return Request::createFromGlobals();
     });
 }
 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');
 }
Exemplo n.º 25
0
 public function register(Container $app)
 {
     $app->share('event', function () use($app) {
         $paths = $app->get('paths');
         $event = Event::getInstance();
         $event->loadListeners($paths['listeners']);
         $event->setResolver(new EventResolver($app));
         return $event;
     });
 }
Exemplo n.º 26
0
 public function testProviderConfig()
 {
     $container = new Container();
     $container->addServiceProvider(new PaginationProvider());
     $container['config.pagination'] = ['per_page' => 5, 'neighbours' => 2, 'base_url' => 'http://acme.com/pages/'];
     $pagination = $container->get('Laasti\\Pagination\\Pagination', [1, 50]);
     $this->assertTrue($pagination->getTotalPages() === 10);
     $this->assertTrue(count($pagination) === 3);
     $this->assertTrue($pagination->last()->link() === 'http://acme.com/pages/10');
 }
Exemplo n.º 27
0
 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());
 }
Exemplo n.º 28
0
 public function testProvider()
 {
     $container = new Container();
     $container->addServiceProvider($this->provider);
     $this->provider->setContainer($container);
     $this->assertTrue($this->provider->provides(View\Manager::class));
     $this->provider->register();
     $this->assertTrue($container->isRegistered(View\Manager::class));
     $this->assertInstanceOf(View\Manager::class, $container->get(View\Manager::class));
 }
Exemplo n.º 29
0
 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');
 }
Exemplo n.º 30
0
 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);
 }