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

Descriptor/Type/CollectionDescriptorTest.php (1 issue)

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\Descriptor\Type;
13
14
class CollectionDescriptorTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
15
{
16
    /** @var CollectionDescriptor */
17
    private $fixture;
18
19
    /**
20
     * Initializes the fixture for this test.
21
     */
22
    protected function setUp()
23
    {
24
        $this->fixture = new CollectionDescriptor('array');
0 ignored issues
show
'array' is of type string, but the function expects a object<phpDocumentor\Des...terfaces\TypeInterface>.

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...
25
    }
26
27
    /**
28
     * @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getName
29
     */
30
    public function testRetrieveNameForBaseTypeWithTypeString()
31
    {
32
        $this->assertSame('array', $this->fixture->getName());
33
    }
34
35
    /**
36
     * @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getName
37
     */
38
    public function testRetrieveNameForBaseTypeWithTypeDescriptor()
39
    {
40
        $fixture = new CollectionDescriptor(new UnknownTypeDescriptor('array'));
41
42
        $this->assertSame('array', $fixture->getName());
43
    }
44
45
    /**
46
     * @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getBaseType
47
     */
48
    public function testRetrieveBaseTypeWithTypeStringReturnsNull()
49
    {
50
        $this->assertNull($this->fixture->getBaseType());
51
    }
52
53
    /**
54
     * @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getBaseType
55
     * @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::setBaseType
56
     */
57
    public function testSetAndRetrieveBaseTypeWithTypeDescriptor()
58
    {
59
        $expected = new UnknownTypeDescriptor('array');
60
        $this->fixture->setBaseType($expected);
61
62
        $this->assertSame($expected, $this->fixture->getBaseType());
63
    }
64
65
    /**
66
     * @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getTypes
67
     * @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::setTypes
68
     */
69
    public function testSetAndRetrieveTypes()
70
    {
71
        $expected = new UnknownTypeDescriptor('array');
72
        $this->fixture->setTypes([$expected]);
73
74
        $this->assertSame([$expected], $this->fixture->getTypes());
75
    }
76
77
    /**
78
     * @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::getKeyTypes
79
     * @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::setKeyTypes
80
     */
81
    public function testSetAndRetrieveKeyTypes()
82
    {
83
        $expected = new UnknownTypeDescriptor('string');
84
        $this->fixture->setKeyTypes([$expected]);
85
86
        $this->assertSame([$expected], $this->fixture->getKeyTypes());
87
    }
88
89
    /**
90
     * @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::__toString
91
     */
92
    public function testRetrieveCollectionNotationFromObject()
93
    {
94
        $this->fixture->setKeyTypes([new StringDescriptor()]);
95
        $this->fixture->setTypes([new FloatDescriptor(), new IntegerDescriptor()]);
96
97
        $this->assertSame('array<string,float|integer>', (string) $this->fixture);
98
    }
99
100
    /**
101
     * @covers phpDocumentor\Descriptor\Type\CollectionDescriptor::__toString
102
     */
103
    public function testRetrieveCollectionNotationFromObjectWithoutKeys()
104
    {
105
        $this->fixture->setTypes([new FloatDescriptor(), new IntegerDescriptor()]);
106
107
        $this->assertSame('array<float|integer>', (string) $this->fixture);
108
    }
109
}
110