Skip to content

Commit 6f07ef5

Browse files
committed
Apply review suggestions
1 parent adf4a53 commit 6f07ef5

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

tests/Tests/Models/Enums/BookCategory.php

-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Doctrine\Common\Collections\ArrayCollection;
88
use Doctrine\Common\Collections\Collection;
9-
use Doctrine\Common\Collections\Criteria;
109
use Doctrine\ORM\Mapping\Column;
1110
use Doctrine\ORM\Mapping\Entity;
1211
use Doctrine\ORM\Mapping\GeneratedValue;
@@ -41,12 +40,4 @@ public function getBooks(): Collection
4140
{
4241
return $this->books;
4342
}
44-
45-
public function getBooksWithColor(BookColor $bookColor): Collection
46-
{
47-
$criteria = Criteria::create()
48-
->andWhere(Criteria::expr()->eq('bookColor', $bookColor));
49-
50-
return $this->books->matching($criteria);
51-
}
5243
}

tests/Tests/Models/Enums/Library.php

-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use Doctrine\Common\Collections\ArrayCollection;
88
use Doctrine\Common\Collections\Collection;
9-
use Doctrine\Common\Collections\Criteria;
109
use Doctrine\ORM\Mapping\Column;
1110
use Doctrine\ORM\Mapping\Entity;
1211
use Doctrine\ORM\Mapping\GeneratedValue;
@@ -29,14 +28,6 @@ public function __construct()
2928
$this->books = new ArrayCollection();
3029
}
3130

32-
public function getBooksWithColor(BookColor $bookColor): Collection
33-
{
34-
$criteria = Criteria::create()
35-
->andWhere(Criteria::expr()->eq('bookColor', $bookColor));
36-
37-
return $this->books->matching($criteria);
38-
}
39-
4031
public function getBooks(): Collection
4132
{
4233
return $this->books;

tests/Tests/ORM/Functional/EnumTest.php

+24-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Doctrine\Tests\ORM\Functional;
66

7+
use Doctrine\Common\Collections\Collection;
8+
use Doctrine\Common\Collections\Criteria;
79
use Doctrine\ORM\AbstractQuery;
810
use Doctrine\ORM\Mapping\Column;
911
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
@@ -78,7 +80,6 @@ public function testEnumHydrationObjectHydrator(): void
7880
$this->_em->persist($card2);
7981
$this->_em->flush();
8082

81-
unset($card1, $card2);
8283
$this->_em->clear();
8384

8485
/** @var list<Card> $foundCards */
@@ -406,7 +407,6 @@ public function testFindByEnum(): void
406407
$this->_em->persist($card2);
407408
$this->_em->flush();
408409

409-
unset($card1, $card2);
410410
$this->_em->clear();
411411

412412
/** @var list<Card> $foundCards */
@@ -542,12 +542,15 @@ public function testEnumLazyCollectionMatchingWithOneToMany(): void
542542
$this->_em->flush();
543543
$libraryId = $library->id;
544544

545-
unset($library, $redBook, $blueBook);
546-
547545
$this->_em->clear();
548546

549547
$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);
551554
}
552555

553556
public function testEnumInitializedCollectionMatchingWithOneToMany(): void
@@ -571,8 +574,6 @@ public function testEnumInitializedCollectionMatchingWithOneToMany(): void
571574
$this->_em->flush();
572575
$libraryId = $library->id;
573576

574-
unset($library, $redBook, $blueBook);
575-
576577
$this->_em->clear();
577578

578579
$library = $this->_em->find(Library::class, $libraryId);
@@ -581,7 +582,11 @@ public function testEnumInitializedCollectionMatchingWithOneToMany(): void
581582
// Load books collection first
582583
$this->assertCount(2, $library->getBooks());
583584

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);
585590
}
586591

587592
public function testEnumLazyCollectionMatchingWithManyToMany(): void
@@ -612,10 +617,14 @@ public function testEnumLazyCollectionMatchingWithManyToMany(): void
612617
$thrillerCategoryId = $thrillerCategory->id;
613618

614619
$this->_em->clear();
615-
unset($thrillerCategory, $fantasyCategory, $blueBook, $redBook);
616620

617621
$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);
619628
}
620629

621630
public function testEnumInitializedCollectionMatchingWithManyToMany(): void
@@ -646,14 +655,17 @@ public function testEnumInitializedCollectionMatchingWithManyToMany(): void
646655
$thrillerCategoryId = $thrillerCategory->id;
647656

648657
$this->_em->clear();
649-
unset($thrillerCategory, $fantasyCategory, $blueBook, $redBook);
650658

651659
$thrillerCategory = $this->_em->find(BookCategory::class, $thrillerCategoryId);
652660
$this->assertInstanceOf(BookCategory::class, $thrillerCategory);
653661

654662
// Load books collection first
655663
$this->assertCount(2, $thrillerCategory->getBooks());
656664

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);
658670
}
659671
}

0 commit comments

Comments
 (0)