Passed
Pull Request — main (#4)
by Peter
06:14 queued 03:00
created

CollectionTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A allInstanceOfProvider() 0 8 1
A testAllInstanceOf() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Framework\Html\Helper;
6
7
use AbterPhp\Framework\Html\INode;
8
use AbterPhp\Framework\Html\Node;
9
use AbterPhp\Framework\Html\Tag;
1 ignored issue
show
Bug introduced by
This use statement conflicts with another class in this namespace, AbterPhp\Framework\Html\Helper\Tag. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
10
use PHPUnit\Framework\TestCase;
11
12
class CollectionTest extends TestCase
13
{
14
    /**
15
     * @return array
16
     */
17
    public function allInstanceOfProvider(): array
18
    {
19
        return [
20
            'empty'               => [[], Node::class, true],
21
            'one-node-node'       => [[new Node()], Node::class, true],
22
            'one-node-inode'      => [[new Node()], INode::class, true],
23
            'first-node-not-tag'  => [[new Node()], INode::class, true],
24
            'second-node-not-tag' => [[new Tag(), new Node()], Tag::class, false],
25
        ];
26
    }
27
28
    /**
29
     * @dataProvider allInstanceOfProvider
30
     *
31
     * @param array  $items
32
     * @param string $className
33
     * @param bool   $expectedResult
34
     */
35
    public function testAllInstanceOf(array $items, string $className, bool $expectedResult): void
36
    {
37
        $actualResult = Collection::allInstanceOf($items, $className);
38
39
        $this->assertEquals($expectedResult, $actualResult);
40
    }
41
}
42