Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a6ef44

Browse files
committed
doctrine#1277 DDC-3346 DDC-3531 - refactoring test code for simplicity/readability
1 parent 33230e5 commit 0a6ef44

1 file changed

Lines changed: 15 additions & 40 deletions

File tree

tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php

Lines changed: 15 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,12 @@ public function setUp()
1515
$this->useModelSet('ddc3346');
1616

1717
parent::setUp();
18+
19+
$this->loadAuthorFixture();
1820
}
1921

2022
public function testFindOneWithEagerFetchWillNotHydrateLimitedCollection()
2123
{
22-
$user = new DDC3346Author();
23-
$user->username = "bwoogy";
24-
25-
$article1 = new DDC3346Article();
26-
$article1->setAuthor($user);
27-
28-
$article2 = new DDC3346Article();
29-
$article2->setAuthor($user);
30-
31-
$this->_em->persist($user);
32-
$this->_em->persist($article1);
33-
$this->_em->persist($article2);
34-
$this->_em->flush();
35-
$this->_em->clear();
36-
3724
/** @var DDC3346Author $author */
3825
$author = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findOneBy(
3926
array('username' => "bwoogy")
@@ -44,33 +31,32 @@ public function testFindOneWithEagerFetchWillNotHydrateLimitedCollection()
4431

4532
public function testFindLimitedWithEagerFetchWillNotHydrateLimitedCollection()
4633
{
47-
$user = new DDC3346Author();
48-
$user->username = "bwoogy";
49-
50-
$article1 = new DDC3346Article();
51-
$article1->setAuthor($user);
52-
53-
$article2 = new DDC3346Article();
54-
$article2->setAuthor($user);
34+
/** @var DDC3346Author[] $authors */
35+
$authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy(
36+
array('username' => "bwoogy"),
37+
null,
38+
1
39+
);
5540

56-
$this->_em->persist($user);
57-
$this->_em->persist($article1);
58-
$this->_em->persist($article2);
59-
$this->_em->flush();
60-
$this->_em->clear();
41+
$this->assertCount(1, $authors);
42+
$this->assertCount(2, $authors[0]->articles);
43+
}
6144

45+
public function testFindWithEagerFetchAndOffsetWillNotHydrateLimitedCollection()
46+
{
6247
/** @var DDC3346Author[] $authors */
6348
$authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy(
6449
array('username' => "bwoogy"),
6550
null,
51+
null,
6652
1
6753
);
6854

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

73-
public function testFindWithEagerFetchAndOffsetWillNotHydrateLimitedCollection()
59+
private function loadAuthorFixture()
7460
{
7561
$user = new DDC3346Author();
7662
$user->username = "bwoogy";
@@ -86,16 +72,5 @@ public function testFindWithEagerFetchAndOffsetWillNotHydrateLimitedCollection()
8672
$this->_em->persist($article2);
8773
$this->_em->flush();
8874
$this->_em->clear();
89-
90-
/** @var DDC3346Author[] $authors */
91-
$authors = $this->_em->getRepository(DDC3346Author::CLASSNAME)->findBy(
92-
array('username' => "bwoogy"),
93-
null,
94-
null,
95-
1
96-
);
97-
98-
$this->assertCount(1, $authors);
99-
$this->assertCount(2, $authors[0]->articles);
10075
}
10176
}

0 commit comments

Comments
 (0)