public function testItCanUseDifferentContainerAdapters() { $container = new ExampleContainer(); ExampleContainerAdapter::reset(); Configurator::apply()->withContainerAdapter(ExampleContainer::class, ExampleContainerAdapter::class)->configFromArray([])->to($container); assertSame(1, ExampleContainerAdapter::getNumberOfInstances()); }
public function testItAddToConfigUsingFiles() { $config = ['keyB' => 'valueB']; $this->createJSONConfigFile('config.json', $config); Configurator::apply()->configFromArray(['keyA' => 'valueA', 'keyB' => 'valueX'])->configFromFiles($this->getTestPath('*'))->to($this->container); assertSame('valueA', $this->container->get('config.keyA')); assertSame('valueB', $this->container->get('config.keyB')); }
public function testItInjectsTheContainerAsFactoryDependency() { $config = ['class_name' => ExampleClassWithArgs::class, 'di' => ['services' => ['example_service' => ['factory' => ExampleFactory::class, 'arguments' => ['config.class_name', Configurator::container()]]]]]; Configurator::apply()->configFromArray($config)->to($this->container); $instance = $this->container->get('example_service'); assertSame([$this->container], $instance->getConstructorArgs()); }
public function testItAddsConfigToTheContainerWithNoPrefix() { Configurator::apply()->configFromArray(['keyA' => 'valueA'])->withSetting(Configurator::SETTING_PREFIX, '')->to($this->container); assertEquals('valueA', $this->container->get('keyA')); }
public function testItSetsUpAnInflectorUsingCustomInflectorsKey() { $config = ['di' => ['services' => ['example' => ['class' => ExampleClass::class]]], 'inflectors' => [ExampleInterface::class => ['setValue' => ['test_value']]]]; Configurator::apply()->configFromArray($config)->withSetting(Configurator::SETTING_INFLECTORS_KEY, 'inflectors')->to($this->container); assertEquals('test_value', $this->container->get('example')->getValue()); }