Skip to content

Commit 464d873

Browse files
committed
enhancing test
1 parent d540035 commit 464d873

File tree

3 files changed

+26
-19
lines changed

3 files changed

+26
-19
lines changed

src/Symfony/Component/AssetMapper/Tests/ImportMap/ImportMapVersionChecker.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ private function isVersionSatisfied(string $versionConstraint, ?string $version)
119119

120120
private function extractPackageNameFromImport(string $importName): string
121121
{
122-
// TODO: remove duplication from JsDelivrEsmResolver?
123122
$i = strpos($importName, '/');
124123
if ($i && (!str_starts_with($importName, '@') || $i = strpos($importName, '/', $i + 1))) {
125124
return substr($importName, 0, $i);

src/Symfony/Component/AssetMapper/Tests/ImportMap/RemotePackageDownloaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testDownloadPackagesDownloadsEverythingWithNoInstalled()
6262
->willReturn([
6363
'foo' => ['content' => 'foo content', 'dependencies' => []],
6464
'bar.js/file' => ['content' => 'bar content', 'dependencies' => []],
65-
'baz' => ['content' => 'baz content', 'dependencies' => []],
65+
'baz' => ['content' => 'baz content', 'dependencies' => ['foo']],
6666
]);
6767

6868
$downloader = new RemotePackageDownloader(
@@ -84,7 +84,7 @@ public function testDownloadPackagesDownloadsEverythingWithNoInstalled()
8484
[
8585
'foo' => ['path' => 'foo.js', 'version' => '1.0.0', 'dependencies' => []],
8686
'bar.js/file' => ['path' => 'bar.js/file.js', 'version' => '1.0.0', 'dependencies' => []],
87-
'baz' => ['path' => 'baz.css', 'version' => '1.0.0', 'dependencies' => []],
87+
'baz' => ['path' => 'baz.css', 'version' => '1.0.0', 'dependencies' => ['foo']],
8888
],
8989
$installed
9090
);

src/Symfony/Component/AssetMapper/Tests/ImportMap/Resolver/JsDelivrEsmResolverTest.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public static function provideResolvePackagesTests(): iterable
268268
/**
269269
* @dataProvider provideDownloadPackagesTests
270270
*/
271-
public function testDownloadPackages(array $importMapEntries, array $expectedRequests, array $expectedContents)
271+
public function testDownloadPackages(array $importMapEntries, array $expectedRequests, array $expectedReturn, array $expectedDependencies = [])
272272
{
273273
$responses = [];
274274
foreach ($expectedRequests as $expectedRequest) {
@@ -284,14 +284,13 @@ public function testDownloadPackages(array $importMapEntries, array $expectedReq
284284

285285
$provider = new JsDelivrEsmResolver($httpClient);
286286
$actualReturn = $provider->downloadPackages($importMapEntries);
287-
$this->assertCount(\count($expectedContents), $actualReturn);
288287

289-
$actualContents = [];
290-
foreach ($actualReturn as $package => $data) {
291-
$actualContents[$package] = trim($data['content']);
288+
foreach ($actualReturn as $key => $data) {
289+
$actualReturn[$key]['content'] = trim($data['content']);
292290
}
291+
$this->assertCount(\count($expectedReturn), $actualReturn);
293292

294-
$this->assertSame($expectedContents, $actualContents);
293+
$this->assertSame($expectedReturn, $actualReturn);
295294
$this->assertSame(\count($expectedRequests), $httpClient->getRequestsCount());
296295
}
297296

@@ -306,7 +305,7 @@ public static function provideDownloadPackagesTests()
306305
],
307306
],
308307
[
309-
'lodash' => 'lodash contents',
308+
'lodash' => ['content' => 'lodash contents', 'dependencies' => []],
310309
],
311310
];
312311

@@ -319,7 +318,7 @@ public static function provideDownloadPackagesTests()
319318
],
320319
],
321320
[
322-
'lodash' => 'chart.js contents',
321+
'lodash' => ['content' => 'chart.js contents', 'dependencies' => []],
323322
],
324323
];
325324

@@ -332,7 +331,7 @@ public static function provideDownloadPackagesTests()
332331
],
333332
],
334333
[
335-
'lodash' => 'bootstrap.css contents',
334+
'lodash' => ['content' => 'bootstrap.css contents', 'dependencies' => []],
336335
],
337336
];
338337

@@ -357,9 +356,9 @@ public static function provideDownloadPackagesTests()
357356
],
358357
],
359358
[
360-
'lodash' => 'lodash contents',
361-
'chart.js/auto' => 'chart.js contents',
362-
'bootstrap/dist/bootstrap.css' => 'bootstrap.css contents',
359+
'lodash' => ['content' => 'lodash contents', 'dependencies' => []],
360+
'chart.js/auto' => ['content' => 'chart.js contents', 'dependencies' => []],
361+
'bootstrap/dist/bootstrap.css' => ['content' => 'bootstrap.css contents', 'dependencies' => []],
363362
],
364363
];
365364

@@ -374,11 +373,14 @@ public static function provideDownloadPackagesTests()
374373
],
375374
],
376375
[
377-
'@chart.js/auto' => 'import{Color as t}from"@kurkle/color";function e(){}const i=(()=',
376+
'@chart.js/auto' => [
377+
'content' => 'import{Color as t}from"@kurkle/color";function e(){}const i=(()=',
378+
'dependencies' => ['@kurkle/color']
379+
],
378380
],
379381
];
380382

381-
yield 'js importmap is removed' => [
383+
yield 'js sourcemap is removed' => [
382384
[
383385
'@chart.js/auto' => new ImportMapEntry('chart.js/auto', version: '1.2.3'),
384386
],
@@ -390,7 +392,10 @@ public static function provideDownloadPackagesTests()
390392
],
391393
],
392394
[
393-
'@chart.js/auto' => 'as Ticks,ta as TimeScale,ia as TimeSeriesScale,oo as Title,wo as Tooltip,Ci as _adapters,us as _detectPlatform,Ye as animator,Si as controllers,tn as default,St as defaults,Pn as elements,qi as layouts,ko as plugins,na as registerables,Ps as registry,sa as scales};',
395+
'@chart.js/auto' => [
396+
'content' => 'as Ticks,ta as TimeScale,ia as TimeSeriesScale,oo as Title,wo as Tooltip,Ci as _adapters,us as _detectPlatform,Ye as animator,Si as controllers,tn as default,St as defaults,Pn as elements,qi as layouts,ko as plugins,na as registerables,Ps as registry,sa as scales};',
397+
'dependencies' => [],
398+
],
394399
],
395400
];
396401

@@ -404,7 +409,10 @@ public static function provideDownloadPackagesTests()
404409
],
405410
],
406411
[
407-
'lodash' => 'print-table-row{display:table-row!important}.d-print-table-cell{display:table-cell!important}.d-print-flex{display:flex!important}.d-print-inline-flex{display:inline-flex!important}.d-print-none{display:none!important}}',
412+
'lodash' => [
413+
'content' => 'print-table-row{display:table-row!important}.d-print-table-cell{display:table-cell!important}.d-print-flex{display:flex!important}.d-print-inline-flex{display:inline-flex!important}.d-print-none{display:none!important}}',
414+
'dependencies' => [],
415+
],
408416
],
409417
];
410418
}

0 commit comments

Comments
 (0)