10000 reproduce #21274 · dmaicher/symfony@77f9c28 · GitHub
[go: up one dir, main page]

Skip to content

Commit 77f9c28

Browse files
committed
reproduce symfony#21274
1 parent cc398db commit 77f9c28

File tree

2 files changed

+75
-0
lines changed

2 files changed

+75
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
4+
use Doctrine\ORM\Mapping as ORM;
5+
6+
/**
7+
* an entity that has two objects (class without toString methods) as primary key
8+
*
9+
* @ORM\Entity
10+
*/
11+
class CompositeObjectNoToStringIdEntity
12+
{
13+
/**
14+
* @var SingleIntIdNoToStringEntity
15+
*
16+
* @ORM\Id
17+
* @ORM\ManyToOne(targetEntity="SingleIntIdNoToStringEntity", cascade={"persist"})
18+
* @ORM\JoinColumn(name="object_one_id")
19+
*/
20+
protected $objectOne;
21+
22+
/**
23+
* @var SingleIntIdNoToStringEntity
24+
*
25+
* @ORM\Id
26+
* @ORM\ManyToOne(targetEntity="SingleIntIdNoToStringEntity", cascade={"persist"})
27+
* @ORM\JoinColumn(name="object_two_id")
28+
*/
29+
protected $objectTwo;
30+
31+
public function __construct(SingleIntIdNoToStringEntity $objectOne, SingleIntIdNoToStringEntity $objectTwo)
32+
{
33+
$this->objectOne = $objectOne;
34+
$this->objectTwo = $objectTwo;
35+
}
36+
37+
/**
38+
* @return SingleIntIdNoToStringEntity
39+
*/
40+
public function getObjectOne()
41+
{
42+
return $this->objectOne;
43+
}
44+
45+
/**
46+
* @return SingleIntIdNoToStringEntity
47+
*/
48+
public function getObjectTwo()
49+
{
50+
return $this->objectTwo;
51+
}
52+
}

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\Common\Persistence\ObjectRepository;
1818
use Symfony\Bridge\Doctrine\Test\DoctrineTestHelper;
1919
use Symfony\Bridge\Doctrine\Test\TestRepositoryFactory;
20+
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeObjectNoToStringIdEntity;
2021
use Symfony\Bridge\Doctrine\Tests\Fixtures\Employee;
2122
use Symfony\Bridge\Doctrine\Tests\Fixtures\Person;
2223
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
@@ -146,6 +147,7 @@ private function createSchema(ObjectManager $em)
146147
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2'),
147148
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\Person'),
148149
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\Employee'),
150+
$em->getClassMetadata('Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeObjectNoToStringIdEntity'),
149151
));
150152
}
151153

@@ -617,4 +619,25 @@ public function testInvalidateRepositoryForInheritance()
617619
$entity = new Person(1, 'Foo');
618620
$this->validator->validate($entity, $constraint);
619621
}
622+
623+
public function testValidateUniquenessWithCompositeObjectNoToStringIdEntity()
624+
{
625+
$constraint = new UniqueEntity(array(
626+
'message' => 'myMessage',
627+
'fields' => array('objectOne', 'objectTwo'),
628+
'em' => self::EM_NAME,
629+
'entityClass' => 'Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeObjectNoToStringIdEntity',
630+
));
631+
632+
$objectOne = new SingleIntIdNoToStringEntity(1, 'foo');
633+
$objectTwo = new SingleIntIdNoToStringEntity(2, 'bar');
634+
$entity = new CompositeObjectNoToStringIdEntity($objectOne, $objectTwo);
635+
636+
$this->em->persist($entity);
637+
$this->em->flush();
638+
639+
$newEntity = new CompositeObjectNoToStringIdEntity($objectOne, $objectTwo);
640+
641+
$this->validator->validate($newEntity, $constraint);
642+
}
620643
}

0 commit comments

Comments
 (0)
0