Skip to content
This repository was archived by the owner on Mar 24, 2025. It is now read-only.

Commit 4c5fe33

Browse files
committed
fix: fix request test
1 parent e6e5e36 commit 4c5fe33

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

src/Transformers/Request.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,27 +183,27 @@ public static function handleStatic($swooleRequest, $swooleResponse, string $pub
183183
{
184184
$uri = $swooleRequest->server['request_uri'] ?? '';
185185
$extension = strtok(pathinfo($uri, PATHINFO_EXTENSION), '?');
186-
$fileName = @realpath($publicPath . $uri);
186+
$filePath = @realpath($publicPath . $uri);
187187

188-
if (!$fileName) {
188+
if (!$filePath) {
189189
return false;
190190
}
191191

192192
if ($extension && in_array($extension, static::EXTENSION_BLACKLIST)) {
193193
return false;
194194
}
195195

196-
if (substr($fileName, 0, strlen($publicPath)) != $publicPath) {
196+
if (substr($filePath, 0, strlen($publicPath)) != $publicPath) {
197197
return false;
198198
}
199199

200-
if (! is_file($fileName) || ! filesize($fileName)) {
200+
if (! is_file($filePath) || ! filesize($filePath)) {
201201
return false;
202202
}
203203

204204
$swooleResponse->status(IlluminateResponse::HTTP_OK);
205205
$swooleResponse->header('Content-Type', MimeType::get($extension));
206-
$swooleResponse->sendfile($fileName);
206+
$swooleResponse->sendfile($filePath);
207207

208208
return true;
209209
}

tests/Transformers/RequestTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public function testToIlluminate()
2626

2727
public function testHandleStatic()
2828
{
29+
$realPath = false;
30+
$this->mockMethod('realpath', function () use (&$realPath) {
31+
$realPath = true;
32+
return '/foo.css';
33+
});
34+
2935
$isFile = false;
3036
$this->mockMethod('is_file', function () use (&$isFile) {
3137
return $isFile = true;
@@ -50,11 +56,12 @@ public function testHandleStatic()
5056
->with('Content-Type', 'text/css')
5157
->once();
5258
$response->shouldReceive('sendfile')
53-
->with('/foo.bar')
59+
->with('/foo.css')
5460
->once();
5561

5662
Request::handleStatic(new SwooleRequestStub, $response, '/');
5763

64+
$this->assertTrue($realPath);
5865
$this->assertTrue($isFile);
5966
$this->assertTrue($fileSize);
6067
}
@@ -70,16 +77,16 @@ public function testHandleStaticWithBlackList()
7077

7178
public function testHandleStaticWithNoneFile()
7279
{
73-
$isFile = false;
74-
$this->mockMethod('is_file', function () use (&$isFile) {
75-
$isFile = true;
80+
$realPath = false;
81+
$this->mockMethod('realpath', function () use (&$realPath) {
82+
$realPath = true;
7683

7784
return false;
7885
});
7986

8087
$result = Request::handleStatic(new SwooleRequestStub, null, '/');
8188
$this->assertFalse($result);
82-
$this->assertTrue($isFile);
89+
$this->assertTrue($realPath);
8390
}
8491

8592
protected function mockMethod($name, \Closure $function, $namespace = null)

0 commit comments

Comments
 (0)