Skip to content

Commit 621f837

Browse files
committed
Added package option strict_mode
- updated dependency on `symfony/asset` to the version `^5.4 || ^6.0` - added the option for the main and nested packages - added assertions in tests
1 parent ec0b763 commit 621f837

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"latte/latte": "^2.5 || ^3.0",
1515
"nette/di": "^3.0.10",
1616
"nette/utils": "^3.2.5",
17-
"symfony/asset": "^4.2 || ^5.0 || ^6.0"
17+
"symfony/asset": "^5.4 || ^6.0"
1818
},
1919
"require-dev": {
2020
"friendsofphp/php-cs-fixer": "^3.13",

src/DI/AssetExtension.php

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function getConfigSchema(): Schema
5151
->before(static fn ($strategy): ?Statement => is_string($strategy) ? new Statement($strategy) : $strategy),
5252
'json_manifest_path' => Expect::string()
5353
->nullable(),
54+
'strict_mode' => Expect::bool(FALSE),
5455
])->assert($assertBasePathAndBaseUrlsCombination, 'You cannot use both \'base_path\' and \'base_urls\' at the same time.')
5556
->assert($assertVersionStrategyAndVersionCombination, 'You cannot use both \'version_strategy\' and \'version\' at the same time.')
5657
->assert($assertVersionStrategyAndJsonManifestPathCombination, 'You cannot use both \'version_strategy\' and \'json_manifest_path\' at the same time.')
@@ -71,6 +72,7 @@ public function getConfigSchema(): Schema
7172
->before(static fn ($strategy): ?Statement => is_string($strategy) ? new Statement($strategy) : $strategy),
7273
'json_manifest_path' => Expect::string()
7374
->nullable(),
75+
'strict_mode' => Expect::bool(FALSE),
7476
'packages' => Expect::arrayOf($packageStructure, 'string'),
7577
])->assert($assertBasePathAndBaseUrlsCombination, 'You cannot use both \'base_path\' and \'base_urls\' at the same time.')
7678
->assert($assertVersionStrategyAndVersionCombination, 'You cannot use both \'version_strategy\' and \'version\' at the same time.')
@@ -156,6 +158,7 @@ private function createVersionStrategy(string $packageName, PackageConfig $confi
156158
if (NULL !== $config->json_manifest_path) {
157159
return new Statement(JsonManifestVersionStrategy::class, [
158160
'manifestPath' => $config->json_manifest_path,
161+
'strictMode' => $config->strict_mode,
159162
]);
160163
}
161164

src/DI/PackageConfig.php

+2
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ class PackageConfig
2121
public ?Statement $version_strategy;
2222

2323
public ?string $json_manifest_path;
24+
25+
public bool $strict_mode;
2426
}

tests/DI/AssertExtensionTest.phpt

+33
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use Symfony\Component\Asset\Packages;
1010
use Symfony\Component\Asset\UrlPackage;
1111
use Symfony\Component\Asset\PathPackage;
1212
use Nette\DI\InvalidConfigurationException;
13+
use Symfony\Component\Asset\Exception\AssetNotFoundException;
1314
use function assert;
1415
use function strpos;
1516

@@ -169,6 +170,38 @@ final class AssertExtensionTest extends TestCase
169170
'/my/image.abc123.png',
170171
'/my/image.abc123.png'
171172
);
173+
174+
# strict mode disabled (by default)
175+
$this->assertPackage(
176+
$packages,
177+
'json_manifest_strategy',
178+
PathPackage::class,
179+
'/missing-image.png',
180+
'/missing-image.png',
181+
'/missing-image.png'
182+
);
183+
184+
$this->assertPackage(
185+
$packages,
186+
'json_manifest_strategy_strict',
187+
PathPackage::class,
188+
'/my/image.abc123.png',
189+
'/my/image.abc123.png'
190+
);
191+
192+
# strict mode enabled
193+
Assert::exception(
194+
fn () => $this->assertPackage(
195+
$packages,
196+
'json_manifest_strategy_strict',
197+
PathPackage::class,
198+
'',
199+
'',
200+
'/missing-image.png'
201+
),
202+
AssetNotFoundException::class,
203+
'Asset "/missing-image.png" not found in manifest "%a%/tests/DI/manifest.json".%A?%'
204+
);
172205
}
173206

174207
public function testAssetsDefaultVersionStrategyAsService(): void

tests/DI/fullFeatured.neon

+3
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,6 @@ asset:
2626
version_strategy: SixtyEightPublishers\Asset\Tests\Fixtures\CustomVersionStrategy('-FOO')
2727
json_manifest_strategy:
2828
json_manifest_path: %cwd%/manifest.json
29+
json_manifest_strategy_strict:
30+
json_manifest_path: %cwd%/manifest.json
31+
strict_mode: yes

0 commit comments

Comments
 (0)