-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
/** | ||
* @ManyToMany(targetEntity="DDC6029User", mappedBy="groups") | ||
*/ | ||
private $users; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.'); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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`.
@foaly-nr1 🚢 thanks for your contribution! |
See #6029 (comment).