1
0
mirror of synced 2025-02-20 22:23:14 +03:00

Update tests

This commit is contained in:
Michaël Gallego 2014-02-21 10:30:41 +01:00 committed by Marco Pivetta
parent 45e9d6ed5a
commit 0a6c2027f5
4 changed files with 104 additions and 34 deletions

View File

@ -0,0 +1,32 @@
<?php
namespace Doctrine\Tests\Models\Tweet;
/**
* @Entity
* @Table(name="tweet_tweet")
*/
class Tweet
{
/**
* @Id
* @GeneratedValue
* @Column(type="integer")
*/
public $id;
/**
* @Column(type="string")
*/
public $content;
/**
* @ManyToOne(targetEntity="User", inversedBy="tweet")
*/
public $author;
public function setAuthor(User $user)
{
$this->author = $user;
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Doctrine\Tests\Models\Tweet;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
* @Table(name="tweet_user")
*/
class User
{
/**
* @Id
* @GeneratedValue
* @Column(type="integer")
*/
public $id;
/**
* @Column(type="string")
*/
public $name;
/**
* @OneToMany(targetEntity="Tweet", mappedBy="author", cascade={"persist"}, fetch="EXTRA_LAZY")
*/
public $tweets;
public function __construct()
{
$this->tweets = new ArrayCollection();
}
public function addTweet(Tweet $tweet)
{
$tweet->setAuthor($this);
$this->tweets->add($tweet);
}
}

View File

@ -19,12 +19,8 @@
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Tests\Models\CMS\CmsArticle;
use Doctrine\Tests\Models\CMS\CmsComment;
use Doctrine\Tests\Models\Company\CompanyAuction;
use Doctrine\Tests\Models\Company\CompanyEmployee;
use Doctrine\Tests\Models\Company\CompanyFlexUltraContract;
use Doctrine\Tests\Models\Company\CompanyOrganization;
use Doctrine\Tests\Models\Tweet\Tweet;
use Doctrine\Tests\Models\Tweet\User;
/**
* @author Michaël Gallego <mic.gallego@gmail.com>
@ -33,7 +29,7 @@ class PersistentCollectionCriteriaTest extends \Doctrine\Tests\OrmFunctionalTest
{
protected function setUp()
{
$this->useModelSet('company');
$this->useModelSet('tweet');
parent::setUp();
}
@ -47,24 +43,23 @@ class PersistentCollectionCriteriaTest extends \Doctrine\Tests\OrmFunctionalTest
public function loadFixture()
{
$companyOrganization = new CompanyOrganization();
$this->_em->persist($companyOrganization);
$author = new User();
$author->name = 'ngal';
$this->_em->persist($author);
$event1 = new CompanyAuction();
$event1->setData('Foo');
$this->_em->persist($event1);
$companyOrganization->addEvent($event1);
$tweet1 = new Tweet();
$tweet1->content = 'Foo';
$author->addTweet($tweet1);
$event2 = new CompanyAuction();
$event2->setData('Bar');
$this->_em->persist($event2);
$companyOrganization->addEvent($event2);
$tweet2 = new Tweet();
$tweet2->content = 'Bar';
$author->addTweet($tweet2);
$this->_em->flush();
unset($companyOrganization);
unset($event1);
unset($event2);
unset($author);
unset($tweet1);
unset($tweet2);
$this->_em->clear();
}
@ -72,25 +67,24 @@ class PersistentCollectionCriteriaTest extends \Doctrine\Tests\OrmFunctionalTest
public function testCanCountWithoutLoadingPersistentCollection()
{
$this->loadFixture();
$repository = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyOrganization');
$repository = $this->_em->getRepository('Doctrine\Tests\Models\Tweet\User');
$organizations = $repository->findAll();
$organization = $organizations[0];
$events = $organization->events->matching(new Criteria());
$user = $repository->findOneBy(array('name' => 'ngal'));
$tweets = $user->tweets->matching(new Criteria());
$this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $events);
$this->assertFalse($events->isInitialized());
$this->assertCount(2, $events);
$this->assertFalse($events->isInitialized());
$this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $tweets);
$this->assertFalse($tweets->isInitialized());
$this->assertCount(2, $tweets);
$this->assertFalse($tweets->isInitialized());
// Make sure it works with constraints
$events = $organization->events->matching(new Criteria(
Criteria::expr()->eq('id', 2)
$tweets = $user->tweets->matching(new Criteria(
Criteria::expr()->eq('content', 'Foo')
));
$this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $events);
$this->assertFalse($events->isInitialized());
$this->assertCount(1, $events);
$this->assertFalse($events->isInitialized());
$this->assertInstanceOf('Doctrine\ORM\LazyCriteriaCollection', $tweets);
$this->assertFalse($tweets->isInitialized());
$this->assertCount(1, $tweets);
$this->assertFalse($tweets->isInitialized());
}
}

View File

@ -183,6 +183,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase
'Doctrine\Tests\Models\Cache\AttractionContactInfo',
'Doctrine\Tests\Models\Cache\AttractionLocationInfo'
),
'tweet' => array(
'Doctrine\Tests\Models\Tweet\User',
'Doctrine\Tests\Models\Tweet\Tweet'
)
);
/**