26
26
27
27
class MappedAssetFactoryTest extends TestCase
28
28
{
29
- private const DEFAULT_FIXTURES = __DIR__ .'/../Fixtures/assets/vendor ' ;
29
+ private const FIXTURES_DIR = __DIR__ .'/../Fixtures ' ;
30
+ private const VENDOR_FIXTURES_DIR = self ::FIXTURES_DIR .'/assets/vendor ' ;
30
31
31
32
private AssetMapperInterface &MockObject $ assetMapper ;
32
33
33
34
public function testCreateMappedAsset ()
34
35
{
35
36
$ factory = $ this ->createFactory ();
36
37
37
- $ asset = $ factory ->createMappedAsset ('file2.js ' , __DIR__ . ' /../Fixtures /dir1/file2.js ' );
38
+ $ asset = $ factory ->createMappedAsset ('file2.js ' , self :: FIXTURES_DIR . ' /dir1/file2.js ' );
38
39
$ this ->assertSame ('file2.js ' , $ asset ->logicalPath );
39
40
$ this ->assertMatchesRegularExpression ('/^\/final-assets\/file2-[a-zA-Z0-9]{7,128}\.js$/ ' , $ asset ->publicPath );
40
41
$ this ->assertSame ('/final-assets/file2.js ' , $ asset ->publicPathWithoutDigest );
@@ -43,7 +44,7 @@ public function testCreateMappedAsset()
43
44
public function testCreateMappedAssetRespectsPreDigestedPaths ()
44
45
{
45
46
$ assetMapper = $ this ->createFactory ();
46
- $ asset = $ assetMapper ->createMappedAsset ('already-abcdefVWXYZ0123456789.digested.css ' , __DIR__ . ' /../Fixtures /dir2/already-abcdefVWXYZ0123456789.digested.css ' );
47
+ $ asset = $ assetMapper ->createMappedAsset ('already-abcdefVWXYZ0123456789.digested.css ' , self :: FIXTURES_DIR . ' /dir2/already-abcdefVWXYZ0123456789.digested.css ' );
47
48
$ this ->assertSame ('already-abcdefVWXYZ0123456789.digested.css ' , $ asset ->logicalPath );
48
49
$ this ->assertSame ('/final-assets/already-abcdefVWXYZ0123456789.digested.css ' , $ asset ->publicPath );
49
50
// for pre-digested files, the digest *is* part of the public path
@@ -67,18 +68,18 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
67
68
$ assetMapper = $ this ->createFactory ($ file1Compiler );
68
69
$ expected = 'totally changed ' ;
69
70
70
- $ asset = $ assetMapper ->createMappedAsset ('file1.css ' , __DIR__ . ' /../Fixtures /dir1/file1.css ' );
71
+ $ asset = $ assetMapper ->createMappedAsset ('file1.css ' , self :: FIXTURES_DIR . ' /dir1/file1.css ' );
71
72
$ this ->assertSame ($ expected , $ asset ->content );
72
73
73
74
// verify internal caching doesn't cause issues
74
- $ asset = $ assetMapper ->createMappedAsset ('file1.css ' , __DIR__ . ' /../Fixtures /dir1/file1.css ' );
75
+ $ asset = $ assetMapper ->createMappedAsset ('file1.css ' , self :: FIXTURES_DIR . ' /dir1/file1.css ' );
75
76
$ this ->assertSame ($ expected , $ asset ->content );
76
77
}
77
78
78
79
public function testCreateMappedAssetWithContentThatDoesNotChange ()
79
80
{
80
81
$ assetMapper = $ this ->createFactory ();
81
- $ asset = $ assetMapper ->createMappedAsset ('file1.css ' , __DIR__ . ' /../Fixtures /dir1/file1.css ' );
82
+ $ asset = $ assetMapper ->createMappedAsset ('file1.css ' , self :: FIXTURES_DIR . ' /dir1/file1.css ' );
82
83
// null content because the final content matches the file source
83
84
$ this ->assertNull ($ asset ->content );
84
85
}
@@ -89,7 +90,7 @@ public function testCreateMappedAssetWithContentErrorsOnCircularReferences()
89
90
90
91
$ this ->expectException (CircularAssetsException::class);
91
92
$ this ->expectExceptionMessage ('Circular reference detected while creating asset for "circular1.css": "circular1.css -> circular2.css -> circular1.css". ' );
92
- $ factory ->createMappedAsset ('circular1.css ' , __DIR__ . ' /../Fixtures /circular_dir/circular1.css ' );
93
+ $ factory ->createMappedAsset ('circular1.css ' , self :: FIXTURES_DIR . ' /circular_dir/circular1.css ' );
93
94
}
94
95
95
96
public function testCreateMappedAssetWithDigest ()
@@ -111,43 +112,43 @@ public function compile(string $content, MappedAsset $asset, AssetMapperInterfac
111
112
};
112
113
113
114
$ factory = $ this ->createFactory ();
114
- $ asset = $ factory ->createMappedAsset ('subdir/file6.js ' , __DIR__ . ' /../Fixtures /dir2/subdir/file6.js ' );
115
+ $ asset = $ factory ->createMappedAsset ('subdir/file6.js ' , self :: FIXTURES_DIR . ' /dir2/subdir/file6.js ' );
115
116
$ this ->assertSame ('7f983f4053a57f07551fed6099c0da4e ' , $ asset ->digest );
116
117
$ this ->assertFalse ($ asset ->isPredigested );
117
118
118
119
// trigger the compiler, which will change file5.js
119
120
// since file6.js imports file5.js, the digest for file6 should change,
120
121
// because, internally, the file path in file6.js to file5.js will need to change
121
122
$ factory = $ this ->createFactory ($ file6Compiler );
122
- $ asset = $ factory ->createMappedAsset ('subdir/file6.js ' , __DIR__ . ' /../Fixtures /dir2/subdir/file6.js ' );
123
+ $ asset = $ factory ->createMappedAsset ('subdir/file6.js ' , self :: FIXTURES_DIR . ' /dir2/subdir/file6.js ' );
123
124
$ this ->assertSame ('7e4f24ebddd4ab2a3bcf0d89270b9f30 ' , $ asset ->digest );
124
125
}
125
126
126
127
public function testCreateMappedAssetWithPredigested ()
127
128
{
128
129
$ assetMapper = $ this ->createFactory ();
129
- $ asset = $ assetMapper ->createMappedAsset ('already-abcdefVWXYZ0123456789.digested.css ' , __DIR__ . ' /../Fixtures /dir2/already-abcdefVWXYZ0123456789.digested.css ' );
130
+ $ asset = $ assetMapper ->createMappedAsset ('already-abcdefVWXYZ0123456789.digested.css ' , self :: FIXTURES_DIR . ' /dir2/already-abcdefVWXYZ0123456789.digested.css ' );
130
131
$ this ->assertSame ('abcdefVWXYZ0123456789.digested ' , $ asset ->digest );
131
132
$ this ->assertTrue ($ asset ->isPredigested );
132
133
}
133
134
134
135
public function testCreateMappedAssetInVendor ()
135
136
{
136
137
$ assetMapper = $ this ->createFactory ();
137
- $ asset = $ assetMapper ->createMappedAsset ('lodash.js ' , __DIR__ . ' /../Fixtures/assets/vendor /lodash/lodash.index.js ' );
138
+ $ asset = $ assetMapper ->createMappedAsset ('lodash.js ' , self :: VENDOR_FIXTURES_DIR . ' /lodash/lodash.index.js ' );
138
139
$ this ->assertSame ('lodash.js ' , $ asset ->logicalPath );
139
140
$ this ->assertTrue ($ asset ->isVendor );
140
141
}
141
142
142
143
public function testCreateMappedAssetInMissingVendor ()
143
144
{
144
145
$ assetMapper = $ this ->createFactory (null , '/this-path-does-not-exist/ ' );
145
- $ asset = $ assetMapper ->createMappedAsset ('lodash.js ' , __DIR__ . ' /../Fixtures/assets/vendor /lodash/lodash.index.js ' );
146
+ $ asset = $ assetMapper ->createMappedAsset ('lodash.js ' , self :: VENDOR_FIXTURES_DIR . ' /lodash/lodash.index.js ' );
146
147
$ this ->assertSame ('lodash.js ' , $ asset ->logicalPath );
147
148
$ this ->assertFalse ($ asset ->isVendor );
148
149
}
149
150
150
- private function createFactory (?AssetCompilerInterface $ extraCompiler = null , ?string $ vendorDir = self ::DEFAULT_FIXTURES ): MappedAssetFactory
151
+ private function createFactory (?AssetCompilerInterface $ extraCompiler = null , ?string $ vendorDir = self ::VENDOR_FIXTURES_DIR ): MappedAssetFactory
151
152
{
152
153
$ compilers = [
153
154
new JavaScriptImportPathCompiler ($ this ->createMock (ImportMapConfigReader::class)),
0 commit comments