Completed
Push — develop ( 4ea5a3...a8c617 )
by Bartko
05:56
created

Doctrine2DBALAdapterTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

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

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 StefanoTree\NestedSet\Adapter\Doctrine2DBALAdapter;
5
use StefanoTree\NestedSet\Options;
6
7
class Doctrine2DBALAdapterTest
8
    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...
9
{
10
    protected function tearDown()
11
    {
12
        \Mockery::close();
13
    }
14
15
    public function testGetDefaultDbSelect()
16
    {
17
        $adapter = $this->getAdapter();
18
19
        $this->assertEquals('SELECT * FROM tableName',
20
            trim($adapter->getDefaultDbSelect()->getSQL()));
21
    }
22
23
    public function testGetDefaultDbSelectMustAlwaysReturnNewInstance()
24
    {
25
        $adapter = $this->getAdapter();
26
        $this->assertNotSame($adapter->getDefaultDbSelect(), $adapter->getDefaultDbSelect());
27
    }
28
29
    public function testSetDefaultDbSelect()
30
    {
31
        $adapter = $this->getAdapter();
32
33
        $select = $this->getConnection()
34
                       ->createQueryBuilder()
35
                       ->select('*')
36
                       ->from('someTable', null);
37
38
        $adapter->setDefaultDbSelect($select);
39
40
        $this->assertEquals($select->getSQL(), $adapter->getDefaultDbSelect()->getSQL());
41
    }
42
43
    /**
44
     * @return Doctrine2DBALAdapter
45
     */
46
    private function getAdapter()
47
    {
48
        $options = new Options(array(
49
            'tableName'    => 'tableName',
50
            'idColumnName' => 'id',
51
        ));
52
53
        return new Doctrine2DBALAdapter($options, $this->getConnection());
54
    }
55
56
    /**
57
     * @return \Doctrine\DBAL\Connection
58
     */
59
    private function getConnection()
60
    {
61
        $config = new \Doctrine\DBAL\Configuration();
62
63
        $connectionParams = array(
64
            'dbname' => ':memory:',
65
            'driver' => 'pdo_sqlite',
66
        );
67
68
        return  \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
69
    }
70
}
71