File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -82,7 +82,8 @@ public function fetchIcon(string $prefix, string $name): Icon
8282 $ height = $ data ['icons ' ][$ name ]['height ' ] ?? $ data ['height ' ] ?? $ this ->sets ()[$ prefix ]['height ' ] ?? null ;
8383 $ width = $ data ['icons ' ][$ name ]['width ' ] ?? $ data ['width ' ] ?? $ this ->sets ()[$ prefix ]['width ' ] ?? null ;
8484 if (null === $ width && null === $ height ) {
85- throw new \RuntimeException (\sprintf ('The icon "%s:%s" does not have a width or height. ' , $ prefix , $ nameArg ));
85+ $ height = 16 ;
86+ $ width = 16 ;
8687 }
8788
8889 return new Icon ($ data ['icons ' ][$ name ]['body ' ], [
@@ -133,6 +134,11 @@ public function fetchIcons(string $prefix, array $names): array
133134 $ height = $ iconData ['height ' ] ?? $ data ['height ' ] ??= $ this ->sets ()[$ prefix ]['height ' ] ?? null ;
134135 $ width = $ iconData ['width ' ] ?? $ data ['width ' ] ??= $ this ->sets ()[$ prefix ]['width ' ] ?? null ;
135136
137+ if (null === $ width && null === $ height ) {
138+ $ height = 16 ;
139+ $ width = 16 ;
140+ }
141+
136142 $ icons [$ iconName ] = new Icon ($ iconData ['body ' ], [
137143 'xmlns ' => self ::ATTR_XMLNS_URL ,
138144 'viewBox ' => \sprintf ('0 0 %d %d ' , $ width ?? $ height , $ height ?? $ width ),
Original file line number Diff line number Diff line change @@ -119,7 +119,7 @@ public function testFetchIconUsesIconsetViewBoxHeight()
119119 $ this ->assertEquals ('0 0 17 17 ' , $ icon ->getAttributes ()['viewBox ' ]);
120120 }
121121
122- public function testFetchIconThrowsWhenViewBoxCannotBeComputed ()
122+ public function testFetchIconSetsDefaultViewBoxTo16 ()
123123 {
124124 $ iconify = new Iconify (
125125 cache: new NullAdapter (),
@@ -138,10 +138,11 @@ public function testFetchIconThrowsWhenViewBoxCannotBeComputed()
138138 ]),
139139 );
140140
141- $ this ->expectException (\RuntimeException::class);
142- $ this ->expectExceptionMessage ('The icon "bi:heart" does not have a width or height. ' );
141+ $ icon = $ iconify ->fetchIcon ('bi ' , 'heart ' );
143142
144- $ iconify ->fetchIcon ('bi ' , 'heart ' );
143+ $ this ->assertIsArray ($ icon ->getAttributes ());
144+ $ this ->assertArrayHasKey ('viewBox ' , $ icon ->getAttributes ());
145+ $ this ->assertEquals ('0 0 16 16 ' , $ icon ->getAttributes ()['viewBox ' ]);
145146 }
146147
147148 public function testFetchIconThrowsWhenStatusCodeNot200 ()
You can’t perform that action at this time.
0 commit comments