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
82
82
$ height = $ data ['icons ' ][$ name ]['height ' ] ?? $ data ['height ' ] ?? $ this ->sets ()[$ prefix ]['height ' ] ?? null ;
83
83
$ width = $ data ['icons ' ][$ name ]['width ' ] ?? $ data ['width ' ] ?? $ this ->sets ()[$ prefix ]['width ' ] ?? null ;
84
84
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 ;
86
87
}
87
88
88
89
return new Icon ($ data ['icons ' ][$ name ]['body ' ], [
@@ -133,6 +134,11 @@ public function fetchIcons(string $prefix, array $names): array
133
134
$ height = $ iconData ['height ' ] ?? $ data ['height ' ] ??= $ this ->sets ()[$ prefix ]['height ' ] ?? null ;
134
135
$ width = $ iconData ['width ' ] ?? $ data ['width ' ] ??= $ this ->sets ()[$ prefix ]['width ' ] ?? null ;
135
136
137
+ if (null === $ width && null === $ height ) {
138
+ $ height = 16 ;
139
+ $ width = 16 ;
140
+ }
141
+
136
142
$ icons [$ iconName ] = new Icon ($ iconData ['body ' ], [
137
143
'xmlns ' => self ::ATTR_XMLNS_URL ,
138
144
'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()
119
119
$ this ->assertEquals ('0 0 17 17 ' , $ icon ->getAttributes ()['viewBox ' ]);
120
120
}
121
121
122
- public function testFetchIconThrowsWhenViewBoxCannotBeComputed ()
122
+ public function testFetchIconSetsDefaultViewBoxTo16 ()
123
123
{
124
124
$ iconify = new Iconify (
125
125
cache: new NullAdapter (),
@@ -138,10 +138,11 @@ public function testFetchIconThrowsWhenViewBoxCannotBeComputed()
138
138
]),
139
139
);
140
140
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 ' );
143
142
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 ' ]);
145
146
}
146
147
147
148
public function testFetchIconThrowsWhenStatusCodeNot200 ()
You can’t perform that action at this time.
0 commit comments