|
13 | 13 | use PHPStan\Type\MixedType;
|
14 | 14 | use PHPStan\Type\StringType;
|
15 | 15 | use PHPStan\Type\Type;
|
| 16 | +use PHPStan\Type\TypeCombinator; |
16 | 17 | use PHPStan\Type\VerbosityLevel;
|
17 | 18 |
|
18 | 19 | class ConstantArrayTypeTest extends \PHPStan\Testing\TestCase
|
@@ -109,15 +110,75 @@ public function dataAccepts(): iterable
|
109 | 110 | new ConstantArrayType([new ConstantStringType('foo')], [new ConstantStringType('bar')]),
|
110 | 111 | TrinaryLogic::createYes(),
|
111 | 112 | ];
|
| 113 | + |
| 114 | + yield [ |
| 115 | + TypeCombinator::union( |
| 116 | + new ConstantArrayType([ |
| 117 | + new ConstantStringType('name'), |
| 118 | + ], [ |
| 119 | + new StringType(), |
| 120 | + ]), |
| 121 | + new ConstantArrayType([ |
| 122 | + new ConstantStringType('name'), |
| 123 | + new ConstantStringType('color'), |
| 124 | + ], [ |
| 125 | + new StringType(), |
| 126 | + new StringType(), |
| 127 | + ]) |
| 128 | + ), |
| 129 | + new ConstantArrayType([ |
| 130 | + new ConstantStringType('name'), |
| 131 | + new ConstantStringType('color'), |
| 132 | + new ConstantStringType('year'), |
| 133 | + ], [ |
| 134 | + new StringType(), |
| 135 | + new StringType(), |
| 136 | + new IntegerType(), |
| 137 | + ]), |
| 138 | + TrinaryLogic::createYes(), |
| 139 | + ]; |
| 140 | + |
| 141 | + yield [ |
| 142 | + new ConstantArrayType([ |
| 143 | + new ConstantStringType('name'), |
| 144 | + new ConstantStringType('color'), |
| 145 | + new ConstantStringType('year'), |
| 146 | + ], [ |
| 147 | + new StringType(), |
| 148 | + new StringType(), |
| 149 | + new IntegerType(), |
| 150 | + ]), |
| 151 | + new MixedType(), |
| 152 | + TrinaryLogic::createYes(), |
| 153 | + ]; |
| 154 | + |
| 155 | + yield [ |
| 156 | + TypeCombinator::union( |
| 157 | + new ConstantArrayType([], []), |
| 158 | + new ConstantArrayType([ |
| 159 | + new ConstantStringType('name'), |
| 160 | + new ConstantStringType('color'), |
| 161 | + ], [ |
| 162 | + new StringType(), |
| 163 | + new StringType(), |
| 164 | + ]) |
| 165 | + ), |
| 166 | + new ConstantArrayType([ |
| 167 | + new ConstantStringType('surname'), |
| 168 | + ], [ |
| 169 | + new StringType(), |
| 170 | + ]), |
| 171 | + TrinaryLogic::createNo(), |
| 172 | + ]; |
112 | 173 | }
|
113 | 174 |
|
114 | 175 | /**
|
115 | 176 | * @dataProvider dataAccepts
|
116 |
| - * @param ConstantArrayType $type |
| 177 | + * @param Type $type |
117 | 178 | * @param Type $otherType
|
118 | 179 | * @param TrinaryLogic $expectedResult
|
119 | 180 | */
|
120 |
| - public function testAccepts(ConstantArrayType $type, Type $otherType, TrinaryLogic $expectedResult): void |
| 181 | + public function testAccepts(Type $type, Type $otherType, TrinaryLogic $expectedResult): void |
121 | 182 | {
|
122 | 183 | $actualResult = $type->accepts($otherType, true);
|
123 | 184 | $this->assertSame(
|
|
0 commit comments