forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
tests/Doctrine/Tests/ORM/Functional/EntityRepositoryCriteriaTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace Doctrine\Tests\ORM\Functional; | ||
|
||
use Doctrine\Tests\Models\Generic\DateTimeModel; | ||
use Doctrine\Common\Collections\Criteria; | ||
|
||
require_once __DIR__ . '/../../TestInit.php'; | ||
|
||
/** | ||
* @author Josiah <[email protected]> | ||
*/ | ||
class EntityRepositoryCriteriaTest extends \Doctrine\Tests\OrmFunctionalTestCase | ||
{ | ||
protected function setUp() { | ||
$this->useModelSet('generic'); | ||
parent::setUp(); | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
if ($this->_em) { | ||
$this->_em->getConfiguration()->setEntityNamespaces(array()); | ||
} | ||
parent::tearDown(); | ||
} | ||
|
||
public function loadFixture() | ||
{ | ||
$today = new DateTimeModel(); | ||
$today->datetime = | ||
$today->date = | ||
$today->time = | ||
new \DateTime('today'); | ||
$this->_em->persist($today); | ||
|
||
$tomorrow = new DateTimeModel(); | ||
$tomorrow->datetime = | ||
$tomorrow->date = | ||
$tomorrow->time = | ||
new \DateTime('tomorrow'); | ||
$this->_em->persist($tomorrow); | ||
|
||
$yesterday = new DateTimeModel(); | ||
$yesterday->datetime = | ||
$yesterday->date = | ||
$yesterday->time = | ||
new \DateTime('yesterday'); | ||
$this->_em->persist($yesterday); | ||
|
||
$this->_em->flush(); | ||
|
||
unset($today); | ||
unset($tomorrow); | ||
unset($yesterday); | ||
|
||
$this->_em->clear(); | ||
} | ||
|
||
public function testLteDateComparison() | ||
{ | ||
$this->loadFixture(); | ||
|
||
$repository = $this->_em->getRepository('Doctrine\Tests\Models\Generic\DateTimeModel'); | ||
$dates = $repository->matching(new Criteria( | ||
Criteria::expr()->lte('datetime', new \DateTime('today')) | ||
)); | ||
|
||
$this->assertEquals(2, count($dates)); | ||
} | ||
} |