|
@@ 39-53 (lines=15) @@
|
| 36 |
|
$this->definitionAnalyzer = new DefinitionAnalyzer(new DefinitionValidator()); |
| 37 |
|
} |
| 38 |
|
|
| 39 |
|
public function testServiceFactoryMethodDoesNotHaveArguments() |
| 40 |
|
{ |
| 41 |
|
$containerBuilder = new ContainerBuilder(); |
| 42 |
|
$containerBuilder->addDefinitions([ |
| 43 |
|
'factory' => new Definition(EmptyConstructorFactory::class), |
| 44 |
|
]); |
| 45 |
|
|
| 46 |
|
$definition = new Definition(EmptyConstructor::class); |
| 47 |
|
$definition->setFactory([ |
| 48 |
|
new Reference('factory'), |
| 49 |
|
'create', |
| 50 |
|
]); |
| 51 |
|
|
| 52 |
|
$this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired($containerBuilder, $definition)); |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
public function testFactoryMethodDoesNotHaveArguments() |
| 56 |
|
{ |
|
@@ 66-82 (lines=17) @@
|
| 63 |
|
$this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired(new ContainerBuilder(), $definition)); |
| 64 |
|
} |
| 65 |
|
|
| 66 |
|
public function testServiceFactoryBuiltClassHaveMissingArgumentsTypehints() |
| 67 |
|
{ |
| 68 |
|
$containerBuilder = new ContainerBuilder(); |
| 69 |
|
$containerBuilder->addDefinitions([ |
| 70 |
|
'factory' => new Definition(MissingArgumentsTypehintsFactory::class), |
| 71 |
|
]); |
| 72 |
|
|
| 73 |
|
$definition = new Definition(MissingArgumentsTypehints::class); |
| 74 |
|
$definition->setFactory([ |
| 75 |
|
new Reference('factory'), |
| 76 |
|
'create', |
| 77 |
|
]); |
| 78 |
|
|
| 79 |
|
$definition->setArguments(['@someService']); |
| 80 |
|
|
| 81 |
|
$this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired($containerBuilder, $definition)); |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
public function testFactoryBuiltClassHaveMissingArgumentsTypehints() |
| 85 |
|
{ |
|
@@ 97-113 (lines=17) @@
|
| 94 |
|
$this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired(new ContainerBuilder(), $definition)); |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
public function testServiceFactoryBuiltClassHaveNotMissingArgumentsTypehints() |
| 98 |
|
{ |
| 99 |
|
$containerBuilder = new ContainerBuilder(); |
| 100 |
|
$containerBuilder->addDefinitions([ |
| 101 |
|
'factory' => new Definition(NotMissingArgumentsTypehintsFactory::class), |
| 102 |
|
]); |
| 103 |
|
|
| 104 |
|
$definition = new Definition(NotMissingArgumentsTypehints::class); |
| 105 |
|
$definition->setFactory([ |
| 106 |
|
new Reference('factory'), |
| 107 |
|
'create', |
| 108 |
|
]); |
| 109 |
|
|
| 110 |
|
$definition->setArguments(['@someService']); |
| 111 |
|
|
| 112 |
|
$this->assertTrue($this->definitionAnalyzer->shouldDefinitionBeAutowired($containerBuilder, $definition)); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
public function testFactoryBuiltClassHaveNotMissingArgumentsTypehints() |
| 116 |
|
{ |
|
@@ 128-145 (lines=18) @@
|
| 125 |
|
$this->assertTrue($this->definitionAnalyzer->shouldDefinitionBeAutowired(new ContainerBuilder(), $definition)); |
| 126 |
|
} |
| 127 |
|
|
| 128 |
|
public function testFactoryServiceIsUsedByAlias() |
| 129 |
|
{ |
| 130 |
|
$containerBuilder = new ContainerBuilder(); |
| 131 |
|
$containerBuilder->addDefinitions([ |
| 132 |
|
'factory' => new Definition(EmptyConstructorFactory::class), |
| 133 |
|
]); |
| 134 |
|
$containerBuilder->addAliases([ |
| 135 |
|
'factory_alias' => 'factory', |
| 136 |
|
]); |
| 137 |
|
|
| 138 |
|
$definition = new Definition(EmptyConstructor::class); |
| 139 |
|
$definition->setFactory([ |
| 140 |
|
new Reference('factory_alias'), |
| 141 |
|
'create', |
| 142 |
|
]); |
| 143 |
|
|
| 144 |
|
$this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired($containerBuilder, $definition)); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
public function testFactoryServiceCanBeDecorated() |
| 148 |
|
{ |
|
@@ 147-162 (lines=16) @@
|
| 144 |
|
$this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired($containerBuilder, $definition)); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
public function testFactoryServiceCanBeDecorated() |
| 148 |
|
{ |
| 149 |
|
$containerBuilder = new ContainerBuilder(); |
| 150 |
|
$containerBuilder->addDefinitions([ |
| 151 |
|
'factory' => new Definition(EmptyConstructorFactory::class), |
| 152 |
|
'decorated_factory' => new DefinitionDecorator('factory'), |
| 153 |
|
]); |
| 154 |
|
|
| 155 |
|
$definition = new Definition(EmptyConstructor::class); |
| 156 |
|
$definition->setFactory([ |
| 157 |
|
new Reference('decorated_factory'), |
| 158 |
|
'create', |
| 159 |
|
]); |
| 160 |
|
|
| 161 |
|
$this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired($containerBuilder, $definition)); |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
public function testFactoryClassNameIsDefinedByParameter() |
| 165 |
|
{ |
|
@@ 164-179 (lines=16) @@
|
| 161 |
|
$this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired($containerBuilder, $definition)); |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
public function testFactoryClassNameIsDefinedByParameter() |
| 165 |
|
{ |
| 166 |
|
$containerBuilder = new ContainerBuilder(); |
| 167 |
|
$containerBuilder->addDefinitions([ |
| 168 |
|
'factory' => new Definition('%factory_class_param%'), |
| 169 |
|
]); |
| 170 |
|
$containerBuilder->setParameter('factory_class_param', EmptyConstructorFactory::class); |
| 171 |
|
|
| 172 |
|
$definition = new Definition(EmptyConstructor::class); |
| 173 |
|
$definition->setFactory([ |
| 174 |
|
new Reference('factory'), |
| 175 |
|
'create', |
| 176 |
|
]); |
| 177 |
|
|
| 178 |
|
$this->assertFalse($this->definitionAnalyzer->shouldDefinitionBeAutowired($containerBuilder, $definition)); |
| 179 |
|
} |
| 180 |
|
|
| 181 |
|
public function testDoctrineRepositoryAsService() |
| 182 |
|
{ |