示例#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);
 }
示例#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);
 }
示例#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');
 }
示例#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();
 }
示例#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();
 }
示例#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'));
 }
示例#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);
 }
示例#10
0
文件: Route.php 项目: mermetbt/biome
 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);
 }
示例#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;
 }
示例#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');
 }
示例#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);
 }
示例#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);
 }
 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());
 }
示例#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;
     });
 }
 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);
 }
示例#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');
 }
示例#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;
     });
 }
 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');
 }
示例#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());
 }
示例#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));
 }
示例#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');
 }
示例#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);
 }