Skip to content

[Validator] return empty metadata collection if none do exist #11614

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 8 additions & 0 deletions src/Symfony/Component/Validator/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ public function hasMemberMetadatas($property)
*/
public function getMemberMetadatas($property)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this method when it has the same implementation as getPropertyMetadata?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getPropertyMetadata() was introduced in efe42cb. I guess getMemberMetadatas() was kept for BC.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, it is the BC layer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be @deprecated then?!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is deprecated at the interface level. This class implements both the new interface and the deprecated one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, looks like a left-over of an even older implementation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it should be deprecated. Though not in this pull request I guess. Should I add it in #11615 or open another PR for it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should only deprecate things in master, not in 2.3

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ill make a PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see #11703

{
if (!isset($this->members[$property])) {
return array();
}

return $this->members[$property];
}

Expand All @@ -387,6 +391,10 @@ public function hasPropertyMetadata($property)
*/
public function getPropertyMetadata($property)
{
if (!isset($this->members[$property])) {
return array();
}

return $this->members[$property];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,4 +220,20 @@ public function testGroupSequenceProvider()
$metadata->setGroupSequenceProvider(true);
$this->assertTrue($metadata->isGroupSequenceProvider());
}

/**
* https://github.com/symfony/symfony/issues/11604
*/
public function testGetMemberMetadatasReturnsEmptyArrayWithoutConfiguredMetadata()
{
$this->assertCount(0, $this->metadata->getMemberMetadatas('foo'), '->getMemberMetadatas() returns an empty collection if no metadata is configured for the given property');
}

/**
* https://github.com/symfony/symfony/issues/11604
*/
public function testGetPropertyMetadataReturnsEmptyArrayWithoutConfiguredMetadata()
{
$this->assertCount(0, $this->metadata->getPropertyMetadata('foo'), '->getPropertyMetadata() returns an empty collection if no metadata is configured for the given property');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,17 @@ public function testValidatePropertyFailsIfPropertiesNotSupported()
$this->validateProperty('VALUE', 'someProperty');
}

/**
* https://github.com/symfony/symfony/issues/11604
*/
public function testValidatePropertyWithoutConstraints()
{
$entity = new Entity();
$violations = $this->validateProperty($entity, 'lastName');

$this->assertCount(0, $violations, '->validateProperty() returns no violations if no constraints have been configured for the property being validated');
}

public function testValidatePropertyValue()
{
$test = $this;
Expand Down Expand Up @@ -970,6 +981,17 @@ public function testValidatePropertyValueFailsIfPropertiesNotSupported()
$this->validatePropertyValue('VALUE', 'someProperty', 'someValue');
}

/**
* https://github.com/symfony/symfony/issues/11604
*/
public function testValidatePropertyValueWithoutConstraints()
{
$entity = new Entity();
$violations = $this->validatePropertyValue($entity, 'lastName', 'foo');

$this->assertCount(0, $violations, '->validatePropertyValue() returns no violations if no constraints have been configured for the property being validated');
}

public function testValidateObjectOnlyOncePerGroup()
{
$entity = new Entity();
Expand Down