Skip to content

Commit 366e400

Browse files
committed
test: adjust tests to new config structure, add SoureDirectoriesTest, import facades, improve testbench setup
1 parent ea1907b commit 366e400

File tree

9 files changed

+93
-30
lines changed

9 files changed

+93
-30
lines changed

testbench.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ workbench:
2525
- create-sqlite-db
2626
- db-wipe
2727
- migrate-fresh
28+
- storage-link
2829
assets:
29-
- laravel-assets
3030
- test-assets
3131
sync:
3232
- from: storage

tests/Feature/CacheTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
declare(strict_types=1);
44

55
use AceOfAces\LaravelImageTransformUrl\Tests\TestCase;
6+
use Illuminate\Support\Facades\Cache;
7+
use Illuminate\Support\Facades\Storage;
68

79
beforeEach(function () {
810
Cache::flush();
@@ -11,15 +13,15 @@
1113

1214
it('can serve from the cache after identical requests', function () {
1315
/** @var TestCase $this */
14-
$response = $this->get(route('image.transform', [
16+
$response = $this->get(route('image.transform.default', [
1517
'options' => 'width=500',
1618
'path' => 'cat.jpg',
1719
]));
1820

1921
$response->assertOk();
2022
$response->assertHeader('X-Cache', 'MISS');
2123

22-
$secondResponse = $this->get(route('image.transform', [
24+
$secondResponse = $this->get(route('image.transform.default', [
2325
'options' => 'width=500',
2426
'path' => 'cat.jpg',
2527
]));
@@ -30,23 +32,23 @@
3032

3133
it('can use the version option to revalidate the cache', function () {
3234
/** @var TestCase $this */
33-
$response = $this->get(route('image.transform', [
35+
$response = $this->get(route('image.transform.default', [
3436
'options' => 'version=1',
3537
'path' => 'cat.jpg',
3638
]));
3739

3840
$response->assertOk();
3941
$response->assertHeader('X-Cache', 'MISS');
4042

41-
$sameVersionResponse = $this->get(route('image.transform', [
43+
$sameVersionResponse = $this->get(route('image.transform.default', [
4244
'options' => 'version=1',
4345
'path' => 'cat.jpg',
4446
]));
4547

4648
$sameVersionResponse->assertOk();
4749
$sameVersionResponse->assertHeader('X-Cache', 'HIT');
4850

49-
$differentVersionResponse = $this->get(route('image.transform', [
51+
$differentVersionResponse = $this->get(route('image.transform.default', [
5052
'options' => 'version=2',
5153
'path' => 'cat.jpg',
5254
]));

tests/Feature/FormatTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
use AceOfAces\LaravelImageTransformUrl\Enums\AllowedMimeTypes;
66
use AceOfAces\LaravelImageTransformUrl\Tests\TestCase;
7+
use Illuminate\Support\Facades\Cache;
8+
use Illuminate\Support\Facades\Storage;
79

810
beforeEach(function () {
911
Cache::flush();
@@ -17,7 +19,7 @@
1719

1820
foreach ($allowedMimeTypes as $allowed) {
1921
/** @var TestCase $this */
20-
$response = $this->get(route('image.transform', [
22+
$response = $this->get(route('image.transform.default', [
2123
'options' => 'format='.$allowed['extension'],
2224
'path' => 'cat.jpg',
2325
]));
@@ -35,7 +37,7 @@
3537

3638
foreach ($allowedMimeTypes as $allowed) {
3739
/** @var TestCase $this */
38-
$response = $this->get(route('image.transform', [
40+
$response = $this->get(route('image.transform.default', [
3941
'options' => 'format='.$allowed['extension'],
4042
'path' => 'cat-kiss.gif',
4143
]));
@@ -53,7 +55,7 @@
5355

5456
foreach ($allowedMimeTypes as $allowed) {
5557
/** @var TestCase $this */
56-
$response = $this->get(route('image.transform', [
58+
$response = $this->get(route('image.transform.default', [
5759
'options' => 'format='.$allowed['extension'],
5860
'path' => 'cat.png',
5961
]));
@@ -70,7 +72,7 @@
7072

7173
foreach ($allowedMimeTypes as $allowed) {
7274
/** @var TestCase $this */
73-
$response = $this->get(route('image.transform', [
75+
$response = $this->get(route('image.transform.default', [
7476
'options' => 'format='.$allowed['extension'],
7577
'path' => 'cat.webp',
7678
]));

tests/Feature/HeadersTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
declare(strict_types=1);
44

55
use AceOfAces\LaravelImageTransformUrl\Tests\TestCase;
6+
use Illuminate\Support\Facades\Cache;
7+
use Illuminate\Support\Facades\Storage;
68

79
beforeEach(function () {
810
Cache::flush();
@@ -18,7 +20,7 @@
1820
]);
1921

2022
/** @var TestCase $this */
21-
$response = $this->get(route('image.transform', [
23+
$response = $this->get(route('image.transform.default', [
2224
'options' => 'width=500',
2325
'path' => 'cat.jpg',
2426
]));

tests/Feature/OptionsTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
it('can process the height option', function () {
1515
/** @var TestCase $this */
16-
$response = $this->get(route('image.transform', [
16+
$response = $this->get(route('image.transform.default', [
1717
'options' => 'width=100',
1818
'path' => 'cat.jpg',
1919
]));
@@ -26,7 +26,7 @@
2626

2727
it('can process the width option', function () {
2828
/** @var TestCase $this */
29-
$response = $this->get(route('image.transform', [
29+
$response = $this->get(route('image.transform.default', [
3030
'options' => 'height=100',
3131
'path' => 'cat.jpg',
3232
]));
@@ -39,7 +39,7 @@
3939

4040
it('can process the format option', function () {
4141
/** @var TestCase $this */
42-
$response = $this->get(route('image.transform', [
42+
$response = $this->get(route('image.transform.default', [
4343
'options' => 'format=webp',
4444
'path' => 'cat.jpg',
4545
]));
@@ -51,7 +51,7 @@
5151

5252
it('can process the quality option', function () {
5353
/** @var TestCase $this */
54-
$response = $this->get(route('image.transform', [
54+
$response = $this->get(route('image.transform.default', [
5555
'options' => 'quality=50',
5656
'path' => 'cat.jpg',
5757
]));
@@ -63,7 +63,7 @@
6363

6464
it('can process the blur option', function () {
6565
/** @var TestCase $this */
66-
$response = $this->get(route('image.transform', [
66+
$response = $this->get(route('image.transform.default', [
6767
'options' => 'blur=20',
6868
'path' => 'cat.jpg',
6969
]));
@@ -74,7 +74,7 @@
7474
});
7575

7676
it('can process the flip option', function () {
77-
$response = $this->get(route('image.transform', [
77+
$response = $this->get(route('image.transform.default', [
7878
'options' => 'flip=hv',
7979
'path' => 'cat.jpg',
8080
]));
@@ -86,7 +86,7 @@
8686

8787
it('can process the contrast option', function () {
8888
/** @var TestCase $this */
89-
$response = $this->get(route('image.transform', [
89+
$response = $this->get(route('image.transform.default', [
9090
'options' => 'contrast=-50',
9191
'path' => 'cat.jpg',
9292
]));
@@ -98,7 +98,7 @@
9898

9999
it('can process the background option', function () {
100100
/** @var TestCase $this */
101-
$response = $this->get(route('image.transform', [
101+
$response = $this->get(route('image.transform.default', [
102102
'options' => 'background=ffaa00',
103103
'path' => 'octocat.png',
104104
]));
@@ -110,7 +110,7 @@
110110

111111
it('can process multiple options at once', function () {
112112
/** @var TestCase $this */
113-
$response = $this->get(route('image.transform', [
113+
$response = $this->get(route('image.transform.default', [
114114
'options' => 'width=100,format=gif,quality=50',
115115
'path' => 'cat.jpg',
116116
]));
@@ -123,7 +123,7 @@
123123

124124
it('can handle a trailing comma in options', function () {
125125
/** @var TestCase $this */
126-
$response = $this->get(route('image.transform', [
126+
$response = $this->get(route('image.transform.default', [
127127
'options' => 'width=100,',
128128
'path' => 'cat.jpg',
129129
]));

tests/Feature/RateLimitTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
declare(strict_types=1);
44

55
use AceOfAces\LaravelImageTransformUrl\Tests\TestCase;
6+
use Illuminate\Support\Facades\Cache;
7+
use Illuminate\Support\Facades\Storage;
68

79
beforeEach(function () {
810
Cache::flush();
@@ -20,7 +22,7 @@
2022
config()->set('image-transform-url.rate_limit.decay_seconds', 60);
2123

2224
/** @var TestCase $this */
23-
$firstResponse = $this->get(route('image.transform', [
25+
$firstResponse = $this->get(route('image.transform.default', [
2426
'options' => 'width=100',
2527
'path' => 'cat.jpg',
2628
]));
@@ -30,7 +32,7 @@
3032
'mime' => 'image/jpeg',
3133
]);
3234

33-
$secondResponse = $this->get(route('image.transform', [
35+
$secondResponse = $this->get(route('image.transform.default', [
3436
'options' => 'width=200',
3537
'path' => 'cat.jpg',
3638
]));
@@ -40,7 +42,7 @@
4042
'mime' => 'image/jpeg',
4143
]);
4244

43-
$thirdResponse = $this->get(route('image.transform', [
45+
$thirdResponse = $this->get(route('image.transform.default', [
4446
'options' => 'width=300',
4547
'path' => 'cat.jpg',
4648
]));
@@ -55,7 +57,7 @@
5557
config()->set('image-transform-url.rate_limit.decay_seconds', 60);
5658

5759
/** @var TestCase $this */
58-
$firstResponse = $this->get(route('image.transform', [
60+
$firstResponse = $this->get(route('image.transform.default', [
5961
'options' => 'width=100',
6062
'path' => 'cat.jpg',
6163
]));
@@ -65,7 +67,7 @@
6567
'mime' => 'image/jpeg',
6668
]);
6769

68-
$secondResponse = $this->get(route('image.transform', [
70+
$secondResponse = $this->get(route('image.transform.default', [
6971
'options' => 'width=100',
7072
'path' => 'cat.jpg',
7173
]));
@@ -75,7 +77,7 @@
7577
'mime' => 'image/jpeg',
7678
]);
7779

78-
$thirdResponse = $this->get(route('image.transform', [
80+
$thirdResponse = $this->get(route('image.transform.default', [
7981
'options' => 'width=100',
8082
'path' => 'cat.jpg',
8183
]));

tests/Feature/RejectionTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
declare(strict_types=1);
44

55
use AceOfAces\LaravelImageTransformUrl\Tests\TestCase;
6+
use Illuminate\Support\Facades\Cache;
7+
use Illuminate\Support\Facades\Storage;
68

79
beforeEach(function () {
810
Cache::flush();
@@ -11,7 +13,7 @@
1113

1214
it('returns 404 for non-existent files', function () {
1315
/** @var TestCase $this */
14-
$response = $this->get(route('image.transform', [
16+
$response = $this->get(route('image.transform.default', [
1517
'options' => 'width=100',
1618
'path' => 'non-existent.jpg',
1719
]));
@@ -21,7 +23,7 @@
2123

2224
it('returns 404 for non-image files', function () {
2325
/** @var TestCase $this */
24-
$response = $this->get(route('image.transform', [
26+
$response = $this->get(route('image.transform.default', [
2527
'options' => 'width=100',
2628
'path' => 'text.txt',
2729
]));
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use AceOfAces\LaravelImageTransformUrl\Tests\TestCase;
6+
use Illuminate\Support\Facades\Cache;
7+
use Illuminate\Support\Facades\Storage;
8+
9+
beforeEach(function () {
10+
Cache::flush();
11+
Storage::fake(config()->string('image-transform-url.cache.disk'));
12+
Storage::fake('public');
13+
});
14+
15+
it('can serve from the storage directory', function () {
16+
17+
$imagePath = 'images/test.jpg';
18+
Storage::disk('public')->put($imagePath, file_get_contents(__DIR__.'/../../workbench/test-data/cat.jpg'));
19+
20+
$response = $this->get(route('image.transform', [
21+
'options' => 'width=100',
22+
'pathPrefix' => 'storage',
23+
'path' => 'images/test.jpg',
24+
]));
25+
26+
expect($response)->toBeImage([
27+
'width' => 100,
28+
'mime' => 'image/jpeg',
29+
]);
30+
});
31+
32+
it('can use the storage directory as the default source directory', function () {
33+
/** @var TestCase $this */
34+
config()->set('image-transform-url.default_source_directory', 'storage');
35+
36+
$imagePath = 'images/test.jpg';
37+
Storage::disk('public')->put($imagePath, file_get_contents(__DIR__.'/../../workbench/test-data/cat.jpg'));
38+
39+
$response = $this->get(route('image.transform.default', [
40+
'options' => 'width=100',
41+
'path' => 'images/test.jpg',
42+
]));
43+
44+
expect($response)->toBeImage([
45+
'width' => 100,
46+
'mime' => 'image/jpeg',
47+
]);
48+
});

tests/TestCase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use AceOfAces\LaravelImageTransformUrl\Enums\AllowedOptions;
66
use AceOfAces\LaravelImageTransformUrl\LaravelImageTransformUrlServiceProvider;
77
use Illuminate\Contracts\Config\Repository;
8+
use Illuminate\Support\Facades\Storage;
89
use Intervention\Image\Laravel\ServiceProvider as InterventionImageServiceProvider;
910
use Orchestra\Testbench\Concerns\WithWorkbench;
1011
use Orchestra\Testbench\TestCase as Orchestra;
@@ -41,7 +42,11 @@ protected function getEnvironmentSetUp($app)
4142
protected function defineEnvironment($app)
4243
{
4344
tap($app['config'], function (Repository $config) {
44-
$config->set('image-transform-url.public_path', 'test-data');
45+
$config->set('image-transform-url.source_directories', [
46+
'test-data' => public_path('test-data'),
47+
'storage' => Storage::fake('public')->path(''),
48+
]);
49+
$config->set('image-transform-url.default_source_directory', 'test-data');
4550
$config->set('image-transform-url.enabled_options', AllowedOptions::all());
4651
});
4752
}

0 commit comments

Comments
 (0)