|
1
|
|
|
<?php |
|
2
|
|
|
namespace StefanoTreeTest\Unit; |
|
3
|
|
|
|
|
4
|
|
|
use StefanoTree\NestedSet; |
|
5
|
|
|
|
|
6
|
|
|
class NestedSetTest |
|
7
|
|
|
extends \PHPUnit_Framework_TestCase |
|
|
|
|
|
|
8
|
|
|
{ |
|
9
|
|
|
public function factoryDataProvider() |
|
10
|
|
|
{ |
|
11
|
|
|
return array( |
|
12
|
|
|
array( |
|
13
|
|
|
'\Zend\Db\Adapter\Adapter', |
|
14
|
|
|
'\StefanoTree\NestedSet\Adapter\Zend2', |
|
15
|
|
|
), |
|
16
|
|
|
array( |
|
17
|
|
|
'\Doctrine\DBAL\Connection', |
|
18
|
|
|
'\StefanoTree\NestedSet\Adapter\Doctrine2DBAL', |
|
19
|
|
|
), |
|
20
|
|
|
// array( // todo |
|
|
|
|
|
|
21
|
|
|
// '\Zend_Db_Adapter_Abstract', |
|
22
|
|
|
// '\StefanoTree\NestedSet\Adapter\Zend1DbAdapter', |
|
23
|
|
|
// ), |
|
24
|
|
|
); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @dataProvider factoryDataProvider |
|
29
|
|
|
*/ |
|
30
|
|
|
public function testFactoryMethod($dbAdapterClass, $expectedAdapterClass) |
|
31
|
|
|
{ |
|
32
|
|
|
$optionsStub = \Mockery::mock('\StefanoTree\NestedSet\Options'); |
|
33
|
|
|
$dbAdapterStub = \Mockery::mock($dbAdapterClass); |
|
34
|
|
|
|
|
35
|
|
|
$tree = NestedSet::factory($optionsStub, $dbAdapterStub); |
|
36
|
|
|
$adapter = $tree->getAdapter(); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertInstanceOf($expectedAdapterClass, $adapter); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testThrowExceptionIfYouDbAdapterIsNotSupporter() |
|
42
|
|
|
{ |
|
43
|
|
|
$optionsStub = \Mockery::mock('\StefanoTree\NestedSet\Options'); |
|
44
|
|
|
$dbAdapter = new \DateTime(); |
|
45
|
|
|
|
|
46
|
|
|
$this->setExpectedException('\StefanoTree\Exception\InvalidArgumentException', |
|
|
|
|
|
|
47
|
|
|
'Db adapter "DateTime" is not supported'); |
|
48
|
|
|
|
|
49
|
|
|
NestedSet::factory($optionsStub, $dbAdapter); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|