File tree Expand file tree Collapse file tree
src/DependencyInjection/Compiler
tests/DependencyInjection/Compiler Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1212use Symfony \Component \DependencyInjection \ContainerBuilder ;
1313use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
1414
15- use function array_key_exists ;
1615use function is_subclass_of ;
1716use function method_exists ;
1817use function sprintf ;
@@ -50,10 +49,6 @@ public function process(ContainerBuilder $container): void
5049
5150 foreach ($ this ->findTaggedResourceIds ($ container ) as $ id => $ tags ) {
5251 foreach ($ tags as $ tag ) {
53- if (! array_key_exists ('name ' , $ tag )) {
54- throw new InvalidArgumentException (sprintf ('The "name" attribute is mandatory for the "doctrine.dbal.type" tag on the "%s" type. ' , $ id ));
55- }
56-
5752 $ class = $ container ->getDefinition ($ id )->getClass ();
5853 if (! $ class ) {
5954 throw new InvalidArgumentException (sprintf ('The definition of "%s" must define its class. ' , $ id ));
@@ -63,7 +58,7 @@ public function process(ContainerBuilder $container): void
6358 throw new InvalidArgumentException (sprintf ('The "%s" class must extends "%s". ' , $ class , Type::class));
6459 }
6560
66- $ types [$ tag ['name ' ]] = ['class ' => $ class ];
61+ $ types [$ tag ['name ' ] ?? $ class ] = ['class ' => $ class ];
6762 }
6863 }
6964
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ public function testTaggedTypeAreAdded(): void
3131 self ::assertSame (['bar ' => ['class ' => BarType::class]], $ container ->getParameter ('doctrine.dbal.connection_factory.types ' ));
3232 }
3333
34- public function testTagMustHaveANameAttribute (): void
34+ public function testUseClassnameAsTypeNameIfNotDefined (): void
3535 {
3636 $ container = new ContainerBuilder ();
3737 $ container ->addCompilerPass (new RegisterDbalTypePass ());
@@ -42,12 +42,9 @@ public function testTagMustHaveANameAttribute(): void
4242 ->addTag ('doctrine.dbal.type ' )
4343 ->addTag ('container.excluded ' );
4444
45- $ this ->expectException (InvalidArgumentException::class);
46- $ this ->expectExceptionMessage (
47- sprintf ('The "name" attribute is mandatory for the "doctrine.dbal.type" tag on the "%s" type. ' , BarType::class),
48- );
49-
5045 $ container ->compile ();
46+
47+ self ::assertSame ([BarType::class => ['class ' => BarType::class]], $ container ->getParameter ('doctrine.dbal.connection_factory.types ' ));
5148 }
5249
5350 public function testTypeMustBeASubclassOfTheDbalBaseType (): void
You can’t perform that action at this time.
0 commit comments