Skip to content

Commit

Permalink
Apply review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
kira0269 committed Jan 13, 2025
1 parent adf4a53 commit 6f07ef5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
9 changes: 0 additions & 9 deletions tests/Tests/Models/Enums/BookCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
Expand Down Expand Up @@ -41,12 +40,4 @@ public function getBooks(): Collection
{
return $this->books;
}

public function getBooksWithColor(BookColor $bookColor): Collection
{
$criteria = Criteria::create()
->andWhere(Criteria::expr()->eq('bookColor', $bookColor));

return $this->books->matching($criteria);
}
}
9 changes: 0 additions & 9 deletions tests/Tests/Models/Enums/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
Expand All @@ -29,14 +28,6 @@ public function __construct()
$this->books = new ArrayCollection();
}

public function getBooksWithColor(BookColor $bookColor): Collection
{
$criteria = Criteria::create()
->andWhere(Criteria::expr()->eq('bookColor', $bookColor));

return $this->books->matching($criteria);
}

public function getBooks(): Collection
{
return $this->books;
Expand Down
36 changes: 24 additions & 12 deletions tests/Tests/ORM/Functional/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Doctrine\Tests\ORM\Functional;

use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\AbstractQuery;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
Expand Down Expand Up @@ -78,7 +80,6 @@ public function testEnumHydrationObjectHydrator(): void
$this->_em->persist($card2);
$this->_em->flush();

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

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

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

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

unset($library, $redBook, $blueBook);

$this->_em->clear();

$library = $this->_em->find(Library::class, $libraryId);
$this->assertCount(1, $library->getBooksWithColor(BookColor::RED));

$redBooks = $library->books->matching(
Criteria::create()->andWhere(Criteria::expr()->eq('bookColor', BookColor::RED)),
);

$this->assertCount(1, $redBooks);
}

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

unset($library, $redBook, $blueBook);

$this->_em->clear();

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

$this->assertCount(1, $library->getBooksWithColor(BookColor::RED));
$redBooks = $library->books->matching(
Criteria::create()->andWhere(Criteria::expr()->eq('bookColor', BookColor::RED)),
);

$this->assertCount(1, $redBooks);
}

public function testEnumLazyCollectionMatchingWithManyToMany(): void
Expand Down Expand Up @@ -612,10 +617,14 @@ public function testEnumLazyCollectionMatchingWithManyToMany(): void
$thrillerCategoryId = $thrillerCategory->id;

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

$thrillerCategory = $this->_em->find(BookCategory::class, $thrillerCategoryId);
$this->assertCount(1, $thrillerCategory->getBooksWithColor(BookColor::RED));

$redBooks = $thrillerCategory->books->matching(
Criteria::create()->andWhere(Criteria::expr()->eq('bookColor', BookColor::RED)),
);

$this->assertCount(1, $redBooks);
}

public function testEnumInitializedCollectionMatchingWithManyToMany(): void
Expand Down Expand Up @@ -646,14 +655,17 @@ public function testEnumInitializedCollectionMatchingWithManyToMany(): void
$thrillerCategoryId = $thrillerCategory->id;

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

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

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

$this->assertCount(1, $thrillerCategory->getBooksWithColor(BookColor::RED));
$redBooks = $thrillerCategory->books->matching(
Criteria::create()->andWhere(Criteria::expr()->eq('bookColor', BookColor::RED)),
);

$this->assertCount(1, $redBooks);
}
}

0 comments on commit 6f07ef5

Please sign in to comment.