Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Functional / EntityRepositoryCriteriaTest.php
1 <?php
2 /*
3  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14  *
15  * This software consists of voluntary contributions made by many individuals
16  * and is licensed under the MIT license. For more information, see
17  * <http://www.doctrine-project.org>.
18  */
19
20 namespace Doctrine\Tests\ORM\Functional;
21
22 use Doctrine\Tests\Models\Generic\DateTimeModel;
23 use Doctrine\Common\Collections\Criteria;
24
25 /**
26  * @author Josiah <josiah@jjs.id.au>
27  */
28 class EntityRepositoryCriteriaTest extends \Doctrine\Tests\OrmFunctionalTestCase
29 {
30     protected function setUp()
31     {
32         $this->useModelSet('generic');
33         parent::setUp();
34     }
35
36     public function tearDown()
37     {
38         if ($this->_em) {
39             $this->_em->getConfiguration()->setEntityNamespaces(array());
40         }
41         parent::tearDown();
42     }
43
44     public function loadFixture()
45     {
46         $today = new DateTimeModel();
47         $today->datetime =
48         $today->date =
49         $today->time =
50             new \DateTime('today');
51         $this->_em->persist($today);
52
53         $tomorrow = new DateTimeModel();
54         $tomorrow->datetime =
55         $tomorrow->date =
56         $tomorrow->time =
57             new \DateTime('tomorrow');
58         $this->_em->persist($tomorrow);
59
60         $yesterday = new DateTimeModel();
61         $yesterday->datetime =
62         $yesterday->date =
63         $yesterday->time =
64             new \DateTime('yesterday');
65         $this->_em->persist($yesterday);
66
67         $this->_em->flush();
68
69         unset($today);
70         unset($tomorrow);
71         unset($yesterday);
72
73         $this->_em->clear();
74     }
75
76     public function testLteDateComparison()
77     {
78         $this->loadFixture();
79
80         $repository = $this->_em->getRepository('Doctrine\Tests\Models\Generic\DateTimeModel');
81         $dates = $repository->matching(new Criteria(
82             Criteria::expr()->lte('datetime', new \DateTime('today'))
83         ));
84
85         $this->assertEquals(2, count($dates));
86     }
87 }