• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 14024978163

23 Mar 2025 05:55PM UTC coverage: 79.391% (-0.05%) from 79.441%
14024978163

push

github

web-flow
feat(view): cache Blade and Twig templates in internal storage (#1061)

2 of 2 new or added lines in 2 files covered. (100.0%)

912 existing lines in 110 files now uncovered.

10478 of 13198 relevant lines covered (79.39%)

91.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.04
/src/Tempest/Framework/Testing/Http/HttpRouterTester.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Framework\Testing\Http;
6

7
use Laminas\Diactoros\ServerRequestFactory;
8
use Psr\Http\Message\ServerRequestInterface as PsrRequest;
9
use Tempest\Container\Container;
10
use Tempest\Http\Method;
11
use Tempest\Router\GenericRequest;
12
use Tempest\Router\GenericRouter;
13
use Tempest\Router\Mappers\RequestToPsrRequestMapper;
14
use Tempest\Router\Request;
15
use Tempest\Router\Router;
16

17
use function Tempest\map;
18

19
final class HttpRouterTester
20
{
21
    public function __construct(
657✔
22
        private Container $container,
23
    ) {
24
    }
657✔
25

26
    public function get(string $uri, array $headers = []): TestResponseHelper
13✔
27
    {
28
        return $this->sendRequest(
13✔
29
            new GenericRequest(
13✔
30
                method: Method::GET,
13✔
31
                uri: $uri,
13✔
32
                body: [],
13✔
33
                headers: $headers,
13✔
34
            ),
13✔
35
        );
13✔
36
    }
37

38
    public function throwExceptions(): self
4✔
39
    {
40
        $router = $this->container->get(Router::class);
4✔
41

42
        if ($router instanceof GenericRouter) {
4✔
43
            $router->throwExceptions();
4✔
44
        }
45

46
        return $this;
4✔
47
    }
48

49
    public function head(string $uri, array $headers = []): TestResponseHelper
2✔
50
    {
51
        return $this->sendRequest(
2✔
52
            new GenericRequest(
2✔
53
                method: Method::HEAD,
2✔
54
                uri: $uri,
2✔
55
                body: [],
2✔
56
                headers: $headers,
2✔
57
            ),
2✔
58
        );
2✔
59
    }
60

61
    public function post(string $uri, array $body = [], array $headers = []): TestResponseHelper
9✔
62
    {
63
        return $this->sendRequest(
9✔
64
            new GenericRequest(
9✔
65
                method: Method::POST,
9✔
66
                uri: $uri,
9✔
67
                body: $body,
9✔
68
                headers: $headers,
9✔
69
            ),
9✔
70
        );
9✔
71
    }
72

73
    public function put(string $uri, array $body = [], array $headers = []): TestResponseHelper
2✔
74
    {
75
        return $this->sendRequest(
2✔
76
            new GenericRequest(
2✔
77
                method: Method::PUT,
2✔
78
                uri: $uri,
2✔
79
                body: $body,
2✔
80
                headers: $headers,
2✔
81
            ),
2✔
82
        );
2✔
83
    }
84

85
    public function delete(string $uri, array $body = [], array $headers = []): TestResponseHelper
2✔
86
    {
87
        return $this->sendRequest(
2✔
88
            new GenericRequest(
2✔
89
                method: Method::DELETE,
2✔
90
                uri: $uri,
2✔
91
                body: $body,
2✔
92
                headers: $headers,
2✔
93
            ),
2✔
94
        );
2✔
95
    }
96

97
    public function connect(string $uri, array $body = [], array $headers = []): TestResponseHelper
2✔
98
    {
99
        return $this->sendRequest(
2✔
100
            new GenericRequest(
2✔
101
                method: Method::CONNECT,
2✔
102
                uri: $uri,
2✔
103
                body: $body,
2✔
104
                headers: $headers,
2✔
105
            ),
2✔
106
        );
2✔
107
    }
108

109
    public function options(string $uri, array $body = [], array $headers = []): TestResponseHelper
2✔
110
    {
111
        return $this->sendRequest(
2✔
112
            new GenericRequest(
2✔
113
                method: Method::OPTIONS,
2✔
114
                uri: $uri,
2✔
115
                body: $body,
2✔
116
                headers: $headers,
2✔
117
            ),
2✔
118
        );
2✔
119
    }
120

121
    public function trace(string $uri, array $body = [], array $headers = []): TestResponseHelper
2✔
122
    {
123
        return $this->sendRequest(
2✔
124
            new GenericRequest(
2✔
125
                method: Method::TRACE,
2✔
126
                uri: $uri,
2✔
127
                body: $body,
2✔
128
                headers: $headers,
2✔
129
            ),
2✔
130
        );
2✔
131
    }
132

133
    public function patch(string $uri, array $body = [], array $headers = []): TestResponseHelper
2✔
134
    {
135
        return $this->sendRequest(
2✔
136
            new GenericRequest(
2✔
137
                method: Method::PATCH,
2✔
138
                uri: $uri,
2✔
139
                body: $body,
2✔
140
                headers: $headers,
2✔
141
            ),
2✔
142
        );
2✔
143
    }
144

145
    public function sendRequest(Request $request): TestResponseHelper
35✔
146
    {
147
        /** @var Router $router */
148
        $router = $this->container->get(Router::class);
35✔
149

150
        return new TestResponseHelper(
35✔
151
            $router->dispatch(map($request)->with(RequestToPsrRequestMapper::class)->do()),
35✔
152
        );
35✔
153
    }
154

155
    public function makePsrRequest(
10✔
156
        string $uri,
157
        Method $method = Method::GET,
158
        array $body = [],
159
        array $headers = [],
160
        array $cookies = [],
161
        array $files = [],
162
    ): PsrRequest {
163
        $_SERVER['REQUEST_URI'] = $uri;
10✔
164
        $_SERVER['REQUEST_METHOD'] = $method->value;
10✔
165

166
        foreach ($headers as $key => $value) {
10✔
UNCOV
167
            $key = strtoupper($key);
×
168

UNCOV
169
            $_SERVER["HTTP_{$key}"] = $value;
×
170
        }
171

172
        $_COOKIE = $cookies;
10✔
173
        $_POST = $body;
10✔
174

175
        return ServerRequestFactory::fromGlobals()->withUploadedFiles($files);
10✔
176
    }
177
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc