Skip to content

Commit 0476903

Browse files
committed
Moved test
1 parent a7fed03 commit 0476903

File tree

2 files changed

+129
-118
lines changed

2 files changed

+129
-118
lines changed

tests/PHPStan/Analyser/AnalyserIntegrationTest.php

Lines changed: 0 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,14 @@
55
use Bug4288\MyClass;
66
use Bug4713\Service;
77
use ExtendingKnownClassWithCheck\Foo;
8-
use PhpParser\Node\Expr;
9-
use PhpParser\Node\Scalar\LNumber;
10-
use PhpParser\Node\Scalar\String_;
118
use PHPStan\File\FileHelper;
129
use PHPStan\Reflection\InitializerExprContext;
1310
use PHPStan\Reflection\InitializerExprTypeResolver;
1411
use PHPStan\Reflection\ParametersAcceptorSelector;
1512
use PHPStan\Reflection\SignatureMap\SignatureMapProvider;
16-
use PHPStan\ShouldNotHappenException;
1713
use PHPStan\Testing\PHPStanTestCase;
1814
use PHPStan\Type\Constant\ConstantIntegerType;
1915
use PHPStan\Type\Constant\ConstantStringType;
20-
use PHPStan\Type\NeverType;
21-
use PHPStan\Type\Type;
2216
use function extension_loaded;
2317
use function restore_error_handler;
2418
use function sprintf;
@@ -1081,118 +1075,6 @@ public function testBug8503(): void
10811075
$this->assertNoErrors($errors);
10821076
}
10831077

1084-
/**
1085-
* @dataProvider dataExplicitNever
1086-
*
1087-
* @param class-string $resultClass
1088-
* @param callable(Expr): Type $callback
1089-
*/
1090-
public function testExplicitNever(Expr $left, Expr $right, callable $callback, string $resultClass, ?bool $resultIsExplicit = null): void
1091-
{
1092-
$initializerExprTypeResolver = self::getContainer()->getByType(InitializerExprTypeResolver::class);
1093-
1094-
$result = $initializerExprTypeResolver->getPlusType(
1095-
$left,
1096-
$right,
1097-
$callback,
1098-
);
1099-
$this->assertInstanceOf($resultClass, $result);
1100-
1101-
if (!($result instanceof NeverType)) {
1102-
return;
1103-
}
1104-
1105-
if ($resultIsExplicit === null) {
1106-
throw new ShouldNotHappenException();
1107-
}
1108-
$this->assertSame($resultIsExplicit, $result->isExplicit());
1109-
}
1110-
1111-
public function dataExplicitNever(): iterable
1112-
{
1113-
yield [
1114-
new LNumber(1),
1115-
new String_('foo'),
1116-
static function (Expr $expr): Type {
1117-
if ($expr instanceof LNumber) {
1118-
return new ConstantIntegerType(1);
1119-
}
1120-
return new NeverType(true);
1121-
},
1122-
NeverType::class,
1123-
true,
1124-
];
1125-
yield [
1126-
new String_('foo'),
1127-
new LNumber(1),
1128-
static function (Expr $expr): Type {
1129-
if ($expr instanceof LNumber) {
1130-
return new ConstantIntegerType(1);
1131-
}
1132-
return new NeverType(true);
1133-
},
1134-
NeverType::class,
1135-
true,
1136-
];
1137-
1138-
yield [
1139-
new LNumber(1),
1140-
new String_('foo'),
1141-
static function (Expr $expr): Type {
1142-
if ($expr instanceof LNumber) {
1143-
return new ConstantIntegerType(1);
1144-
}
1145-
return new NeverType(false);
1146-
},
1147-
NeverType::class,
1148-
false,
1149-
];
1150-
yield [
1151-
new String_('foo'),
1152-
new LNumber(1),
1153-
static function (Expr $expr): Type {
1154-
if ($expr instanceof LNumber) {
1155-
return new ConstantIntegerType(1);
1156-
}
1157-
return new NeverType(false);
1158-
},
1159-
NeverType::class,
1160-
false,
1161-
];
1162-
1163-
yield [
1164-
new String_('foo'),
1165-
new LNumber(1),
1166-
static function (Expr $expr): Type {
1167-
if ($expr instanceof LNumber) {
1168-
return new NeverType(true);
1169-
}
1170-
return new NeverType(false);
1171-
},
1172-
NeverType::class,
1173-
true,
1174-
];
1175-
yield [
1176-
new LNumber(1),
1177-
new String_('foo'),
1178-
static function (Expr $expr): Type {
1179-
if ($expr instanceof LNumber) {
1180-
return new NeverType(true);
1181-
}
1182-
return new NeverType(false);
1183-
},
1184-
NeverType::class,
1185-
true,
1186-
];
1187-
1188-
yield [
1189-
new LNumber(1),
1190-
new LNumber(1),
1191-
static fn (Expr $expr): Type => new ConstantIntegerType(1),
1192-
ConstantIntegerType::class,
1193-
];
1194-
}
1195-
11961078
/**
11971079
* @param string[]|null $allAnalysedFiles
11981080
* @return Error[]
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Reflection;
4+
5+
use PhpParser\Node\Expr;
6+
use PhpParser\Node\Scalar\LNumber;
7+
use PhpParser\Node\Scalar\String_;
8+
use PHPStan\ShouldNotHappenException;
9+
use PHPStan\Testing\PHPStanTestCase;
10+
use PHPStan\Type\Constant\ConstantIntegerType;
11+
use PHPStan\Type\NeverType;
12+
use PHPStan\Type\Type;
13+
14+
class InitializerExprTypeResolverTest extends PHPStanTestCase
15+
{
16+
17+
public function dataExplicitNever(): iterable
18+
{
19+
yield [
20+
new LNumber(1),
21+
new String_('foo'),
22+
static function (Expr $expr): Type {
23+
if ($expr instanceof LNumber) {
24+
return new ConstantIntegerType(1);
25+
}
26+
return new NeverType(true);
27+
},
28+
NeverType::class,
29+
true,
30+
];
31+
yield [
32+
new String_('foo'),
33+
new LNumber(1),
34+
static function (Expr $expr): Type {
35+
if ($expr instanceof LNumber) {
36+
return new ConstantIntegerType(1);
37+
}
38+
return new NeverType(true);
39+
},
40+
NeverType::class,
41+
true,
42+
];
43+
44+
yield [
45+
new LNumber(1),
46+
new String_('foo'),
47+
static function (Expr $expr): Type {
48+
if ($expr instanceof LNumber) {
49+
return new ConstantIntegerType(1);
50+
}
51+
return new NeverType(false);
52+
},
53+
NeverType::class,
54+
false,
55+
];
56+
yield [
57+
new String_('foo'),
58+
new LNumber(1),
59+
static function (Expr $expr): Type {
60+
if ($expr instanceof LNumber) {
61+
return new ConstantIntegerType(1);
62+
}
63+
return new NeverType(false);
64+
},
65+
NeverType::class,
66+
false,
67+
];
68+
69+
yield [
70+
new String_('foo'),
71+
new LNumber(1),
72+
static function (Expr $expr): Type {
73+
if ($expr instanceof LNumber) {
74+
return new NeverType(true);
75+
}
76+
return new NeverType(false);
77+
},
78+
NeverType::class,
79+
true,
80+
];
81+
yield [
82+
new LNumber(1),
83+
new String_('foo'),
84+
static function (Expr $expr): Type {
85+
if ($expr instanceof LNumber) {
86+
return new NeverType(true);
87+
}
88+
return new NeverType(false);
89+
},
90+
NeverType::class,
91+
true,
92+
];
93+
94+
yield [
95+
new LNumber(1),
96+
new LNumber(1),
97+
static fn (Expr $expr): Type => new ConstantIntegerType(1),
98+
ConstantIntegerType::class,
99+
];
100+
}
101+
102+
/**
103+
* @dataProvider dataExplicitNever
104+
*
105+
* @param class-string $resultClass
106+
* @param callable(Expr): Type $callback
107+
*/
108+
public function testExplicitNever(Expr $left, Expr $right, callable $callback, string $resultClass, ?bool $resultIsExplicit = null): void
109+
{
110+
$initializerExprTypeResolver = self::getContainer()->getByType(InitializerExprTypeResolver::class);
111+
112+
$result = $initializerExprTypeResolver->getPlusType(
113+
$left,
114+
$right,
115+
$callback,
116+
);
117+
$this->assertInstanceOf($resultClass, $result);
118+
119+
if (!($result instanceof NeverType)) {
120+
return;
121+
}
122+
123+
if ($resultIsExplicit === null) {
124+
throw new ShouldNotHappenException();
125+
}
126+
$this->assertSame($resultIsExplicit, $result->isExplicit());
127+
}
128+
129+
}

0 commit comments

Comments
 (0)