Skip to content

Commit 6fbe53a

Browse files
committed
feat: add layout factory
1 parent c6724a9 commit 6fbe53a

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/Html/Layout.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ class Layout extends Fluent
1111
{
1212
use Macroable;
1313

14+
public static function make(array $options = []): static
15+
{
16+
return new static($options);
17+
}
18+
1419
public function topStart(string|array|null $options, int $order = 0): static
1520
{
1621
return $this->top($options, $order, 'Start');

tests/LayoutTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,49 @@ public function it_can_be_used_in_builder(): void
8282
$this->assertArrayHasKey('top1End', $builder->getAttributes()['layout']);
8383
$this->assertArrayHasKey('bottom1End', $builder->getAttributes()['layout']);
8484
}
85+
86+
#[Test]
87+
public function it_has_factory_method(): void
88+
{
89+
$layout = Layout::make();
90+
$this->assertInstanceOf(Layout::class, $layout);
91+
92+
$builder = resolve(Builder::class);
93+
$builder->layout(Layout::make());
94+
95+
$this->assertArrayHasKey('layout', $builder->getAttributes());
96+
}
97+
98+
#[Test]
99+
public function it_can_be_macroable(): void
100+
{
101+
Layout::macro('test', fn () => 'test');
102+
103+
$layout = new Layout;
104+
$this->assertEquals('test', $layout->test());
105+
}
106+
107+
#[Test]
108+
public function it_can_accept_array(): void
109+
{
110+
$layout = new Layout(['top' => 'test']);
111+
$this->assertEquals('test', $layout->get('top'));
112+
}
113+
114+
#[Test]
115+
public function it_can_accept_array_as_parameter(): void
116+
{
117+
$layout = Layout::make(['top' => 'test']);
118+
$this->assertEquals('test', $layout->get('top'));
119+
}
120+
121+
#[Test]
122+
public function it_can_accept_array_as_parameter_in_builder(): void
123+
{
124+
$builder = resolve(Builder::class);
125+
$builder->layout(['top' => 'test']);
126+
127+
$this->assertArrayHasKey('layout', $builder->getAttributes());
128+
$this->assertArrayHasKey('top', $builder->getAttributes()['layout']);
129+
}
85130
}

0 commit comments

Comments
 (0)