Skip to content

Commit ed8e5f1

Browse files
committed
rework test
1 parent dc8a226 commit ed8e5f1

File tree

8 files changed

+69
-78
lines changed

8 files changed

+69
-78
lines changed

.github/workflows/e2e-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ jobs:
255255
echo "$OUTPUT"
256256
../bashunit -a contains 'Child process error (exit code 255): PHP Fatal error' "$OUTPUT"
257257
../bashunit -a contains 'Result is incomplete because of severe errors.' "$OUTPUT"
258+
- script: |
259+
cd e2e/bug-11857
260+
composer install
261+
../../bin/phpstan
258262
259263
steps:
260264
- name: "Checkout"

e2e/bug-11857/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor

e2e/bug-11857/composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"autoload-dev": {
3+
"classmap": ["src/"]
4+
}
5+
}

e2e/bug-11857/composer.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/PHPStan/Analyser/bug-11857.neon renamed to e2e/bug-11857/phpstan.neon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
parameters:
2+
level: 8
3+
paths:
4+
- src
5+
16
services:
27
-
38
class: Bug11857\RelationDynamicMethodReturnTypeExtension

e2e/bug-11857/src/extension.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Bug11857;
4+
5+
use PHPStan\Analyser\Scope;
6+
use PHPStan\Reflection\MethodReflection;
7+
use PHPStan\Type\DynamicMethodReturnTypeExtension;
8+
use PHPStan\Type\Generic\GenericObjectType;
9+
use PHPStan\Type\ObjectType;
10+
use PHPStan\Type\Type;
11+
use PhpParser\Node\Expr\MethodCall;
12+
13+
class RelationDynamicMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension
14+
{
15+
public function getClass(): string
16+
{
17+
return Model::class;
18+
}
19+
20+
public function isMethodSupported(MethodReflection $methodReflection): bool
21+
{
22+
return $methodReflection->getName() === 'belongsTo';
23+
}
24+
25+
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type {
26+
$returnType = $methodReflection->getVariants()[0]->getReturnType();
27+
$argType = $scope->getType($methodCall->getArgs()[0]->value);
28+
$modelClass = $argType->getClassStringObjectType()->getObjectClassNames()[0];
29+
30+
return new GenericObjectType($returnType->getObjectClassNames()[0], [
31+
new ObjectType($modelClass),
32+
$scope->getType($methodCall->var),
33+
]);
34+
}
35+
}
36+

tests/PHPStan/Analyser/data/bug-11857.php renamed to e2e/bug-11857/src/test.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,8 @@
22

33
namespace Bug11857;
44

5-
use PHPStan\Analyser\Scope;
6-
use PHPStan\Reflection\MethodReflection;
7-
use PHPStan\Type\DynamicMethodReturnTypeExtension;
8-
use PHPStan\Type\Generic\GenericObjectType;
9-
use PHPStan\Type\ObjectType;
10-
use PHPStan\Type\Type;
11-
use PhpParser\Node\Expr\MethodCall;
12-
135
use function PHPStan\Testing\assertType;
146

15-
class RelationDynamicMethodReturnTypeExtension implements DynamicMethodReturnTypeExtension
16-
{
17-
public function getClass(): string
18-
{
19-
return Model::class;
20-
}
21-
22-
public function isMethodSupported(MethodReflection $methodReflection): bool
23-
{
24-
return $methodReflection->getName() === 'belongsTo';
25-
}
26-
27-
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type {
28-
$returnType = $methodReflection->getVariants()[0]->getReturnType();
29-
$argType = $scope->getType($methodCall->getArgs()[0]->value);
30-
$modelClass = $argType->getClassStringObjectType()->getObjectClassNames()[0];
31-
32-
return new GenericObjectType($returnType->getObjectClassNames()[0], [
33-
new ObjectType($modelClass),
34-
$scope->getType($methodCall->var),
35-
]);
36-
}
37-
}
38-
397
abstract class Model
408
{
419
/** @return BelongsTo<*, *> */

tests/PHPStan/Analyser/Bug11857Test.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)