|
16 | 16 | use Symfony\Component\HttpClient\MockHttpClient;
|
17 | 17 | use Symfony\Component\HttpClient\Response\JsonMockResponse;
|
18 | 18 | use Symfony\UX\Icons\Exception\IconNotFoundException;
|
| 19 | +use Symfony\UX\Icons\Icon; |
19 | 20 | use Symfony\UX\Icons\Iconify;
|
20 | 21 |
|
21 | 22 | /**
|
@@ -162,6 +163,71 @@ public function testFetchIconThrowsWhenStatusCodeNot200(): void
|
162 | 163 | $iconify->fetchIcon('bi', 'heart');
|
163 | 164 | }
|
164 | 165 |
|
| 166 | + public function testFetchIcons(): void |
| 167 | + { |
| 168 | + $iconify = new Iconify( |
| 169 | + cache: new NullAdapter(), |
| 170 | + endpoint: 'https://example.com', |
| 171 | + http: new MockHttpClient([ |
| 172 | + new JsonMockResponse([ |
| 173 | + 'bi' => [], |
| 174 | + ]), |
| 175 | + new JsonMockResponse([ |
| 176 | + 'icons' => [ |
| 177 | + 'heart' => [ |
| 178 | + 'body' => '<path d="M0 0h24v24H0z" fill="none"/>', |
| 179 | + 'height' => 17, |
| 180 | + ], |
| 181 | + 'bar' => [ |
| 182 | + 'body' => '<path d="M0 0h24v24H0z" fill="none"/>', |
| 183 | + 'height' => 17, |
| 184 | + ], |
| 185 | + ], |
| 186 | + ]), |
| 187 | + ]), |
| 188 | + ); |
| 189 | + |
| 190 | + $icons = $iconify->fetchIcons('bi', ['heart', 'bar']); |
| 191 | + |
| 192 | + $this->assertCount(2, $icons); |
| 193 | + $this->assertSame(['heart', 'bar'], array_keys($icons)); |
| 194 | + $this->assertContainsOnlyInstancesOf(Icon::class, $icons); |
| 195 | + } |
| 196 | + |
| 197 | + public function testFetchIconsThrowsWithInvalidIconNames(): void |
| 198 | + { |
| 199 | + $iconify = new Iconify( |
| 200 | + cache: new NullAdapter(), |
| 201 | + endpoint: 'https://example.com', |
| 202 | + http: new MockHttpClient([ |
| 203 | + new JsonMockResponse([ |
| 204 | + 'bi' => [], |
| 205 | + ]), |
| 206 | + ]), |
| 207 | + ); |
| 208 | + |
| 209 | + $this->expectException(\InvalidArgumentException::class); |
| 210 | + |
| 211 | + $iconify->fetchIcons('bi', ['à', 'foo']); |
| 212 | + } |
| 213 | + |
| 214 | + public function testFetchIconsThrowsWithTooManyIcons(): void |
| 215 | + { |
| 216 | + $iconify = new Iconify( |
| 217 | + cache: new NullAdapter(), |
| 218 | + endpoint: 'https://example.com', |
| 219 | + http: new MockHttpClient([ |
| 220 | + new JsonMockResponse([ |
| 221 | + 'bi' => [], |
| 222 | + ]), |
| 223 | + ]), |
| 224 | + ); |
| 225 | + |
| 226 | + $this->expectException(\InvalidArgumentException::class); |
| 227 | + |
| 228 | + $iconify->fetchIcons('bi', array_fill(0, 50, '1234567890')); |
| 229 | + } |
| 230 | + |
165 | 231 | public function testGetMetadata(): void
|
166 | 232 | {
|
167 | 233 | $responseFile = __DIR__.'/../Fixtures/Iconify/collections.json';
|
|
0 commit comments