Completed
Push — master ( f2ef3e...a98c98 )
by Bartko
01:49
created

Doctrine2DBALAdapterTest::getAdapter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace StefanoTreeTest\Unit\NestedSet\Adapter;
6
7
use Doctrine\DBAL;
8
use StefanoTree\NestedSet\Adapter\Doctrine2DBAL;
9
use StefanoTree\NestedSet\Options;
10
use StefanoTreeTest\UnitTestCase;
11
12
class Doctrine2DBALAdapterTest extends UnitTestCase
13
{
14
    protected function tearDown()
15
    {
16
        \Mockery::close();
17
    }
18
19
    public function testGetBlankDbSelect()
20
    {
21
        $adapter = $this->getAdapter();
22
23
        $this->assertEquals('SELECT tableName.* FROM tableName',
24
            trim($adapter->getBlankDbSelect()->getSQL()));
25
    }
26
27
    public function testGetDefaultDbSelectMustAlwaysReturnNewInstance()
28
    {
29
        $adapter = $this->getAdapter();
30
        $this->assertNotSame($adapter->getDefaultDbSelect(), $adapter->getDefaultDbSelect());
31
    }
32
33
    public function testSetDefaultDbSelectBuilder()
34
    {
35
        $adapter = $this->getAdapter();
36
37
        $selectBuilder = function () {
38
            return $this->getConnection()
39
                ->createQueryBuilder()
40
                ->select('*')
41
                ->from('someTable', null);
42
        };
43
44
        $adapter->setDbSelectBuilder($selectBuilder);
45
46
        $this->assertEquals($selectBuilder()->getSQL(), $adapter->getDefaultDbSelect()->getSQL());
47
    }
48
49
    /**
50
     * @return Doctrine2DBAL
51
     */
52
    private function getAdapter()
53
    {
54
        $options = new Options(array(
55
            'tableName' => 'tableName',
56
            'idColumnName' => 'id',
57
        ));
58
59
        return new Doctrine2DBAL($options, $this->getConnection());
60
    }
61
62
    /**
63
     * @return \Doctrine\DBAL\Connection
64
     */
65
    private function getConnection()
66
    {
67
        $config = new DBAL\Configuration();
68
69
        $connectionParams = array(
70
            'dbname' => ':memory:',
71
            'driver' => 'pdo_sqlite',
72
        );
73
74
        return  DBAL\DriverManager::getConnection($connectionParams, $config);
75
    }
76
}
77