Skip to content

Commit

Permalink
[Serializer] Ignore when using #[Ignore] on a non-accessor
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Apr 4, 2024
1 parent e9a7cb9 commit 580b06a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,9 @@ public function loadClassMetadata(ClassMetadataInterface $classMetadata)

$attributeMetadata->setSerializedName($annotation->getSerializedName());
} elseif ($annotation instanceof Ignore) {
if (!$accessorOrMutator) {
throw new MappingException(sprintf('Ignore on "%s::%s()" cannot be added. Ignore can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
if ($accessorOrMutator) {
$attributeMetadata->setIgnore(true);
}

$attributeMetadata->setIgnore(true);
} elseif ($annotation instanceof Context) {
if (!$accessorOrMutator) {
throw new MappingException(sprintf('Context on "%s::%s()" cannot be added. Context can only be added on methods beginning with "get", "is", "has" or "set".', $className, $method->name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,12 @@ public function testCanHandleUnrelatedIgnoredMethods()
{
$class = $this->getNamespace().'\Entity45016';

$this->expectException(MappingException::class);
$this->expectExceptionMessage(sprintf('Ignore on "%s::badIgnore()" cannot be added', $class));

$metadata = new ClassMetadata($class);
$loader = $this->getLoaderForContextMapping();

$loader->loadClassMetadata($metadata);

$this->assertSame(['id'], array_keys($metadata->getAttributesMetadata()));
}

public function testIgnoreGetterWirhRequiredParameterIfIgnoreAnnotationIsUsed()
Expand Down

0 comments on commit 580b06a

Please sign in to comment.