File: ImportMapEntryTest.php

package info (click to toggle)
symfony 7.3.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 148,424 kB
  • sloc: php: 1,510,651; xml: 7,039; javascript: 979; sh: 586; makefile: 242; pascal: 70
file content (83 lines) | stat: -rw-r--r-- 2,815 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Symfony\Component\AssetMapper\Tests\ImportMap;

use PHPUnit\Framework\TestCase;
use Symfony\Component\AssetMapper\ImportMap\ImportMapEntry;
use Symfony\Component\AssetMapper\ImportMap\ImportMapType;

class ImportMapEntryTest extends TestCase
{
    public function testCreateLocal()
    {
        $entry = ImportMapEntry::createLocal('foo', ImportMapType::JS, 'foo.js', true);
        $this->assertSame('foo', $entry->importName);
        $this->assertSame(ImportMapType::JS, $entry->type);
        $this->assertSame('foo.js', $entry->path);
        $this->assertTrue($entry->isEntrypoint);
        $this->assertFalse($entry->isRemotePackage());
    }

    public function testCreateRemote()
    {
        $entry = ImportMapEntry::createRemote('foo', ImportMapType::JS, 'foo.js', '1.0.0', 'foo/bar', true);
        $this->assertSame('foo', $entry->importName);
        $this->assertSame(ImportMapType::JS, $entry->type);
        $this->assertSame('foo.js', $entry->path);
        $this->assertTrue($entry->isEntrypoint);
        $this->assertTrue($entry->isRemotePackage());
        $this->assertSame('1.0.0', $entry->version);
        $this->assertSame('foo/bar', $entry->packageModuleSpecifier);
    }

    #[\PHPUnit\Framework\Attributes\DataProvider('getSplitPackageNameTests')]
    public function testSplitPackageNameAndFilePath(string $packageModuleSpecifier, string $expectedPackage, string $expectedPath)
    {
        [$actualPackage, $actualPath] = ImportMapEntry::splitPackageNameAndFilePath($packageModuleSpecifier);
        $this->assertSame($expectedPackage, $actualPackage);
        $this->assertSame($expectedPath, $actualPath);
    }

    public static function getSplitPackageNameTests()
    {
        yield 'package-name' => [
            'package-name',
            'package-name',
            '',
        ];

        yield 'package-name/path' => [
            'package-name/path',
            'package-name',
            '/path',
        ];

        yield '@scope/package-name' => [
            '@scope/package-name',
            '@scope/package-name',
            '',
        ];

        yield '@scope/package-name/path' => [
            '@scope/package-name/path',
            '@scope/package-name',
            '/path',
        ];
    }

    public function testGetPackageNameAndPackagePath()
    {
        $entry = ImportMapEntry::createRemote('foo', ImportMapType::JS, 'foo.js', '1.0.0', 'foo/bar', true);
        $this->assertSame('foo', $entry->getPackageName());
        $this->assertSame('/bar', $entry->getPackagePathString());
    }
}