Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDC-3346] Failing test for issue (bad findOneBy behaviour with eager fetch) #1277

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/Doctrine/Tests/Models/DDC3346/DDC3346Article.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Doctrine\Tests\Models\DDC3346;

/**
* @Entity
* @Table(name="ddc3346_articles")
*/
class DDC3346Article
{
const CLASSNAME = 'Doctrine\Tests\Models\DDC3346\DDC3346Article';
/**
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
public $id;
/**
* @ManyToOne(targetEntity="DDC3346Author", inversedBy="articles")
* @JoinColumn(name="user_id", referencedColumnName="id")
*/
public $user;

public function setAuthor(DDC3346Author $author)
{
$this->user = $author;
}
}
25 changes: 25 additions & 0 deletions tests/Doctrine/Tests/Models/DDC3346/DDC3346Author.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Doctrine\Tests\Models\DDC3346;

/**
* @Entity
* @Table(name="ddc3346_users")
*/
class DDC3346Author
{
const CLASSNAME = 'Doctrine\Tests\Models\DDC3346\DDC3346Author';
/**
* @Id @Column(type="integer")
* @GeneratedValue
*/
public $id;
/**
* @Column(type="string", length=255, unique=true)
*/
public $username;
/**
* @OneToMany(targetEntity="DDC3346Article", mappedBy="user", fetch="EAGER", cascade={"detach"})
*/
public $articles;
}
82 changes: 82 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3346Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Tests\Models\DDC3346\DDC3346Article;
use Doctrine\Tests\Models\DDC3346\DDC3346Author;

/**
* @group DDC-3346
*/
class DDC3346Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
parent::setUp();

$this->setUpEntitySchema(
array(
DDC3346Author::CLASSNAME,
DDC3346Article::CLASSNAME,
)
);
}

public function testFindOneByWithEagerFetch()
{
$user1 = new DDC3346Author();
$user1->username = "first";

$user2 = new DDC3346Author();
$user2->username = "second";

$user3 = new DDC3346Author();
$user3->username = "third";

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

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

$this->_em->persist($user1);
$this->_em->persist($user2);
$this->_em->persist($user3);
$this->_em->persist($article1);
$this->_em->persist($article2);
$this->_em->flush();
$this->_em->close();

/** @var DDC3346Author[] $authors */
$authors = $this->_em->getRepository('Doctrine\Tests\Models\DDC3346\DDC3346Author')->findBy(
array('username' => "first")
);

$this->assertCount(1, $authors);

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

$this->_em->close();

/** @var DDC3346Author $author */
$author = $this->_em->getRepository('Doctrine\Tests\Models\DDC3346\DDC3346Author')->findOneBy(
array('username' => "first")
);

$this->assertCount(2, $author->articles);

$this->_em->close();
unset($authors);

/** @var DDC3346Author[] $authors */
$authors = $this->_em->getRepository('Doctrine\Tests\Models\DDC3346\DDC3346Author')->findBy(
array(), array(), 3
);

$this->assertCount(3, $authors);

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