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

tempestphp / tempest-framework / 14049246919

24 Mar 2025 09:42PM UTC coverage: 79.353% (-0.04%) from 79.391%
14049246919

push

github

web-flow
feat(support): support array parameters in string manipulations (#1073)

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

735 existing lines in 126 files now uncovered.

10492 of 13222 relevant lines covered (79.35%)

90.78 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(
658✔
22
        private Container $container,
23
    ) {}
658✔
24

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

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

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

45
        return $this;
4✔
46
    }
47

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

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

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

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

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

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

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

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

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

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

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

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

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

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

174
        return ServerRequestFactory::fromGlobals()->withUploadedFiles($files);
10✔
175
    }
176
}
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