Completed
Push — develop ( 8f34f3...3bf98d )
by Jaap
13:27 queued 03:31
created

FolderTest::itCanAddAdditionalPathsInThisFolder()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2016 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\DomainModel\Renderer\Asset;
14
15
use phpDocumentor\DomainModel\Path;
16
17
/**
18
 * @coversDefaultClass phpDocumentor\DomainModel\Renderer\Asset\Folder
19
 * @covers ::<private>
20
 */
21
final class FolderTest extends \PHPUnit_Framework_TestCase
22
{
23
    /**
24
     * @test
25
     * @coversNothing
26
     */
27
    public function itShouldBeACollection()
28
    {
29
        $folder = new Folder(new Path('images'), []);
30
        $this->assertInstanceOf(\ArrayObject::class, $folder);
31
    }
32
33
    /**
34
     * @test
35
     * @covers ::__construct
36
     * @covers ::path
37
     */
38
    public function itShouldExposeThePathForThisFolder()
39
    {
40
        $path = new Path('images');
41
42
        $folder = new Folder($path, []);
43
44
        $this->assertSame($path, $folder->path());
45
    }
46
47
    /**
48
     * @test
49
     * @covers ::offsetSet
50
     */
51
    public function itCanAddAdditionalPathsInThisFolder()
52
    {
53
        $folder = new Folder(new Path('images'), []);
54
        $path = new Path('cats.png');
55
56
        $folder[] = $path;
57
58
        $this->assertSame($path, $folder[0]);
59
    }
60
61
    /**
62
     * @test
63
     * @covers ::__construct
64
     */
65
    public function itShouldErrorWhenTheConstructorReceivesSomethingOtherThanAPathObject()
66
    {
67
        $this->setExpectedException(\InvalidArgumentException::class);
68
69
        new Folder(new Path('images'), [new \stdClass()]);
0 ignored issues
show
Documentation introduced by
array(new \stdClass()) is of type array<integer,object<std...0":"object<stdClass>"}>, but the function expects a array<integer,object<php...ntor\DomainModel\Path>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
    }
71
72
    /**
73
     * @test
74
     * @covers ::offsetSet
75
     */
76
    public function itShouldErrorWhenTheSomethingOtherThanAPathObjectIsAdded()
77
    {
78
        $this->setExpectedException(\InvalidArgumentException::class);
79
80
        $folder = new Folder(new Path('images'), []);
81
82
        $folder[] = new \stdClass();
83
    }
84
}
85