Completed
Push — develop ( 32afc4...f78f16 )
by Bartko
03:00
created

NestedSetTest::testFactoryMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
namespace StefanoTreeTest\Unit;
3
4
use StefanoTree\NestedSet;
5
6
class NestedSetTest
7
    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...
8
{
9
    public function factoryDataProvider()
10
    {
11
        return array(
12
            array(
13
                '\StefanoDb\Adapter\Adapter',
14
                '\StefanoTree\NestedSet\Adapter\Zend2DbAdapter',
15
            ),
16
            array(
17
                '\Doctrine\DBAL\Connection',
18
                '\StefanoTree\NestedSet\Adapter\Doctrine2DBALAdapter',
19
            ),
20
            array(
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',
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
47
            'Db adapter "DateTime" is not supported');
48
49
        NestedSet::factory($optionsStub, $dbAdapter);
50
    }
51
}
52