5
5
use PHPUnit \Framework \TestCase ;
6
6
use Symfony \Component \Asset \Packages ;
7
7
use Symfony \WebpackEncoreBundle \Asset \EntrypointLookupInterface ;
8
+ use Symfony \WebpackEncoreBundle \Asset \EntrypointLookupCollection ;
8
9
use Symfony \WebpackEncoreBundle \Asset \TagRenderer ;
9
10
10
11
class TagRendererTest extends TestCase
@@ -15,6 +16,11 @@ public function testRenderScriptTags()
15
16
$ entrypointLookup ->expects ($ this ->once ())
16
17
->method ('getJavaScriptFiles ' )
17
18
->willReturn (['/build/file1.js ' , '/build/file2.js ' ]);
19
+ $ entrypointCollection = $ this ->createMock (EntrypointLookupCollection::class);
20
+ $ entrypointCollection ->expects ($ this ->once ())
21
+ ->method ('getEntrypointLookup ' )
22
+ ->withConsecutive (['_default ' ])
23
+ ->will ($ this ->onConsecutiveCalls ($ entrypointLookup ));
18
24
19
25
$ packages = $ this ->createMock (Packages::class);
20
26
$ packages ->expects ($ this ->exactly (2 ))
@@ -26,7 +32,7 @@ public function testRenderScriptTags()
26
32
->willReturnCallback (function ($ path ) {
27
33
return 'http://localhost:8080 ' .$ path ;
28
34
});
29
- $ renderer = new TagRenderer ($ entrypointLookup , $ packages );
35
+ $ renderer = new TagRenderer ($ entrypointCollection , $ packages );
30
36
31
37
$ output = $ renderer ->renderWebpackScriptTags ('my_entry ' , 'custom_package ' );
32
38
$ this ->assertContains (
@@ -45,19 +51,81 @@ public function testRenderScriptTagsWithBadFilename()
45
51
$ entrypointLookup ->expects ($ this ->once ())
46
52
->method ('getJavaScriptFiles ' )
47
53
->willReturn (['/build/file<"bad_chars.js ' ]);
54
+ $ entrypointCollection = $ this ->createMock (EntrypointLookupCollection::class);
55
+ $ entrypointCollection ->expects ($ this ->once ())
56
+ ->method ('getEntrypointLookup ' )
57
+ ->withConsecutive (['_default ' ])
58
+ ->will ($ this ->onConsecutiveCalls ($ entrypointLookup ));
48
59
49
60
$ packages = $ this ->createMock (Packages::class);
50
61
$ packages ->expects ($ this ->once ())
51
62
->method ('getUrl ' )
52
63
->willReturnCallback (function ($ path ) {
53
64
return 'http://localhost:8080 ' .$ path ;
54
65
});
55
- $ renderer = new TagRenderer ($ entrypointLookup , $ packages );
66
+ $ renderer = new TagRenderer ($ entrypointCollection , $ packages );
56
67
57
68
$ output = $ renderer ->renderWebpackScriptTags ('my_entry ' , 'custom_package ' );
58
69
$ this ->assertContains (
59
70
'<script src="http://localhost:8080/build/file<"bad_chars.js"></script> ' ,
60
71
$ output
61
72
);
62
73
}
74
+
75
+ public function testRenderScriptTagsWithinAnEntryPointCollection ()
76
+ {
77
+ $ entrypointLookup = $ this ->createMock (EntrypointLookupInterface::class);
78
+ $ entrypointLookup ->expects ($ this ->once ())
79
+ ->method ('getJavaScriptFiles ' )
80
+ ->willReturn (['/build/file1.js ' ]);
81
+
82
+ $ secondEntrypointLookup = $ this ->createMock (EntrypointLookupInterface::class);
83
+ $ secondEntrypointLookup ->expects ($ this ->once ())
84
+ ->method ('getJavaScriptFiles ' )
85
+ ->willReturn (['/build/file2.js ' ]);
86
+ $ thirdEntrypointLookup = $ this ->createMock (EntrypointLookupInterface::class);
87
+ $ thirdEntrypointLookup ->expects ($ this ->once ())
88
+ ->method ('getJavaScriptFiles ' )
89
+ ->willReturn (['/build/file3.js ' ]);
90
+
91
+ $ entrypointCollection = $ this ->createMock (EntrypointLookupCollection::class);
92
+ $ entrypointCollection ->expects ($ this ->exactly (3 ))
93
+ ->method ('getEntrypointLookup ' )
94
+ ->withConsecutive (['_default ' ], ['second ' ], ['third ' ])
95
+ ->will ($ this ->onConsecutiveCalls (
96
+ $ entrypointLookup ,
97
+ $ secondEntrypointLookup ,
98
+ $ thirdEntrypointLookup
99
+ ));
100
+
101
+ $ packages = $ this ->createMock (Packages::class);
102
+ $ packages ->expects ($ this ->exactly (3 ))
103
+ ->method ('getUrl ' )
104
+ ->withConsecutive (
105
+ ['/build/file1.js ' , 'custom_package ' ],
106
+ ['/build/file2.js ' , null ],
107
+ ['/build/file3.js ' , 'specific_package ' ]
108
+ )
109
+ ->willReturnCallback (function ($ path ) {
110
+ return 'http://localhost:8080 ' .$ path ;
111
+ });
112
+ $ renderer = new TagRenderer ($ entrypointCollection , $ packages );
113
+
114
+ $ output = $ renderer ->renderWebpackScriptTags ('my_entry ' , 'custom_package ' );
115
+ $ this ->assertContains (
116
+ '<script src="http://localhost:8080/build/file1.js"></script> ' ,
117
+ $ output
118
+ );
119
+ $ output = $ renderer ->renderWebpackScriptTags ('my_entry ' , null , 'second ' );
120
+ $ this ->assertContains (
121
+ '<script src="http://localhost:8080/build/file2.js"></script> ' ,
122
+ $ output
123
+ );
124
+ $ output = $ renderer ->renderWebpackScriptTags ('my_entry ' , 'specific_package ' , 'third ' );
125
+ $ this ->assertContains (
126
+ '<script src="http://localhost:8080/build/file3.js"></script> ' ,
127
+ $ output
128
+ );
129
+ }
130
+
63
131
}
0 commit comments