Completed
Pull Request — 1.x (#357)
by Akihito
03:21 queued 01:46
created

FakeRun::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
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\TransferInterface;
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 is_callable;
22
use function is_object;
23
use function property_exists;
24
25
class FakeRun
26
{
27
    /** @var InjectorInterface */
28
    private $injector;
29
30
    /** @var string */
31
    private $context;
32
33
    /** @var AbstractAppMeta  */
34
    private $appMeta;
35
36
    public function __construct(InjectorInterface $injector, string $context, AbstractAppMeta $appMeta)
37
    {
38
        $this->injector = $injector;
39
        $this->context = $context;
40
        $this->appMeta = $appMeta;
41
    }
42
43
    /**
44
     * @psalm-suppress MixedFunctionCall
45
     * @psalm-suppress NoInterfaceProperties
46
     * @psalm-suppress MixedMethodCall
47
     * @psalm-suppress MixedPropertyFetch
48
     */
49
    public function __invoke(): void
50
    {
51
        $appBootstrap = $this->appMeta->name . '\Bootstrap';
52
        $bootstrap = class_exists($appBootstrap) ? new $appBootstrap() : new Bootstrap($this->appMeta);
53
        $_SERVER['HTTP_IF_NONE_MATCH'] = '0';
54
        $_SERVER['REQUEST_URI'] = '/';
55
        $_SERVER['REQUEST_METHOD'] = 'GET';
56
        assert(is_callable($bootstrap));
57
        /** @psalm-suppress PossiblyUndefinedVariable */
58
        ($bootstrap)($this->appMeta->name, $this->context, $GLOBALS, $_SERVER); // 200 OK
59
        $_SERVER['REQUEST_METHOD'] = 'DELETE';
60
        $app = $this->injector->getInstance(AppInterface::class);
61
        assert(is_object($app));
62
        assert(property_exists($app, 'resource'));
63
        assert(property_exists($app, 'responder'));
64
        $ro = $this->injector->getInstance(NullPage::class);
65
        assert($ro instanceof NullPage);
66
        $ro->uri = new Uri('app://self/');
67
        /** @var NullPage $ro */
68
        $ro = $app->resource->get->object($ro)(['required' => 'string']);
69
        assert($app->responder instanceof TransferInterface);
70
        $ro->transfer($app->responder, []);
71
        class_exists(HttpCacheInterface::class);
72
        class_exists(HttpCache::class);
73
        class_exists(HttpResponder::class);
74
        class_exists(EtagSetter::class);
75
        class_exists(ReflectiveMethodInvocation::class);
76
    }
77
}
78