Skip to content
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

Improve misleading ORMInvalidArgumentException message #6801

Merged
merged 2 commits into from
Nov 26, 2017

Conversation

foaly-nr1
Copy link
Contributor

/**
* @ManyToMany(targetEntity="DDC6029User", mappedBy="groups")
*/
private $users;
Copy link
Member

Choose a reason for hiding this comment

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

Is this needed? Let's keep only the things required by the tests

*/
public function testIssue()
{
$user = new DDC6029User();
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we add here the expected exception and the expected exception message? Like:

$this->expectException(ORMInvalidArgumentException::class);
$this->expectExceptionMessage('Expected value of type "Doctrine\Tests\ORM\Functional\Ticket\DDC6029Group" for association field "Doctrine\Tests\ORM\Functional\Ticket\DDC6029User#$groups", got "Doctrine\Tests\ORM\Functional\Ticket\DDC6029Group2" instead.');

* Verifies that when wrong entity is persisted via relationship field, the error message does not correctly state
* the expected class name.
*/
public function testIssue()
Copy link
Member

Choose a reason for hiding this comment

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

: void


/**
* Verifies that when wrong entity is persisted via relationship field, the error message does not correctly state
* the expected class name.
Copy link
Member

Choose a reason for hiding this comment

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

Please add @group with the ticket number so that we can trace things back

$user = new DDC6029User();
$user->addGroup(new DDC6029Group2());

self::expectException(ORMInvalidArgumentException::class);
Copy link
Member

Choose a reason for hiding this comment

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

This method is not static, so we should use $this instead

$user->addGroup(new DDC6029Group2());

self::expectException(ORMInvalidArgumentException::class);
self::expectExceptionMessage('Expected value of type "Doctrine\Tests\ORM\Functional\Ticket\DDC6029Group" for association field "Doctrine\Tests\ORM\Functional\Ticket\DDC6029User#$groups", got "Doctrine\Tests\ORM\Functional\Ticket\DDC6029Group2" instead.');
Copy link
Member

Choose a reason for hiding this comment

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

This method is not static, so we should use $this instead

@@ -195,11 +195,7 @@ public static function invalidIdentifierBindingEntity()
*/
public static function invalidAssociation(ClassMetadata $targetClass, $assoc, $actualValue)
{
$expectedType = 'Doctrine\Common\Collections\Collection|array';

if (($assoc['type'] & ClassMetadata::TO_ONE) > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Is there any explanation on why we had this code there (commit msg)? Maybe @Ocramius can give us some context

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No details in the commit message of 71a6a88 and not sure where I could find details on DDC-3490.

@lcobucci lcobucci changed the title Misleading ORMInvalidArgumentException message Improve misleading ORMInvalidArgumentException message Nov 26, 2017
Copy link
Member

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

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

I've rebased and added a test for one-to-many association as well.

@lcobucci lcobucci self-assigned this Nov 26, 2017
@lcobucci lcobucci added this to the 2.6.0 milestone Nov 26, 2017
foaly-nr1 added 2 commits November 26, 2017 17:55
Since the UoW checks each item of a *-to-many association to ensure
it has the correct type, we should never say that we expect an instance
of `Doctrine\Common\Collections\Collection` or an `array`.
@lcobucci lcobucci merged commit 6e095f7 into doctrine:master Nov 26, 2017
@lcobucci
Copy link
Member

@foaly-nr1 🚢 thanks for your contribution!

@foaly-nr1 foaly-nr1 deleted the DDC6029 branch November 26, 2017 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants