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 |
|
|
|
|
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
|
|
|
|