Completed
Push — 1.x ( c86fd3...4b8bd5 )
by Akihito
14s queued 12s
created

FakeRun   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 6
Bugs 0 Features 0
Metric Value
wmc 2
eloc 29
c 6
b 0
f 0
dl 0
loc 51
rs 10

2 Methods

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