Completed
Push — master ( fb3933...6b2ed6 )
by Jaap
04:25
created

CompoundTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 87
rs 10
c 1
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A testCompoundCannotBeConstructedFromType() 0 4 1
A testCompoundGetType() 0 6 1
A testCompoundGetNotExistingType() 0 4 1
A testCompoundHasType() 0 4 1
A testCompoundHasNotExistingType() 0 4 1
A testCompoundCanBeConstructedAndStringifiedCorrectly() 0 4 1
A testCompoundCanBeIterated() 0 8 2
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-2017 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\Reflection\Types;
14
15
/**
16
 * @coversDefaultClass \phpDocumentor\Reflection\Types\Compound
17
 */
18
class CompoundTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @covers ::__construct
22
     *
23
     * @expectedException \InvalidArgumentException
24
     * @expectedExceptionMessage A compound type can only have other types as elements
25
     */
26
    public function testCompoundCannotBeConstructedFromType()
27
    {
28
        new Compound(['foo']);
0 ignored issues
show
Documentation introduced by
array('foo') is of type array<integer,string,{"0":"string"}>, but the function expects a array<integer,object<php...entor\Reflection\Type>>.

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...
29
    }
30
31
    /**
32
     * @covers ::get
33
     *
34
     * @uses \phpDocumentor\Reflection\Types\Compound::__construct
35
     * @uses \phpDocumentor\Reflection\Types\Compound::has
36
     * @uses \phpDocumentor\Reflection\Types\Integer
37
     */
38
    public function testCompoundGetType()
39
    {
40
        $integer = new Integer();
41
42
        $this->assertSame($integer, (new Compound([$integer]))->get(0));
43
    }
44
45
    /**
46
     * @covers ::get
47
     *
48
     * @uses \phpDocumentor\Reflection\Types\Compound::__construct
49
     * @uses \phpDocumentor\Reflection\Types\Compound::has
50
     */
51
    public function testCompoundGetNotExistingType()
52
    {
53
        $this->assertNull((new Compound([]))->get(0));
54
    }
55
56
    /**
57
     * @covers ::has
58
     *
59
     * @uses \phpDocumentor\Reflection\Types\Compound::__construct
60
     * @uses \phpDocumentor\Reflection\Types\Integer
61
     */
62
    public function testCompoundHasType()
63
    {
64
        $this->assertTrue((new Compound([new Integer()]))->has(0));
65
    }
66
67
    /**
68
     * @covers ::has
69
     *
70
     * @uses \phpDocumentor\Reflection\Types\Compound::__construct
71
     */
72
    public function testCompoundHasNotExistingType()
73
    {
74
        $this->assertFalse((new Compound([]))->has(0));
75
    }
76
77
    /**
78
     * @covers ::__construct
79
     * @covers ::__toString
80
     *
81
     * @uses \phpDocumentor\Reflection\Types\Integer
82
     * @uses \phpDocumentor\Reflection\Types\Boolean
83
     */
84
    public function testCompoundCanBeConstructedAndStringifiedCorrectly()
85
    {
86
        $this->assertSame('int|bool', (string)(new Compound([new Integer(), new Boolean()])));
87
    }
88
89
    /**
90
     * @covers ::getIterator
91
     *
92
     * @uses \phpDocumentor\Reflection\Types\Compound::__construct
93
     * @uses \phpDocumentor\Reflection\Types\Integer
94
     * @uses \phpDocumentor\Reflection\Types\Boolean
95
     */
96
    public function testCompoundCanBeIterated()
97
    {
98
        $types = [new Integer(), new Boolean()];
99
100
        foreach (new Compound($types) as $index => $type) {
101
            $this->assertSame($types[$index], $type);
102
        }
103
    }
104
}
105