Skip to content

Commit

Permalink
doctrine#1277 DDC-3346 DDC-3531 - refactoring test code for simplicit…
Browse files Browse the repository at this point in the history
…y/readability
  • Loading branch information
Ocramius committed Jan 23, 2015
1 parent 33230e5 commit 0a6ef44
Showing 1 changed file with 15 additions and 40 deletions.
55 changes: 15 additions & 40 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,12 @@ public function setUp()
$this->useModelSet('ddc3346');

parent::setUp();

$this->loadAuthorFixture();
}

public function testFindOneWithEagerFetchWillNotHydrateLimitedCollection()
{
$user = new DDC3346Author();
$user->username = "bwoogy";

$article1 = new DDC3346Article();
$article1->setAuthor($user);

$article2 = new DDC3346Article();
$article2->setAuthor($user);

$this->_em->persist($user);
$this->_em->persist($article1);
$this->_em->persist($article2);
$this->_em->flush();
$this->_em->clear();

/** @var DDC3346Author $author */
$author = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findOneBy(
array('username' => "bwoogy")
Expand All @@ -44,33 +31,32 @@ public function testFindOneWithEagerFetchWillNotHydrateLimitedCollection()

public function testFindLimitedWithEagerFetchWillNotHydrateLimitedCollection()
{
$user = new DDC3346Author();
$user->username = "bwoogy";

$article1 = new DDC3346Article();
$article1->setAuthor($user);

$article2 = new DDC3346Article();
$article2->setAuthor($user);
/** @var DDC3346Author[] $authors */
$authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy(
array('username' => "bwoogy"),
null,
1
);

$this->_em->persist($user);
$this->_em->persist($article1);
$this->_em->persist($article2);
$this->_em->flush();
$this->_em->clear();
$this->assertCount(1, $authors);
$this->assertCount(2, $authors[0]->articles);
}

public function testFindWithEagerFetchAndOffsetWillNotHydrateLimitedCollection()
{
/** @var DDC3346Author[] $authors */
$authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy(
array('username' => "bwoogy"),
null,
null,
1
);

$this->assertCount(1, $authors);
$this->assertCount(2, $authors[0]->articles);
}

public function testFindWithEagerFetchAndOffsetWillNotHydrateLimitedCollection()
private function loadAuthorFixture()
{
$user = new DDC3346Author();
$user->username = "bwoogy";
Expand All @@ -86,16 +72,5 @@ public function testFindWithEagerFetchAndOffsetWillNotHydrateLimitedCollection()
$this->_em->persist($article2);
$this->_em->flush();
$this->_em->clear();

/** @var DDC3346Author[] $authors */
$authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy(
array('username' => "bwoogy"),
null,
null,
1
);

$this->assertCount(1, $authors);
$this->assertCount(2, $authors[0]->articles);
}
}

0 comments on commit 0a6ef44

Please sign in to comment.