Completed
Push — develop ( 0a2cdf...062ac6 )
by Bartko
03:22
created

Doctrine2DBALAdapterTest::testSetDefaultDbSelect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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