Skip to content
This repository was archived by the owner on Dec 25, 2023. It is now read-only.

Commit 4af88ae

Browse files
committed
add cast of Item to CSS
1 parent ced6b28 commit 4af88ae

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/DTO/Item.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,14 @@ public function toArray(): array
4141
'left' => $this->left,
4242
];
4343
}
44+
45+
/**
46+
* Return the css string used to place the box.
47+
*
48+
* @return string
49+
*/
50+
public function toCSS(): string
51+
{
52+
return sprintf("top: %dpx; width: %dpx; height: %dpx; left: %dpx;", $this->top, $this->width, $this->height, $this->left);
53+
}
4454
}

tests/PhpFlickrJustifiedLayout/ItemTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use PHPUnit\Framework\TestCase;
88

9-
use function Safe\json_encode;
10-
119
class ItemTest extends TestCase
1210
{
1311

@@ -16,18 +14,20 @@ public function testArray(): void
1614
$item = new Item(
1715
aspectRatio: 1,
1816
width: 340,
19-
height: 340,
17+
height: 350,
2018
top: 10,
21-
left: 10
19+
left: 20
2220
);
2321

2422
self::assertEquals([
2523
"aspectRatio" => 1,
2624
"top" => 10,
2725
"width" => 340,
28-
"height" => 340,
29-
"left" => 10
26+
"height" => 350,
27+
"left" => 20
3028
], $item->toArray()
3129
);
30+
31+
self::assertEquals("top: 10px; width: 340px; height: 350px; left: 20px;", $item->toCSS());
3232
}
3333
}

0 commit comments

Comments
 (0)