Skip to content

Commit a8d47a4

Browse files
committed
Added new Testing, added bypassing of finals
1 parent eb3e7a8 commit a8d47a4

File tree

5 files changed

+60
-4
lines changed

5 files changed

+60
-4
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
},
3535
"require-dev": {
3636
"phpunit/phpunit": "^9.2",
37-
"phpspec/prophecy-phpunit": "^2.0"
37+
"phpspec/prophecy-phpunit": "^2.0",
38+
"dg/bypass-finals": "^1.2"
3839
}
3940
}

src/Http/Controllers/ImageController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use le0daniel\Laravel\ImageEngine\Image\ImageEngine;
1515
use le0daniel\Laravel\ImageEngine\Utility\SignatureException;
1616
use le0daniel\Laravel\ImageEngine\Utility\Signatures;
17+
use Symfony\Component\HttpFoundation\BinaryFileResponse;
1718

1819
class ImageController extends BaseController
1920
{
@@ -48,8 +49,9 @@ public function image(string $folder, string $path, string $extension)
4849
false
4950
);
5051

51-
return response()->file(
52-
$absoluteImagePath,
52+
return new BinaryFileResponse(
53+
new \SplFileInfo($absoluteImagePath),
54+
200,
5355
$imageRepresentation->cacheControlHeaders()
5456
);
5557
} catch (SignatureException $signatureException) {

src/Image/ImageRepresentation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private function getValue(string $name, $value)
9393
switch ($name) {
9494
case 'timestamp':
9595
return $this->expires;
96-
case 'disk':
96+
case 'diskName':
9797
return $value ?? self::DEFAULT_DISK_NAME;
9898
case 'extension':
9999
return pathinfo($this->filePath, PATHINFO_EXTENSION);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace le0daniel\Tests\Laravel\ImageEngine\Http\Controllers;
4+
5+
use Intervention\Image\ImageManager;
6+
use le0daniel\Laravel\ImageEngine\Http\Controllers\ImageController;
7+
use le0daniel\Laravel\ImageEngine\Image\ImageEngine;
8+
use le0daniel\Laravel\ImageEngine\Image\ImageRepresentation;
9+
use PHPUnit\Framework\TestCase;
10+
use Prophecy\Argument;
11+
use Prophecy\PhpUnit\ProphecyTrait;
12+
use Symfony\Component\HttpFoundation\BinaryFileResponse;
13+
14+
final class ImageControllerTest extends TestCase
15+
{
16+
use ProphecyTrait;
17+
18+
private const SECRET = 'asdfasdf!?';
19+
private $imageEngine;
20+
private ImageController $imageController;
21+
22+
protected function setUp(): void
23+
{
24+
$this->imageEngine = $this->prophesize(ImageEngine::class);
25+
$this->imageController = new ImageController(
26+
$this->imageEngine->reveal()
27+
);
28+
}
29+
30+
public function testImage()
31+
{
32+
$this->imageEngine->getImageFromSignedString('folder::string')->willReturn(
33+
ImageRepresentation::from('path', 'medium')
34+
);
35+
36+
$this
37+
->imageEngine
38+
->render(Argument::type(ImageRepresentation::class), 'jpg', false)
39+
->willReturn(test_files('image.jpg'))
40+
;
41+
42+
/** @var BinaryFileResponse $binaryFileResponse */
43+
$binaryFileResponse = $this->imageController->image('folder', 'string', 'jpg');
44+
$this->assertSame(
45+
test_files('image.jpg'),
46+
$binaryFileResponse->getFile()->getRealPath()
47+
);
48+
}
49+
}

tests/bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?php
22

3+
use DG\BypassFinals;
4+
35
define('PHP_UNIT_TEST_MODE', true);
46

7+
BypassFinals::enable();
8+
59
function test_files(string $filePath, bool $ensureCreated = false): string
610
{
711
$file = __DIR__ . "/static_files/$filePath";

0 commit comments

Comments
 (0)