forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbug-14096.php
More file actions
56 lines (45 loc) · 1.44 KB
/
bug-14096.php
File metadata and controls
56 lines (45 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php declare(strict_types = 1);
namespace Bug14096;
use function PHPStan\Testing\assertType;
class AbstractView {}
class App {}
interface ServerRequestInterface {}
class Test
{
/**
* @template T of App
*
* @param \Closure(ServerRequestInterface): T $createAppFx
* @param \Closure(T): ServerRequestInterface $simulateRequestFx
*
* @return T
*/
protected function simulateAppCallback(\Closure $createAppFx, \Closure $simulateRequestFx): App
{
$appBase = $createAppFx(new class() implements ServerRequestInterface {});
$request = $simulateRequestFx($appBase);
$app = $createAppFx($request);
return $app;
}
/**
* @template T of AbstractView
*
* @param \Closure(ServerRequestInterface): T $createViewFx
* @param \Closure(T): ServerRequestInterface $simulateRequestFx
*
* @return T
*/
protected function simulateViewCallback(\Closure $createViewFx, \Closure $simulateRequestFx): AbstractView
{
$view = null;
$this->simulateAppCallback(static function (ServerRequestInterface $request) use ($createViewFx, &$view) {
$view = $createViewFx($request);
return new App();
}, static function () use ($simulateRequestFx, &$view) {
assertType('T of Bug14096\AbstractView (method Bug14096\Test::simulateViewCallback(), argument)|null', $view);
return $simulateRequestFx($view);
});
assertType('T of Bug14096\AbstractView (method Bug14096\Test::simulateViewCallback(), argument)|null', $view);
return $view;
}
}