Skip to content

Commit

Permalink
Fix tests for PHPStan 1.12.6
Browse files Browse the repository at this point in the history
Co-authored-by: Ondřej Mirtes <ondrej@mirtes.cz>
Co-authored-by: Markus Staab <maggus.staab@googlemail.com>
  • Loading branch information
3 people authored Oct 7, 2024
1 parent 0d88669 commit de811c7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"require": {
"php": "^7.2 || ^8.0",
"phpstan/phpstan": "^1.12"
"phpstan/phpstan": "^1.12.6"
},
"conflict": {
"doctrine/collections": "<1.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPStan\Php\PhpVersion;
use PHPStan\Testing\PHPStanTestCase;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\Accessory\AccessoryLowercaseStringType;
use PHPStan\Type\Accessory\AccessoryNumericStringType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
Expand Down Expand Up @@ -308,12 +309,17 @@ private static function list(Type $values): Type
return AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), $values));
}

private static function numericString(): Type
private static function numericString(bool $lowercase = false): Type
{
return new IntersectionType([
$types = [
new StringType(),
new AccessoryNumericStringType(),
]);
];
if ($lowercase) {
$types[] = new AccessoryLowercaseStringType();
}

return new IntersectionType($types);
}

/**
Expand Down
18 changes: 12 additions & 6 deletions tests/Type/Doctrine/Query/QueryResultTypeWalkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPStan\Php\PhpVersion;
use PHPStan\Testing\PHPStanTestCase;
use PHPStan\Type\Accessory\AccessoryArrayListType;
use PHPStan\Type\Accessory\AccessoryLowercaseStringType;
use PHPStan\Type\Accessory\AccessoryNumericStringType;
use PHPStan\Type\ArrayType;
use PHPStan\Type\Constant\ConstantArrayTypeBuilder;
Expand Down Expand Up @@ -1474,7 +1475,7 @@ public function getTestData(): iterable
$this->constantArray([
[new ConstantStringType('minusInt'), $this->stringifies() ? new ConstantStringType('-1') : new ConstantIntegerType(-1)],
[new ConstantStringType('minusFloat'), $this->stringifies() ? $this->numericString() : new ConstantFloatType(-0.1)],
[new ConstantStringType('minusIntRange'), $this->stringifies() ? $this->numericString() : IntegerRangeType::fromInterval(null, 0)],
[new ConstantStringType('minusIntRange'), $this->stringifies() ? $this->numericString(true) : IntegerRangeType::fromInterval(null, 0)],
]),
'
SELECT -1 as minusInt,
Expand Down Expand Up @@ -1622,12 +1623,17 @@ private function constantArray(array $elements): Type
return $builder->getArray();
}

private function numericString(): Type
private function numericString(bool $lowercase = false): Type
{
return new IntersectionType([
$types = [
new StringType(),
new AccessoryNumericStringType(),
]);
];
if ($lowercase) {
$types[] = new AccessoryLowercaseStringType();
}

return new IntersectionType($types);
}

private function uint(): Type
Expand Down Expand Up @@ -1673,14 +1679,14 @@ private function stringifies(): bool
private function intOrStringified(): Type
{
return $this->stringifies()
? $this->numericString()
? $this->numericString(true)
: new IntegerType();
}

private function uintOrStringified(): Type
{
return $this->stringifies()
? $this->numericString()
? $this->numericString(true)
: $this->uint();
}

Expand Down

0 comments on commit de811c7

Please sign in to comment.