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

Doctrine2DBALAdapterTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 1
cbo 8
dl 0
loc 64
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 4 1
A testGetDefaultDbSelect() 0 7 1
A testGetDefaultDbSelectMustAlwaysReturnNewInstance() 0 5 1
A testSetDefaultDbSelect() 0 13 1
A getAdapter() 0 9 1
A getConnection() 0 11 1
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