|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Type; |
| 4 | + |
| 5 | +use PHPStan\Testing\PHPStanTestCase; |
| 6 | +use PHPStan\Type\Accessory\AccessoryLowercaseStringType; |
| 7 | +use PHPStan\Type\Accessory\AccessoryNonFalsyStringType; |
| 8 | +use PHPStan\Type\Generic\GenericObjectType; |
| 9 | +use PHPStan\Type\Generic\TemplateTypeVariance; |
| 10 | + |
| 11 | +class VerbosityLevelTest extends PHPStanTestCase |
| 12 | +{ |
| 13 | + |
| 14 | + public function dataGetRecommendedLevelByType(): iterable |
| 15 | + { |
| 16 | + yield [ |
| 17 | + new BooleanType(), |
| 18 | + new IntersectionType([new StringType(), new AccessoryLowercaseStringType()]), |
| 19 | + VerbosityLevel::typeOnly(), |
| 20 | + ]; |
| 21 | + yield [ |
| 22 | + new IntersectionType([new StringType(), new AccessoryNonFalsyStringType()]), |
| 23 | + new IntersectionType([new StringType(), new AccessoryLowercaseStringType()]), |
| 24 | + VerbosityLevel::value(), |
| 25 | + ]; |
| 26 | + yield [ |
| 27 | + new GenericObjectType( |
| 28 | + 'ArrayAccess', |
| 29 | + [ |
| 30 | + new IntegerType(), |
| 31 | + new IntersectionType([new StringType(), new AccessoryNonFalsyStringType()]), |
| 32 | + ], |
| 33 | + null, |
| 34 | + null, |
| 35 | + [TemplateTypeVariance::createInvariant(), TemplateTypeVariance::createInvariant()], |
| 36 | + ), |
| 37 | + new GenericObjectType( |
| 38 | + 'ArrayAccess', |
| 39 | + [ |
| 40 | + new IntegerType(), |
| 41 | + new IntersectionType([new StringType(), new AccessoryLowercaseStringType()]), |
| 42 | + ], |
| 43 | + null, |
| 44 | + null, |
| 45 | + [TemplateTypeVariance::createInvariant(), TemplateTypeVariance::createInvariant()], |
| 46 | + ), |
| 47 | + VerbosityLevel::precise(), |
| 48 | + ]; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @dataProvider dataGetRecommendedLevelByType |
| 53 | + */ |
| 54 | + public function testGetRecommendedLevelByType(Type $acceptingType, ?Type $acceptedType, VerbosityLevel $expected): void |
| 55 | + { |
| 56 | + $level = VerbosityLevel::getRecommendedLevelByType($acceptingType, $acceptedType); |
| 57 | + |
| 58 | + $this->assertSame($expected->getLevelValue(), $level->getLevelValue()); |
| 59 | + } |
| 60 | + |
| 61 | +} |
0 commit comments