Issues (34)

tests/StefanoTreeTest/Unit/NestedSetTest.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace StefanoTreeTest\Unit;
6
7
use StefanoTree\NestedSet;
8
use StefanoTreeTest\UnitTestCase;
9
10
/**
11
 * @internal
12
 */
13
class NestedSetTest extends UnitTestCase
14
{
15
    private $options = array(
16
        'idColumnName' => 'id',
17
        'tableName' => 'table',
18
    );
19
20
    public function dataProvider()
21
    {
22
        return array(
23
            array(
24
                \PDO::class,
25
                NestedSet\Adapter\Pdo::class,
26
            ),
27
            array(
28
                \Laminas\Db\Adapter\Adapter::class,
29
                NestedSet\Adapter\LaminasDb::class,
30
            ),
31
            array(
32
                \Doctrine\DBAL\Connection::class,
33
                NestedSet\Adapter\Doctrine2DBAL::class,
34
            ),
35
            array(
36
                \Zend_Db_Adapter_Abstract::class,
37
                NestedSet\Adapter\Zend1::class,
38
            ),
39
        );
40
    }
41
42
    /**
43
     * @dataProvider dataProvider
44
     *
45
     * @param mixed $dbAdapterClass
46
     * @param mixed $expectedAdapterClass
47
     */
48
    public function testConstructorMethodWithOptionAsObject($dbAdapterClass, $expectedAdapterClass)
49
    {
50
        $dbAdapterStub = \Mockery::mock($dbAdapterClass);
51
        $options = new \StefanoTree\NestedSet\Options($this->options);
52
53
        $tree = new NestedSet($options, $dbAdapterStub);
54
        $adapter = $tree->getManipulator()->getAdapter()->getAdapter();
0 ignored issues
show
The method getAdapter() does not exist on StefanoTree\NestedSet\Ma...or\ManipulatorInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to StefanoTree\NestedSet\Ma...or\ManipulatorInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
        $adapter = $tree->getManipulator()->/** @scrutinizer ignore-call */ getAdapter()->getAdapter();
Loading history...
55
56
        $this->assertInstanceOf($expectedAdapterClass, $adapter);
57
    }
58
59
    /**
60
     * @dataProvider dataProvider
61
     *
62
     * @param mixed $dbAdapterClass
63
     * @param mixed $expectedAdapterClass
64
     */
65
    public function testConstructorMethodWithOptionAsArray($dbAdapterClass, $expectedAdapterClass)
66
    {
67
        $dbAdapterStub = \Mockery::mock($dbAdapterClass);
68
        $options = $this->options;
69
70
        $tree = new NestedSet($options, $dbAdapterStub);
71
        $adapter = $tree->getManipulator()->getAdapter()->getAdapter();
72
73
        $this->assertInstanceOf($expectedAdapterClass, $adapter);
74
    }
75
76
    public function testThrowExceptionIfYourDbAdapterIsNotSupporter()
77
    {
78
        $options = new \StefanoTree\NestedSet\Options($this->options);
79
        $dbAdapter = new \DateTime();
80
81
        $this->expectException(\StefanoTree\Exception\InvalidArgumentException::class);
82
        $this->expectExceptionMessage('Db adapter "DateTime" is not supported');
83
84
        new NestedSet($options, $dbAdapter);
85
    }
86
}
87