Skip to content

Commit b16a24b

Browse files
committed
Fix tests
1 parent 8c76be6 commit b16a24b

5 files changed

Lines changed: 45 additions & 29 deletions

File tree

‎tests/PHPStan/Analyser/nsrt/generics.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1410,7 +1410,7 @@ class CarFactoryProcessor {
14101410
*/
14111411
public function process($class): void {
14121412
$car = $class::create();
1413-
assertType(Car::class, $car);
1413+
assertType(T::class, $car); // @template T is unknown in static method
14141414
}
14151415
}
14161416

‎tests/PHPStan/Rules/Generics/MethodSignatureVarianceRuleTest.php‎

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -186,32 +186,8 @@ public function testRule(): void
186186

187187
$this->analyse([__DIR__ . '/data/method-signature-variance-constructor.php'], []);
188188

189-
$this->analyse([__DIR__ . '/data/method-signature-variance-static.php'], [
190-
[
191-
'Template type X is declared as covariant, but occurs in contravariant position in parameter a of method MethodSignatureVariance\StaticMethod\B::a().',
192-
43,
193-
],
194-
[
195-
'Template type X is declared as covariant, but occurs in contravariant position in parameter c of method MethodSignatureVariance\StaticMethod\B::a().',
196-
43,
197-
],
198-
[
199-
'Template type X is declared as covariant, but occurs in contravariant position in return type of method MethodSignatureVariance\StaticMethod\B::c().',
200-
49,
201-
],
202-
[
203-
'Template type X is declared as contravariant, but occurs in covariant position in parameter b of method MethodSignatureVariance\StaticMethod\C::a().',
204-
62,
205-
],
206-
[
207-
'Template type X is declared as contravariant, but occurs in covariant position in return type of method MethodSignatureVariance\StaticMethod\C::b().',
208-
65,
209-
],
210-
[
211-
'Template type X is declared as contravariant, but occurs in covariant position in return type of method MethodSignatureVariance\StaticMethod\C::d().',
212-
71,
213-
],
214-
]);
189+
// class-level @template X is unknown in static methods
190+
$this->analyse([__DIR__ . '/data/method-signature-variance-static.php'], []);
215191
}
216192

217193
public function testBug8880(): void

‎tests/PHPStan/Rules/Methods/CallStaticMethodsRuleTest.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,12 @@ public function testBug6249(): void
541541
// discussion https://github.com/phpstan/phpstan/discussions/6249
542542
$this->checkThisOnly = false;
543543
$this->checkExplicitMixed = true;
544-
$this->analyse([__DIR__ . '/data/bug-6249.php'], []);
544+
$this->analyse([__DIR__ . '/data/bug-6249.php'], [
545+
[
546+
'Parameter #1 $iterable of static method Bug6249N3\Cw<(int|string),mixed>::fromIterable() expects iterable<Bug6249N3\TKey, Bug6249N3\T>, Bug6249N2\Eii given.',
547+
145,
548+
],
549+
]);
545550
}
546551

547552
public function testBug5749(): void

‎tests/PHPStan/Rules/Methods/ReturnTypeRuleTest.php‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,7 +1248,29 @@ public function testBug13043(): void
12481248

12491249
public function testBug12739(): void
12501250
{
1251-
$this->analyse([__DIR__ . '/data/bug-12739.php'], []);
1251+
// @template TScalar is unknown in static methods
1252+
$this->analyse([__DIR__ . '/data/bug-12739.php'], [
1253+
[
1254+
"Method MyInt::getClassIdentify() should return class-string<ScalarType<TScalar>> but returns 'MyInt'.",
1255+
20,
1256+
],
1257+
[
1258+
"Method MyString::getClassIdentify() should return class-string<ScalarType<TScalar>> but returns 'MyString'.",
1259+
29,
1260+
],
1261+
[
1262+
"Method MyLowerString::getClassIdentify() should return class-string<ScalarType<TScalar>> but returns 'MyLowerString'.",
1263+
38,
1264+
],
1265+
[
1266+
"Method MyUpperString::getClassIdentify() should return class-string<ScalarType<TScalar>> but returns 'MyUpperString'.",
1267+
47,
1268+
],
1269+
[
1270+
"Method MyClassString::getClassIdentify() should return class-string<ScalarType<TScalar>> but returns 'MyClassString'.",
1271+
56,
1272+
],
1273+
]);
12521274
}
12531275

12541276
public function testBug12928(): void

‎tests/PHPStan/Rules/Methods/data/bug-6249.php‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,18 @@ public static function fromIterable(iterable $iterable): self
106106
return new self($iterable);
107107
}
108108

109+
/**
110+
* @template UKey of array-key
111+
* @template U
112+
* @param iterable<UKey, U> $iterable
113+
*
114+
* @return self<UKey, U>
115+
*/
116+
public static function fromIterableCorrect(iterable $iterable): self
117+
{
118+
return new self($iterable);
119+
}
120+
109121
public function count(): int
110122
{
111123
if (is_array($this->iterable) || $this->iterable instanceof Countable) {
@@ -131,6 +143,7 @@ class Foo
131143
public function doFoo()
132144
{
133145
\Bug6249N3\Cw::fromIterable(new \Bug6249N2\Eii([]));
146+
\Bug6249N3\Cw::fromIterableCorrect(new \Bug6249N2\Eii([]));
134147
}
135148

136149
}

0 commit comments

Comments
 (0)