Completed
Push — develop ( 8eb671...133594 )
by Mike
19:30 queued 09:24
created

Metadata/TableOfContents/BaseEntryTest.php (2 issues)

mismatching argument types.

Documentation Minor

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * phpDocumentor
4
 *
5
 * PHP Version 5.3
6
 *
7
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
8
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
9
 * @link      http://phpdoc.org
10
 */
11
12
namespace phpDocumentor\Plugin\Scrybe\Converter\Metadata\TableOfContents;
13
14
use Mockery as m;
15
use phpDocumentor\Plugin\Scrybe\Converter\Metadata\TableOfContents;
16
17
/**
18
 * Test class for the BaseEntry object.
19
 */
20
class BaseEntryTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
21
{
22
    /**
23
     * @var BaseEntry
24
     */
25
    protected $object;
26
27
    /**
28
     * Sets up the fixture, for example, opens a network connection.
29
     * This method is called before a test is executed.
30
     */
31
    protected function setUp()
32
    {
33
        $this->object = m::mock('phpDocumentor\Plugin\Scrybe\Converter\Metadata\TableOfContents\BaseEntry[]');
34
    }
35
36
    /**
37
     * @covers phpDocumentor\Plugin\Scrybe\Converter\Metadata\TableOfContents\BaseEntry::getParent
38
     * @covers phpDocumentor\Plugin\Scrybe\Converter\Metadata\TableOfContents\BaseEntry::setParent
39
     */
40
    public function testAddingAParentEntry()
41
    {
42
        $this->assertNull($this->object->getParent());
43
44
        $heading = new Heading();
45
        $this->object->setParent($heading);
46
47
        $this->assertSame($heading, $this->object->getParent());
48
    }
49
50
    /**
51
     * @expectedException \InvalidArgumentException
52
     *
53
     * @covers phpDocumentor\Plugin\Scrybe\Converter\Metadata\TableOfContents\BaseEntry::setParent
54
     */
55
    public function testAddingAnInvalidParentEntry()
56
    {
57
        $toc = new TableOfContents();
58
        $this->object->setParent($toc);
0 ignored issues
show
$toc is of type object<phpDocumentor\Plu...tadata\TableOfContents>, but the function expects a object<phpDocumentor\Plu...ontents\BaseEntry>|null.

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...
59
    }
60
61
    /**
62
     * @covers phpDocumentor\Plugin\Scrybe\Converter\Metadata\TableOfContents\BaseEntry::getChildren
63
     * @covers phpDocumentor\Plugin\Scrybe\Converter\Metadata\TableOfContents\BaseEntry::addChild
64
     */
65
    public function testAddingChildren()
66
    {
67
        $this->assertEmpty($this->object->getChildren());
68
69
        $heading = new Heading();
70
        $this->object->addChild($heading);
0 ignored issues
show
$heading is of type object<phpDocumentor\Plu...ableOfContents\Heading>, but the function expects a object<self>.

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...
71
72
        $this->assertCount(1, $this->object->getChildren());
73
        $this->assertSame([$heading], $this->object->getChildren());
74
    }
75
76
    /**
77
     * @covers phpDocumentor\Plugin\Scrybe\Converter\Metadata\TableOfContents\BaseEntry::getName
78
     * @covers phpDocumentor\Plugin\Scrybe\Converter\Metadata\TableOfContents\BaseEntry::setName
79
     */
80
    public function testSettingAName()
81
    {
82
        $this->assertSame('', $this->object->getName());
83
84
        $this->object->setName('name');
85
86
        $this->assertSame('name', $this->object->getName());
87
    }
88
}
89