Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\Exception\MappingException;

/**
Expand All @@ -33,9 +32,6 @@ public function process(ContainerBuilder $container): void
if (!$definition->hasTag('serializer.attribute_metadata')) {
continue;
}
if (!$definition->hasTag('container.excluded')) {
throw new InvalidArgumentException(\sprintf('The resource "%s" tagged "serializer.attribute_metadata" is missing the "container.excluded" tag.', $id));
}
$class = $resolve($definition->getClass());
foreach ($definition->getTag('serializer.attribute_metadata') as $attributes) {
if ($class !== $for = $attributes['for'] ?? $class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\Serializer\DependencyInjection\AttributeMetadataPass;
use Symfony\Component\Serializer\Exception\MappingException;
use Symfony\Component\Serializer\Mapping\Loader\AttributeLoader;
Expand Down Expand Up @@ -52,18 +51,14 @@ public function testProcessWithTaggedServices()
->setArguments([false, []]);

$container->register('service1', '%user_entity.class%')
->addTag('serializer.attribute_metadata')
->addTag('container.excluded');
->addTag('serializer.attribute_metadata');
$container->register('service2', 'App\Entity\Product')
->addTag('serializer.attribute_metadata')
->addTag('container.excluded');
->addTag('serializer.attribute_metadata');
$container->register('service3', 'App\Entity\Order')
->addTag('serializer.attribute_metadata')
->addTag('container.excluded');
->addTag('serializer.attribute_metadata');
// Classes should be deduplicated
$container->register('service4', 'App\Entity\Order')
->addTag('serializer.attribute_metadata')
->addTag('container.excluded');
->addTag('serializer.attribute_metadata');

(new AttributeMetadataPass())->process($container);

Expand All @@ -78,18 +73,6 @@ public function testProcessWithTaggedServices()
$this->assertSame([false, $expectedClasses], $arguments);
}

public function testThrowsWhenMissingExcludedTag()
{
$container = new ContainerBuilder();
$container->register('serializer.mapping.attribute_loader');

$container->register('service_without_excluded', 'App\\Entity\\User')
->addTag('serializer.attribute_metadata');

$this->expectException(InvalidArgumentException::class);
(new AttributeMetadataPass())->process($container);
}

public function testProcessWithForOptionAndMatchingMembers()
{
$sourceClass = _AttrMeta_Source::class;
Expand All @@ -100,8 +83,7 @@ public function testProcessWithForOptionAndMatchingMembers()
->setArguments([false, []]);

$container->register('service.source', $sourceClass)
->addTag('serializer.attribute_metadata', ['for' => $targetClass])
->addTag('container.excluded');
->addTag('serializer.attribute_metadata', ['for' => $targetClass]);

(new AttributeMetadataPass())->process($container);

Expand All @@ -119,8 +101,7 @@ public function testProcessWithForOptionAndMissingMemberThrows()
->setArguments([false, []]);

$container->register('service.source', $sourceClass)
->addTag('serializer.attribute_metadata', ['for' => $targetClass])
->addTag('container.excluded');
->addTag('serializer.attribute_metadata', ['for' => $targetClass]);

$this->expectException(MappingException::class);
(new AttributeMetadataPass())->process($container);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\Validator\Exception\MappingException;

/**
Expand All @@ -33,9 +32,6 @@ public function process(ContainerBuilder $container): void
if (!$definition->hasTag('validator.attribute_metadata')) {
continue;
}
if (!$definition->hasTag('container.excluded')) {
throw new InvalidArgumentException(\sprintf('The resource "%s" tagged "validator.attribute_metadata" is missing the "container.excluded" tag.', $id));
}
$class = $resolve($definition->getClass());
foreach ($definition->getTag('validator.attribute_metadata') as $attributes) {
if ($class !== $for = $attributes['for'] ?? $class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\Validator\DependencyInjection\AttributeMetadataPass;
use Symfony\Component\Validator\Exception\MappingException;

Expand Down Expand Up @@ -49,18 +48,14 @@ public function testProcessWithTaggedServices()
->addMethodCall('addAttributeMappings', [[]]);

$container->register('service1', '%user_entity.class%')
->addTag('validator.attribute_metadata')
->addTag('container.excluded');
->addTag('validator.attribute_metadata');
$container->register('service2', 'App\Entity\Product')
->addTag('validator.attribute_metadata')
->addTag('container.excluded');
->addTag('validator.attribute_metadata');
$container->register('service3', 'App\Entity\Order')
->addTag('validator.attribute_metadata')
->addTag('container.excluded');
->addTag('validator.attribute_metadata');
// Classes should be deduplicated
$container->register('service4', 'App\Entity\Order')
->addTag('validator.attribute_metadata')
->addTag('container.excluded');
->addTag('validator.attribute_metadata');

(new AttributeMetadataPass())->process($container);

Expand All @@ -77,18 +72,6 @@ public function testProcessWithTaggedServices()
$this->assertEquals([$expectedClasses], $methodCalls[1][1]);
}

public function testThrowsWhenMissingExcludedTag()
{
$container = new ContainerBuilder();
$container->register('validator.builder');

$container->register('service_without_excluded', 'App\\Entity\\User')
->addTag('validator.attribute_metadata');

$this->expectException(InvalidArgumentException::class);
(new AttributeMetadataPass())->process($container);
}

public function testProcessWithForOptionAndMatchingMembers()
{
$sourceClass = _AttrMeta_Source::class;
Expand All @@ -98,8 +81,7 @@ public function testProcessWithForOptionAndMatchingMembers()
$container->register('validator.builder');

$container->register('service.source', $sourceClass)
->addTag('validator.attribute_metadata', ['for' => $targetClass])
->addTag('container.excluded');
->addTag('validator.attribute_metadata', ['for' => $targetClass]);

(new AttributeMetadataPass())->process($container);

Expand All @@ -118,8 +100,7 @@ public function testProcessWithForOptionAndMissingMemberThrows()
$container->register('validator.builder');

$container->register('service.source', $sourceClass)
->addTag('validator.attribute_metadata', ['for' => $targetClass])
->addTag('container.excluded');
->addTag('validator.attribute_metadata', ['for' => $targetClass]);

$this->expectException(MappingException::class);
(new AttributeMetadataPass())->process($container);
Expand Down