summaryrefslogtreecommitdiffstats
path: root/tests/Psecio/Gatekeeper/DataSource/MysqlTest.php
blob: d91f42c27ed2bdd90ac4861d493b1b29f63d06b5 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

namespace Psecio\Gatekeeper\DataSource;

include_once __DIR__.'/../MockPdo.php';
include_once __DIR__.'/../MockModel.php';

class MysqlTest extends \Psecio\Gatekeeper\Base
{
    public function testCreatePdoOnConstruct()
    {
        $config = array(
            'username' => 'foo',
            'password' => 'bar',
            'name' => 'dbname',
            'host' => '127.0.0.1'
        );
        $pdo = $this->getMockBuilder('\Psecio\Gatekeeper\MockPdo')->getMock();

        $mysql = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
            ->setConstructorArgs(array($config, $pdo))
            ->setMethods(array('buildPdo'))
            ->getMock();

        $this->assertEquals($mysql->getDb(), $pdo);
    }

    /**
     * Test the getter/setter of the DB instance
     *     (just uses a basic object)
     */
    public function testGetSetDatabaseInstance()
    {
        $mysql = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
            ->disableOriginalConstructor()
            ->setMethods(array('buildPdo'))
            ->getMock();

        $db = (object)array('test' => 'foo');
        $mysql->setDb($db);

        $this->assertEquals($mysql->getDb(), $db);
    }

    /**
     * Test getting the table name for the model instance
     */
    public function testGetTableName()
    {
        $config = array();
        $pdo = $this->getMockBuilder('\Psecio\Gatekeeper\MockPdo')->getMock();

        $ds = $this->getMockBuilder('\Psecio\Gatekeeper\DataSource\Mysql')
            ->setConstructorArgs(array($config, $pdo))
            ->setMethods(array('buildPdo'))
            ->getMock();

        $mysql = new \Psecio\Gatekeeper\MockModel($ds);
        $this->assertEquals('test', $mysql->getTableName());
    }
}