2
2
3
3
namespace le0daniel \Tests \Laravel \ImageEngine \Http \Controllers ;
4
4
5
+ use Carbon \Carbon ;
6
+ use Illuminate \Http \JsonResponse ;
5
7
use Intervention \Image \ImageManager ;
6
8
use le0daniel \Laravel \ImageEngine \Http \Controllers \ImageController ;
7
9
use le0daniel \Laravel \ImageEngine \Image \ImageEngine ;
10
+ use le0daniel \Laravel \ImageEngine \Image \ImageException ;
8
11
use le0daniel \Laravel \ImageEngine \Image \ImageRepresentation ;
12
+ use le0daniel \Laravel \ImageEngine \Utility \SignatureException ;
9
13
use PHPUnit \Framework \TestCase ;
10
14
use Prophecy \Argument ;
11
15
use Prophecy \PhpUnit \ProphecyTrait ;
@@ -25,6 +29,12 @@ protected function setUp(): void
25
29
$ this ->imageController = new ImageController (
26
30
$ this ->imageEngine ->reveal ()
27
31
);
32
+
33
+ $ this
34
+ ->imageEngine
35
+ ->render (Argument::type (ImageRepresentation::class), 'jpg ' , false )
36
+ ->willReturn (test_files ('image.jpg ' ))
37
+ ;
28
38
}
29
39
30
40
public function testImage ()
@@ -33,17 +43,53 @@ public function testImage()
33
43
ImageRepresentation::from ('path ' , 'medium ' )
34
44
);
35
45
36
- $ this
37
- ->imageEngine
38
- ->render (Argument::type (ImageRepresentation::class), 'jpg ' , false )
39
- ->willReturn (test_files ('image.jpg ' ))
40
- ;
41
-
42
46
/** @var BinaryFileResponse $binaryFileResponse */
43
47
$ binaryFileResponse = $ this ->imageController ->image ('folder ' , 'string ' , 'jpg ' );
44
48
$ this ->assertSame (
45
49
test_files ('image.jpg ' ),
46
50
$ binaryFileResponse ->getFile ()->getRealPath ()
47
51
);
48
52
}
53
+
54
+ public function testExpired ()
55
+ {
56
+ $ this ->imageEngine ->getImageFromSignedString ('folder::string ' )->willReturn (
57
+ ImageRepresentation::from ('path ' , 'medium ' , Carbon::now ()->subHour ())
58
+ );
59
+
60
+ /** @var JsonResponse $jsonResponse */
61
+ $ jsonResponse = $ this ->imageController ->image ('folder ' , 'string ' , 'jpg ' );
62
+ $ this ->assertSame (
63
+ 410 ,
64
+ $ jsonResponse ->getStatusCode ()
65
+ );
66
+ }
67
+
68
+ public function testInvalidSignature ()
69
+ {
70
+ $ this ->imageEngine ->getImageFromSignedString ('folder::string ' )->willThrow (
71
+ new SignatureException ('invalid sig ' )
72
+ );
73
+
74
+ /** @var JsonResponse $jsonResponse */
75
+ $ jsonResponse = $ this ->imageController ->image ('folder ' , 'string ' , 'jpg ' );
76
+ $ this ->assertSame (
77
+ 422 ,
78
+ $ jsonResponse ->getStatusCode ()
79
+ );
80
+ }
81
+
82
+ public function testImageExceptionHandling ()
83
+ {
84
+ $ this ->imageEngine ->getImageFromSignedString ('folder::string ' )->willThrow (
85
+ ImageException::withHint ('test ' , 'value ' )
86
+ );
87
+
88
+ /** @var JsonResponse $jsonResponse */
89
+ $ jsonResponse = $ this ->imageController ->image ('folder ' , 'string ' , 'jpg ' );
90
+ $ this ->assertSame (
91
+ 500 ,
92
+ $ jsonResponse ->getStatusCode ()
93
+ );
94
+ }
49
95
}
0 commit comments