|
18 | 18 | use Symfony\Component\HttpClient\Response\MockResponse;
|
19 | 19 | use Symfony\UX\Icons\Exception\IconNotFoundException;
|
20 | 20 | use Symfony\UX\Icons\Iconify;
|
21 |
| -use Symfony\UX\Icons\Svg\Icon; |
22 | 21 |
|
23 | 22 | /**
|
24 | 23 | * @author Simon André <[email protected]>
|
@@ -53,13 +52,7 @@ public function testFetchIcon(): void
|
53 | 52 |
|
54 | 53 | public function testFetchIconThrowsWhenIconSetDoesNotExists(): void
|
55 | 54 | {
|
56 |
| - $iconify = new Iconify( |
57 |
| - cache: new NullAdapter(), |
58 |
| - endpoint: 'https://example.com', |
59 |
| - http: new MockHttpClient([ |
60 |
| - new JsonMockResponse([]), |
61 |
| - ]), |
62 |
| - ); |
| 55 | + $iconify = new Iconify(new NullAdapter(), 'https://example.com', new MockHttpClient(new JsonMockResponse([]))); |
63 | 56 |
|
64 | 57 | $this->expectException(IconNotFoundException::class);
|
65 | 58 | $this->expectExceptionMessage('The icon "bi:heart" does not exist on iconify.design.');
|
@@ -130,50 +123,21 @@ public function testGetMetadata(): void
|
130 | 123 | $this->assertSame('Font Awesome Solid', $metadata['name']);
|
131 | 124 | }
|
132 | 125 |
|
133 |
| - /** |
134 |
| - * @dataProvider provideHttpErrors |
135 |
| - */ |
136 |
| - public function testGetMetadataWhenHttpError(int $code, string $expectedException): void |
137 |
| - { |
138 |
| - $mockClient = $this->createHttpClient([], $code); |
139 |
| - $iconify = new Iconify(new NullAdapter(), 'https://localhost', $mockClient); |
140 |
| - |
141 |
| - $this->expectException($expectedException); |
142 |
| - |
143 |
| - $iconify->metadataFor('foo'); |
144 |
| - } |
145 |
| - |
146 | 126 | public function testFetchSvg(): void
|
147 | 127 | {
|
148 | 128 | $responseFile = __DIR__.'/../Fixtures/Iconify/icon.svg';
|
149 |
| - $client = new MockHttpClient(MockResponse::fromFile($responseFile)); |
| 129 | + $client = new MockHttpClient([ |
| 130 | + JsonMockResponse::fromFile(__DIR__.'/../Fixtures/Iconify/collections.json'), |
| 131 | + MockResponse::fromFile($responseFile), |
| 132 | + ]); |
150 | 133 | $iconify = new Iconify(new NullAdapter(), 'https://localhost', $client);
|
151 | 134 |
|
152 |
| - $svg = $iconify->fetchSvg('foo', 'bar'); |
| 135 | + $svg = $iconify->fetchSvg('fa6-regular', 'bar'); |
153 | 136 |
|
154 | 137 | $this->assertIsString($svg);
|
155 | 138 | $this->stringContains('-.224l.235-.468ZM6.013 2.06c-.649-.1', $svg);
|
156 | 139 | }
|
157 | 140 |
|
158 |
| - /** |
159 |
| - * @dataProvider provideHttpErrors |
160 |
| - */ |
161 |
| - public function testFetchSvgWhenHttpError(int $code, string $expectedException): void |
162 |
| - { |
163 |
| - $mockClient = $this->createHttpClient([], $code); |
164 |
| - $iconify = new Iconify(new NullAdapter(), 'https://localhost', $mockClient); |
165 |
| - |
166 |
| - $this->expectException($expectedException); |
167 |
| - $iconify->fetchSvg('foo', 'bar'); |
168 |
| - } |
169 |
| - |
170 |
| - public static function provideHttpErrors(): iterable |
171 |
| - { |
172 |
| - yield [400, IconNotFoundException::class]; |
173 |
| - yield [404, IconNotFoundException::class]; |
174 |
| - yield [500, IconNotFoundException::class]; |
175 |
| - } |
176 |
| - |
177 | 141 | private function createHttpClient(mixed $data, int $code = 200): MockHttpClient
|
178 | 142 | {
|
179 | 143 | $mockResponse = new JsonMockResponse($data, ['http_code' => $code]);
|
|
0 commit comments