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