|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace BEAR\Package\Compiler; |
|
6
|
|
|
|
|
7
|
|
|
use BEAR\AppMeta\AbstractAppMeta; |
|
8
|
|
|
use BEAR\Package\Provide\Error\NullPage; |
|
9
|
|
|
use BEAR\QueryRepository\EtagSetter; |
|
10
|
|
|
use BEAR\QueryRepository\HttpCache; |
|
11
|
|
|
use BEAR\Resource\ResourceObject; |
|
12
|
|
|
use BEAR\Resource\Uri; |
|
13
|
|
|
use BEAR\Sunday\Extension\Application\AppInterface; |
|
14
|
|
|
use BEAR\Sunday\Extension\Transfer\HttpCacheInterface; |
|
15
|
|
|
use BEAR\Sunday\Provide\Transfer\HttpResponder; |
|
16
|
|
|
use Ray\Aop\ReflectiveMethodInvocation; |
|
17
|
|
|
use Ray\Di\InjectorInterface; |
|
18
|
|
|
|
|
19
|
|
|
use function assert; |
|
20
|
|
|
use function class_exists; |
|
21
|
|
|
use function property_exists; |
|
22
|
|
|
|
|
23
|
|
|
class FakeRun |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var InjectorInterface */ |
|
26
|
|
|
private $injector; |
|
27
|
|
|
|
|
28
|
|
|
/** @var string */ |
|
29
|
|
|
private $context; |
|
30
|
|
|
|
|
31
|
|
|
/** @var AbstractAppMeta */ |
|
32
|
|
|
private $appMeta; |
|
33
|
|
|
|
|
34
|
|
|
public function __construct(InjectorInterface $injector, string $context, AbstractAppMeta $appMeta) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->injector = $injector; |
|
37
|
|
|
$this->context = $context; |
|
38
|
|
|
$this->appMeta = $appMeta; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @psalm-suppress MixedFunctionCall |
|
43
|
|
|
* @psalm-suppress NoInterfaceProperties |
|
44
|
|
|
* @psalm-suppress MixedMethodCall |
|
45
|
|
|
* @psalm-suppress MixedPropertyFetch |
|
46
|
|
|
*/ |
|
47
|
|
|
public function __invoke(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$appBootstrap = $this->appMeta->name . '\Bootstrap'; |
|
50
|
|
|
$bootstrap = class_exists($appBootstrap) ? $appBootstrap : Bootstrap::class; |
|
51
|
|
|
$_SERVER['HTTP_IF_NONE_MATCH'] = '0'; |
|
52
|
|
|
$_SERVER['REQUEST_URI'] = '/'; |
|
53
|
|
|
$_SERVER['REQUEST_METHOD'] = 'GET'; |
|
54
|
|
|
(new $bootstrap())($this->context, $GLOBALS, $_SERVER); // 200 OK |
|
55
|
|
|
$_SERVER['REQUEST_METHOD'] = 'DELETE'; |
|
56
|
|
|
(new $bootstrap())($this->context, $GLOBALS, $_SERVER); // 405 MethodNotAllowedException |
|
57
|
|
|
$app = $this->injector->getInstance(AppInterface::class); |
|
58
|
|
|
assert(property_exists($app, 'resource')); |
|
59
|
|
|
assert(property_exists($app, 'responder')); |
|
60
|
|
|
$ro = $this->injector->getInstance(NullPage::class); |
|
61
|
|
|
$ro->uri = new Uri('app://self/'); |
|
62
|
|
|
$ro = $app->resource->get->object($ro)(['required' => 'string']); |
|
63
|
|
|
assert($ro instanceof ResourceObject); |
|
64
|
|
|
$ro->transfer($app->responder, []); |
|
65
|
|
|
class_exists(HttpCacheInterface::class); |
|
66
|
|
|
class_exists(HttpCache::class); |
|
67
|
|
|
class_exists(HttpResponder::class); |
|
68
|
|
|
class_exists(EtagSetter::class); |
|
69
|
|
|
class_exists(ReflectiveMethodInvocation::class); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|