summaryrefslogtreecommitdiff
path: root/vendor/j4mie/idiorm/test/CacheIntegrationTest.php
blob: 0a5dc6101c88a2f131b7b98b8d1206f4a4c049f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

class CacheIntegrationTest extends PHPUnit_Framework_TestCase {

    public function setUp() {
        ORM::configure('sqlite::memory:');
        ORM::configure('logging', true);
        ORM::configure('caching', true);

        ORM::raw_execute('CREATE TABLE `league` ( `class_id` INTEGER )');
        // needs to be individually inserted to support SQLite before
        // version 3.7.11
        ORM::raw_execute('INSERT INTO `league`(`class_id`) VALUES (1)');
        ORM::raw_execute('INSERT INTO `league`(`class_id`) VALUES (2)');
        ORM::raw_execute('INSERT INTO `league`(`class_id`) VALUES (3)');

        $x = ORM::for_table('league')->count();
        $this->assertEquals(3, $x);
    }

    public function tearDown() {
        ORM::raw_execute('DROP TABLE `league`');
    }

    public function testRegressionForPullRequest319() {
        $rs = ORM::for_table('league')->where('class_id', 1);
        $total = $rs->count();
        $this->assertEquals(1, $total);
        $row = $rs->find_one();
        $this->assertEquals(array('class_id' => 1), $row->as_array());

        $rs = ORM::for_table('league')->where('class_id', 1);
        $total = $rs->count();
        $this->assertEquals(1, $total);
        try {
            $row = $rs->find_one();
        } catch(PDOException $e) {
            $this->fail("Caching is breaking subsequent queries!\n{$e->getMessage()}");
        }
        $this->assertEquals(array('class_id' => 1), $row->as_array());
    }

}