@@ -404,4 +404,59 @@ public function provideVersions(): \Generator
404404 '1.0 ' ,
405405 ];
406406 }
407+
408+ /**
409+ * @test
410+ */
411+ public function testDependencyExtractionCanBeDisabled (): void
412+ {
413+ $ expectedDependencies = ['foo ' , 'bar ' , 'baz ' ];
414+ $ expectedVersion = '1.0 ' ;
415+
416+ vfsStream::newFile ('script.asset.json ' )
417+ ->withContent (
418+ json_encode (
419+ [
420+ 'dependencies ' => $ expectedDependencies ,
421+ 'version ' => $ expectedVersion ,
422+ ]
423+ )
424+ )
425+ ->at ($ this ->root );
426+
427+ $ expectedFile = vfsStream::newFile ('script.js ' )->at ($ this ->root );
428+
429+ $ testee = new Script ('script ' , $ expectedFile ->url (), Asset::FRONTEND , false );
430+ $ testee ->withFilePath ($ expectedFile ->url ());
431+
432+ // Dependencies should not be loaded from the .asset.json file
433+ static ::assertEmpty ($ testee ->dependencies ());
434+
435+ // Version is still autodiscovered from file modification time, not from .asset.json
436+ // To verify it's not from .asset.json, we check it's not the expected version
437+ static ::assertNotEquals ($ expectedVersion , $ testee ->version ());
438+ }
439+
440+ /**
441+ * @test
442+ */
443+ public function testDependencyExtractionEnabledByDefault (): void
444+ {
445+ $ expectedDependencies = ['foo ' , 'bar ' , 'baz ' ];
446+
447+ vfsStream::newFile ('script.asset.json ' )
448+ ->withContent (json_encode (['dependencies ' => $ expectedDependencies ]))
449+ ->at ($ this ->root );
450+
451+ $ expectedFile = vfsStream::newFile ('script.js ' )->at ($ this ->root );
452+
453+ $ testee = new Script ('script ' , $ expectedFile ->url ());
454+ $ testee ->withFilePath ($ expectedFile ->url ());
455+
456+ // Should load dependencies by default
457+ static ::assertEqualsCanonicalizing (
458+ $ expectedDependencies ,
459+ $ testee ->dependencies ()
460+ );
461+ }
407462}
0 commit comments