FinderTest::testGetConnection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Fwk\Db;
4
5
/**
6
 * Test class for Finder.
7
 * Generated by PHPUnit on 2012-07-05 at 13:54:28.
8
 */
9
class FinderTest extends \PHPUnit_Framework_TestCase
10
{
11
    /**
12
     * @var Finder
13
     */
14
    protected $object;
15
    
16
    /**
17
     * @var Connection
18
     */
19
    protected $db;
20
21
    /**
22
     * Sets up the fixture, for example, opens a network connection.
23
     * This method is called before a test is executed.
24
     */
25
    protected function setUp()
26
    {
27
        $this->db = new Connection(array(
28
            'memory' => true,
29
            'driver' => 'pdo_sqlite'
30
        ));
31
        
32
        \FwkDbTestUtil::createTestDb($this->db);
33
        $this->object = new Finder(new Table('fwkdb_test_users'));
34
    }
35
36
    protected function tearDown() {
37
        \FwkDbTestUtil::dropTestDb($this->db);
38
    }
39
    
40
    /**
41
     */
42
    public function testGetConnectionFail()
43
    {
44
        $this->setExpectedException('\Fwk\Db\Exception');
45
        $this->object->getConnection();
46
    }
47
48
    public function testGetConnection()
49
    {
50
        $db = new Connection(array(
51
                    'memory' => true,
52
                    'driver' => 'pdo_sqlite'
53
                ));
54
55
        $this->object->setConnection($db);
56
        $this->assertEquals($db, $this->object->getConnection());
57
    }
58
    
59
    public function testPreventDoubleExecute()
60
    {
61
        $this->object->setConnection($this->db);
62
63
        $this->object->find(array('id' => 2));
64
        $this->setExpectedException('\Fwk\Db\Exception');
65
        $this->object->find(array('id' => 2));
66
    }
67
    
68
    public function testPreventOneDoubleExecute()
69
    {
70
        $this->object = $this->db->table('fwkdb_test_users')->finder();
71
72
        $this->object->one(2);
73
        $this->setExpectedException('\Fwk\Db\Exception');
74
        $this->object->one(2);
75
    }
76
    
77
    public function testMissingIdentifiers()
78
    {
79
        $this->object = $this->db->table('fwkdb_test_users_emails')->finder();
80
        $this->setExpectedException('\Fwk\Db\Exception');
81
        $this->object->one(2);
82
    }
83
}
84