Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e29ffc2

Browse files
Fix test - container is created by no longer crashes on parse error because of named args
1 parent 39320da commit e29ffc2

File tree

3 files changed

+69
-64
lines changed

3 files changed

+69
-64
lines changed

‎tests/PHPStan/Analyser/DynamicMethodThrowTypeExtensionTest.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function dataFileAsserts(): iterable
1515
}
1616

1717
yield from $this->gatherAssertTypes(__DIR__ . '/data/dynamic-method-throw-type-extension.php');
18-
yield from $this->gatherAssertTypes(__DIR__ . '/data/dynamic-method-throw-type-extension-named-args.php');
18+
yield from $this->gatherAssertTypes(__DIR__ . '/data/dynamic-method-throw-type-extension-named-args-fixture.php');
1919
}
2020

2121
/**
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php // lint >= 8.0
2+
3+
namespace DynamicMethodThrowTypeExtensionNamedArgs;
4+
5+
use PHPStan\TrinaryLogic;
6+
use function PHPStan\Testing\assertVariableCertainty;
7+
8+
class Foo
9+
{
10+
11+
/** @throws \Exception */
12+
public function throwOrNot(bool $need): int
13+
{
14+
if ($need) {
15+
throw new \Exception();
16+
}
17+
18+
return 1;
19+
}
20+
21+
/** @throws \Exception */
22+
public static function staticThrowOrNot(bool $need): int
23+
{
24+
if ($need) {
25+
throw new \Exception();
26+
}
27+
28+
return 1;
29+
}
30+
31+
public function doFoo1()
32+
{
33+
try {
34+
$result = $this->throwOrNot(need: true);
35+
} finally {
36+
assertVariableCertainty(TrinaryLogic::createMaybe(), $result);
37+
}
38+
}
39+
40+
public function doFoo2()
41+
{
42+
try {
43+
$result = $this->throwOrNot(need: false);
44+
} finally {
45+
assertVariableCertainty(TrinaryLogic::createYes(), $result);
46+
}
47+
}
48+
49+
public function doFoo3()
50+
{
51+
try {
52+
$result = self::staticThrowOrNot(need: true);
53+
} finally {
54+
assertVariableCertainty(TrinaryLogic::createMaybe(), $result);
55+
}
56+
}
57+
58+
public function doFoo4()
59+
{
60+
try {
61+
$result = self::staticThrowOrNot(need: false);
62+
} finally {
63+
assertVariableCertainty(TrinaryLogic::createYes(), $result);
64+
}
65+
}
66+
67+
}
68+

‎tests/PHPStan/Analyser/data/dynamic-method-throw-type-extension-named-args.php‎

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
use PhpParser\Node\Expr\StaticCall;
77
use PHPStan\Analyser\Scope;
88
use PHPStan\Reflection\MethodReflection;
9-
use PHPStan\TrinaryLogic;
109
use PHPStan\Type\Constant\ConstantBooleanType;
1110
use PHPStan\Type\DynamicMethodThrowTypeExtension;
1211
use PHPStan\Type\DynamicStaticMethodThrowTypeExtension;
1312
use PHPStan\Type\Type;
14-
use function PHPStan\Testing\assertVariableCertainty;
1513

1614
class MethodThrowTypeExtension implements DynamicMethodThrowTypeExtension
1715
{
@@ -60,64 +58,3 @@ public function getThrowTypeFromStaticMethodCall(MethodReflection $methodReflect
6058
}
6159

6260
}
63-
64-
class Foo
65-
{
66-
67-
/** @throws \Exception */
68-
public function throwOrNot(bool $need): int
69-
{
70-
if ($need) {
71-
throw new \Exception();
72-
}
73-
74-
return 1;
75-
}
76-
77-
/** @throws \Exception */
78-
public static function staticThrowOrNot(bool $need): int
79-
{
80-
if ($need) {
81-
throw new \Exception();
82-
}
83-
84-
return 1;
85-
}
86-
87-
public function doFoo1()
88-
{
89-
try {
90-
$result = $this->throwOrNot(need: true);
91-
} finally {
92-
assertVariableCertainty(TrinaryLogic::createMaybe(), $result);
93-
}
94-
}
95-
96-
public function doFoo2()
97-
{
98-
try {
99-
$result = $this->throwOrNot(need: false);
100-
} finally {
101-
assertVariableCertainty(TrinaryLogic::createYes(), $result);
102-
}
103-
}
104-
105-
public function doFoo3()
106-
{
107-
try {
108-
$result = self::staticThrowOrNot(need: true);
109-
} finally {
110-
assertVariableCertainty(TrinaryLogic::createMaybe(), $result);
111-
}
112-
}
113-
114-
public function doFoo4()
115-
{
116-
try {
117-
$result = self::staticThrowOrNot(need: false);
118-
} finally {
119-
assertVariableCertainty(TrinaryLogic::createYes(), $result);
120-
}
121-
}
122-
123-
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /