4
4
5
5
namespace Doctrine \Tests \ORM \Functional ;
6
6
7
+ use Doctrine \Common \Collections \Collection ;
8
+ use Doctrine \Common \Collections \Criteria ;
7
9
use Doctrine \ORM \AbstractQuery ;
8
10
use Doctrine \ORM \Mapping \Column ;
9
11
use Doctrine \ORM \Mapping \Driver \AttributeDriver ;
@@ -78,7 +80,6 @@ public function testEnumHydrationObjectHydrator(): void
78
80
$ this ->_em ->persist ($ card2 );
79
81
$ this ->_em ->flush ();
80
82
81
- unset($ card1 , $ card2 );
82
83
$ this ->_em ->clear ();
83
84
84
85
/** @var list<Card> $foundCards */
@@ -406,7 +407,6 @@ public function testFindByEnum(): void
406
407
$ this ->_em ->persist ($ card2 );
407
408
$ this ->_em ->flush ();
408
409
409
- unset($ card1 , $ card2 );
410
410
$ this ->_em ->clear ();
411
411
412
412
/** @var list<Card> $foundCards */
@@ -542,12 +542,15 @@ public function testEnumLazyCollectionMatchingWithOneToMany(): void
542
542
$ this ->_em ->flush ();
543
543
$ libraryId = $ library ->id ;
544
544
545
- unset($ library , $ redBook , $ blueBook );
546
-
547
545
$ this ->_em ->clear ();
548
546
549
547
$ library = $ this ->_em ->find (Library::class, $ libraryId );
550
- $ this ->assertCount (1 , $ library ->getBooksWithColor (BookColor::RED ));
548
+
549
+ $ redBooks = $ library ->books ->matching (
550
+ Criteria::create ()->andWhere (Criteria::expr ()->eq ('bookColor ' , BookColor::RED )),
551
+ );
552
+
553
+ $ this ->assertCount (1 , $ redBooks );
551
554
}
552
555
553
556
public function testEnumInitializedCollectionMatchingWithOneToMany (): void
@@ -571,8 +574,6 @@ public function testEnumInitializedCollectionMatchingWithOneToMany(): void
571
574
$ this ->_em ->flush ();
572
575
$ libraryId = $ library ->id ;
573
576
574
- unset($ library , $ redBook , $ blueBook );
575
-
576
577
$ this ->_em ->clear ();
577
578
578
579
$ library = $ this ->_em ->find (Library::class, $ libraryId );
@@ -581,7 +582,11 @@ public function testEnumInitializedCollectionMatchingWithOneToMany(): void
581
582
// Load books collection first
582
583
$ this ->assertCount (2 , $ library ->getBooks ());
583
584
584
- $ this ->assertCount (1 , $ library ->getBooksWithColor (BookColor::RED ));
585
+ $ redBooks = $ library ->books ->matching (
586
+ Criteria::create ()->andWhere (Criteria::expr ()->eq ('bookColor ' , BookColor::RED )),
587
+ );
588
+
589
+ $ this ->assertCount (1 , $ redBooks );
585
590
}
586
591
587
592
public function testEnumLazyCollectionMatchingWithManyToMany (): void
@@ -612,10 +617,14 @@ public function testEnumLazyCollectionMatchingWithManyToMany(): void
612
617
$ thrillerCategoryId = $ thrillerCategory ->id ;
613
618
614
619
$ this ->_em ->clear ();
615
- unset($ thrillerCategory , $ fantasyCategory , $ blueBook , $ redBook );
616
620
617
621
$ thrillerCategory = $ this ->_em ->find (BookCategory::class, $ thrillerCategoryId );
618
- $ this ->assertCount (1 , $ thrillerCategory ->getBooksWithColor (BookColor::RED ));
622
+
623
+ $ redBooks = $ thrillerCategory ->books ->matching (
624
+ Criteria::create ()->andWhere (Criteria::expr ()->eq ('bookColor ' , BookColor::RED )),
625
+ );
626
+
627
+ $ this ->assertCount (1 , $ redBooks );
619
628
}
620
629
621
630
public function testEnumInitializedCollectionMatchingWithManyToMany (): void
@@ -646,14 +655,17 @@ public function testEnumInitializedCollectionMatchingWithManyToMany(): void
646
655
$ thrillerCategoryId = $ thrillerCategory ->id ;
647
656
648
657
$ this ->_em ->clear ();
649
- unset($ thrillerCategory , $ fantasyCategory , $ blueBook , $ redBook );
650
658
651
659
$ thrillerCategory = $ this ->_em ->find (BookCategory::class, $ thrillerCategoryId );
652
660
$ this ->assertInstanceOf (BookCategory::class, $ thrillerCategory );
653
661
654
662
// Load books collection first
655
663
$ this ->assertCount (2 , $ thrillerCategory ->getBooks ());
656
664
657
- $ this ->assertCount (1 , $ thrillerCategory ->getBooksWithColor (BookColor::RED ));
665
+ $ redBooks = $ thrillerCategory ->books ->matching (
666
+ Criteria::create ()->andWhere (Criteria::expr ()->eq ('bookColor ' , BookColor::RED )),
667
+ );
668
+
669
+ $ this ->assertCount (1 , $ redBooks );
658
670
}
659
671
}
0 commit comments