/** * @dataProvider dataProviderConfigurable * * @param ContainerConfiguratorTestStubYiiBaseObject|ContainerConfiguratorTestStubYiiBaseConfigurable|string $class * * @throws WrongConfigException */ public function testConfigurable($class) { if (!class_exists($class, false)) { $this->markTestSkipped("Class '{$class}' not found, maybe yii2 old version, it's ok"); } $config = ['service' => ['class' => $class, 'arguments' => [['type' => ContainerConfigurator::ARGUMENT_TYPE_VALUE, 'value' => 'argument1value'], ['type' => ContainerConfigurator::ARGUMENT_TYPE_VALUE, 'value' => 'argument2value']], 'properties' => ['property1' => ['type' => ContainerConfigurator::ARGUMENT_TYPE_VALUE, 'value' => 'property1value'], 'property2' => ['type' => ContainerConfigurator::ARGUMENT_TYPE_VALUE, 'value' => 'property2value']]]]; $container = new Container(); $containerConfigurator = new ContainerConfigurator($container); $containerConfigurator->configure($config); /** @var ContainerConfiguratorTestStubYiiBaseObject|ContainerConfiguratorTestStubYiiBaseConfigurable $stub */ $stub = $container->get('service'); $class::test($this, ['class' => $config['service']['class'], 'arguments' => ['argument1value', 'argument2value', ['property1' => 'property1value', 'property2' => 'property2value']]], $stub); }
/** * @expectedException \mougrim\yii2ContainerConfigurator\WrongConfigException * @dataProvider dataProviderConfigureException * * @param array $config * @param array $createParams * @param integer $containerSetCallsQty * @param integer $containerSetSingletonCallsQty * * @throws WrongConfigException */ public function testConfigureException(array $config, array $createParams, $containerSetCallsQty, $containerSetSingletonCallsQty) { $callParams = []; $container = $this->getContainerMock($callParams, $containerSetCallsQty, $containerSetSingletonCallsQty); $containerConfigurator = new ContainerConfigurator($container); $containerConfigurator->configure($config); $this->assertTrue(isset($callParams['setSingleton'])); $this->assertTrue(isset($callParams['setSingleton']['service'])); $this->assertEquals(1, count($callParams['setSingleton']['service'])); $this->assertTrue(is_callable($callParams['setSingleton']['service'][0])); $callParams['setSingleton']['service'][0]($container, $createParams, []); $this->assertFalse(isset($callParams['set'])); }