| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace Doctrine\Tests\ORM\Functional\Ticket; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Doctrine\Common\Collections\ArrayCollection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Doctrine\Common\Collections\Collection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Doctrine\Common\Collections\Criteria; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Doctrine\Tests\OrmFunctionalTestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use function assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | final class GH7534Test extends OrmFunctionalTestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |      * {@inheritDoc} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     protected function setUp() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         parent::setUp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $this->setUpEntitySchema( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |                 GH7534Person::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |                 GH7534PhoneNumber::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |             ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->_em->persist( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |             new GH7534Person( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                 [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                     new GH7534PhoneNumber('123', 0), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |                     new GH7534PhoneNumber('456', 1), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |                     new GH7534PhoneNumber('789', 2), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |                 ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         $this->_em->flush(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->_em->clear(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      * @test | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @group 7534 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     public function collectionShouldBe() : void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $person = $this->_em->find(GH7534Person::class, 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         assert($person instanceof GH7534Person); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |         $criteria = Criteria::create()->where(Criteria::expr()->eq('type', 1)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                                       ->orWhere(Criteria::expr()->eq('type', 2)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $phoneNumbers = $person->phoneNumbers->matching($criteria); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         self::assertCount(2, $phoneNumbers); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         self::assertSame('456', $phoneNumbers->get(0)->number); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         self::assertSame('789', $phoneNumbers->get(1)->number); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  * @Entity | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | class GH7534Person | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |      * @Id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * @Column(type="integer") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * @GeneratedValue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @var int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     public $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |      * @ManyToMany(targetEntity=GH7534PhoneNumber::class, cascade={"all"}) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |      * @var Collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     public $phoneNumbers; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * @param GH7534PhoneNumber[] $phoneNumbers | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 84 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |     public function __construct(array $phoneNumbers = []) | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |         $this->phoneNumbers = new ArrayCollection($phoneNumbers); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |  * @Entity | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | class GH7534PhoneNumber | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |      * @Id | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      * @Column(type="integer") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @GeneratedValue | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @var int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     public $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @Column(type="string") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |     public $number; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |      * @Column(type="integer") | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |      * @var int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     public $type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     public function __construct(string $number, int $type) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |         $this->number = $number; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |         $this->type   = $type; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 121 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 122 |  |  |  |