diff --git a/src/Node/Block/MediaSingle.php b/src/Node/Block/MediaSingle.php index d14802e..824657f 100644 --- a/src/Node/Block/MediaSingle.php +++ b/src/Node/Block/MediaSingle.php @@ -57,7 +57,11 @@ public static function load(array $data, ?BlockNode $parent = null): self self::checkNodeData(static::class, $data, ['attrs']); self::checkRequiredKeys(['layout'], $data['attrs']); - $node = new self($data['attrs']['layout'], $data['attrs']['width'] ?? null, $parent); + $node = new self( + $data['attrs']['layout'], + isset($data['attrs']['width']) ? (int) $data['attrs']['width'] : null, + $parent + ); // set content if defined if (\array_key_exists('content', $data)) { diff --git a/tests/Node/Block/MediaSingleTest.php b/tests/Node/Block/MediaSingleTest.php index 225887a..ac1dc5c 100644 --- a/tests/Node/Block/MediaSingleTest.php +++ b/tests/Node/Block/MediaSingleTest.php @@ -48,4 +48,19 @@ public function testEmptyMediaSingleWithWidth(): void ], ])); } + + public function testWidthWithFloatValue(): void + { + $json = [ + 'type' => 'mediaSingle', + 'content' => [], + 'attrs' => [ + 'layout' => 'wrap-left', + 'width' => 80.5, + ], + ]; + + $doc = MediaSingle::load($json); + $this->assertInstanceOf(MediaSingle::class, $doc); + } }