|
| 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']); |
| 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 | +} |
0 commit comments