Skip to content

Commit 3d30b7c

Browse files
committed
tests: add one more phar test case
1 parent eab5077 commit 3d30b7c

File tree

3 files changed

+201
-8
lines changed

3 files changed

+201
-8
lines changed

tests/phar/data/absolute_1.out

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ Version main
77
Parsing Foo\Foo total: 19 errors
88
Parsing Models\LaravelModel total: 20 errors
99
Parsing IPv4Address total: 20 errors
10-
Parsing SuperCoolLibrary\Meta total: 20 errors
11-
Parsing Net_Sample total: 22 errors
10+
Parsing MyContainer total: 22 errors
11+
Parsing Collection total: 22 errors
12+
Parsing DogCollection total: 22 errors
13+
Parsing PersistentCollection total: 22 errors
14+
Parsing Cat total: 22 errors
15+
Parsing Foo total: 22 errors
16+
Parsing Bar total: 22 errors
17+
Parsing SuperCoolLibrary\Meta total: 22 errors
18+
Parsing Net_Sample total: 24 errors
1219
Parsing done
1320

1421
Rendering Global index.html
@@ -27,19 +34,26 @@ Rendering Namespace Illuminate\Database
2734
Rendering Namespace Illuminate\Database\Eloquent
2835
Rendering Namespace Models
2936
Rendering Namespace SuperCoolLibrary
37+
Rendering Class Bar
38+
Rendering Class Cat
39+
Rendering Class Collection
40+
Rendering Class DogCollection
41+
Rendering Class Foo
3042
Rendering Class Foo\Foo
3143
Rendering Class IPv4Address
3244
Rendering Class Illuminate\Database\Eloquent\Builder
3345
Rendering Class Models\LaravelModel
46+
Rendering Class MyContainer
3447
Rendering Class Net_Sample
48+
Rendering Class PersistentCollection
3549
Rendering Class SuperCoolLibrary\Meta
3650
Rendering done
3751

3852

3953
Version Updated C Removed C
40-
main 6 0
54+
main 13 0
4155

4256

4357
Version Updated C Updated N Removed C Removed N
44-
main 6 7 0 0
58+
main 13 7 0 0
4559

tests/phar/data/relative_1.out

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@ Version main
77
Parsing Foo\Foo total: 19 errors
88
Parsing Models\LaravelModel total: 20 errors
99
Parsing IPv4Address total: 20 errors
10-
Parsing SuperCoolLibrary\Meta total: 20 errors
11-
Parsing Net_Sample total: 22 errors
10+
Parsing MyContainer total: 22 errors
11+
Parsing Collection total: 22 errors
12+
Parsing DogCollection total: 22 errors
13+
Parsing PersistentCollection total: 22 errors
14+
Parsing Cat total: 22 errors
15+
Parsing Foo total: 22 errors
16+
Parsing Bar total: 22 errors
17+
Parsing SuperCoolLibrary\Meta total: 22 errors
18+
Parsing Net_Sample total: 24 errors
1219
Parsing done
1320

1421
Rendering Global index.html
@@ -27,19 +34,26 @@ Rendering Namespace Illuminate\Database
2734
Rendering Namespace Illuminate\Database\Eloquent
2835
Rendering Namespace Models
2936
Rendering Namespace SuperCoolLibrary
37+
Rendering Class Bar
38+
Rendering Class Cat
39+
Rendering Class Collection
40+
Rendering Class DogCollection
41+
Rendering Class Foo
3042
Rendering Class Foo\Foo
3143
Rendering Class IPv4Address
3244
Rendering Class Illuminate\Database\Eloquent\Builder
3345
Rendering Class Models\LaravelModel
46+
Rendering Class MyContainer
3447
Rendering Class Net_Sample
48+
Rendering Class PersistentCollection
3549
Rendering Class SuperCoolLibrary\Meta
3650
Rendering done
3751

3852

3953
Version Updated C Removed C
40-
main 6 0
54+
main 13 0
4155

4256

4357
Version Updated C Updated N Removed C Removed N
44-
main 6 7 0 0
58+
main 13 7 0 0
4559

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
/**
4+
* @template T
5+
*/
6+
class MyContainer
7+
{
8+
/** @var T */
9+
private $value;
10+
11+
/** @param T $value */
12+
public function __construct($value)
13+
{
14+
$this->value = $value;
15+
}
16+
17+
/** @return T */
18+
public function getValue()
19+
{
20+
return $this->value;
21+
}
22+
23+
/** @return array<T> */
24+
public function getValueAsArray()
25+
{
26+
return [$this->value];
27+
}
28+
29+
/** @return MyContainer<array<int,int>> */
30+
public function getContainerOfInts()
31+
{
32+
// doc block used so phpstan let's us do what we want
33+
/** @var array<int,int> */
34+
$data = [
35+
1, 2, 3
36+
];
37+
return new MyContainer($data);
38+
}
39+
40+
/**
41+
* @template T
42+
* @param T $a
43+
* @return T
44+
*/
45+
function foo($a)
46+
{
47+
return $a;
48+
}
49+
50+
/**
51+
* @template T of \Exception
52+
* @param T $exception
53+
* @return T
54+
*/
55+
function fooEx($exception)
56+
{
57+
}
58+
59+
/**
60+
* @template T
61+
* @param class-string<T> $className
62+
* @param int $id
63+
* @return T|null
64+
*/
65+
function findEntity(string $className, int $id)
66+
{
67+
}
68+
69+
/**
70+
* @phpstan-template T of \Exception
71+
*
72+
* @param \Exception $param
73+
* @return \Exception
74+
*
75+
* @phpstan-param T $param
76+
* @phpstan-return T
77+
*/
78+
function foo3($param) { }
79+
80+
}
81+
$data = [
82+
'a',
83+
'b',
84+
];
85+
$c = new MyContainer($data);
86+
foreach ($c->getValue() as $key => $val) {
87+
if (is_string($val)) {
88+
// valid, always true
89+
}
90+
if (is_array($val)) {
91+
// invalid, code never enters
92+
}
93+
}
94+
foreach ($c->getValueAsArray()[0] as $key => $val) {
95+
if (is_string($val)) {
96+
// valid, always true
97+
}
98+
if (is_array($val)) {
99+
// invalid, code never enters
100+
}
101+
}
102+
foreach ($c->getContainerOfInts()->getValue() as $key => $val) {
103+
if (is_string($val)) {
104+
// invalid, code never enters
105+
}
106+
if (is_array($val)) {
107+
// invalid, code never enters
108+
}
109+
if (is_int($val)) {
110+
// valid, always true
111+
}
112+
}
113+
class Collection {
114+
function add($v): void {
115+
116+
}
117+
}
118+
119+
/**
120+
* @implements Collection<Dog>
121+
*/
122+
class DogCollection implements Collection
123+
{
124+
}
125+
126+
/**
127+
* @template T
128+
* @implements Collection<T>
129+
*/
130+
class PersistentCollection implements Collection
131+
{
132+
}
133+
134+
class Cat {}
135+
class Foo {
136+
/**
137+
* @param Collection<Dog> $dogs
138+
*/
139+
function foo(Collection $dogs)
140+
{
141+
// Dog expected, Cat given
142+
$dogs->add(new Cat());
143+
}
144+
}
145+
class Bar {}
146+
147+
/**
148+
* @return \Generator<int, string, Foo, Bar>
149+
*/
150+
function foo(): \Generator
151+
{
152+
yield 'foo' => new Foo(); // wrong key and value
153+
$send = yield 1 => 'foo'; // correct
154+
// $send is Foo
155+
156+
if (rand(0, 1)) {
157+
return $send; // wrong
158+
}
159+
160+
return new Bar(); // correct
161+
}
162+
163+
$generator = foo();
164+
$generator->send(1); // wrong, expects Foo
165+
$generator->getReturn(); // Bar

0 commit comments

Comments
 (0)