Skip to content

Commit 69800b7

Browse files
authored
Merge pull request #16 from 8fold/custom-properties-in-doctype
Feature: Concatenate
2 parents 1d6f197 + 88b2ae7 commit 69800b7

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

src/Concatenate.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace Eightfold\XMLBuilder;
5+
6+
use Eightfold\XMLBuilder\Contracts\Buildable;
7+
8+
use Stringable;
9+
10+
use Eightfold\XMLBuilder\Implementations\Buildable as BuildableImp;
11+
12+
class Concatenate implements Buildable
13+
{
14+
use BuildableImp;
15+
16+
/**
17+
* @var array<string|Stringable>
18+
*/
19+
private array $content = [];
20+
21+
public static function create(string|Stringable ...$content): self
22+
{
23+
return new self(...$content);
24+
}
25+
26+
final private function __construct(string|Stringable ...$content)
27+
{
28+
$this->content = $content;
29+
}
30+
31+
public function __toString(): string
32+
{
33+
return implode('', $this->content);
34+
}
35+
}

src/Implementations/Contentable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait Contentable
1414
private array $content = [];
1515

1616
/**
17-
* @param array<string|String> $content
17+
* @param array<string|Stringable> $content
1818
*/
1919
public static function __callStatic(
2020
string $name,

tests/ConcatenateBaselineTest.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Eightfold\XMLBuilder\Tests;
6+
7+
use PHPUnit\Framework\TestCase;
8+
9+
use Eightfold\XMLBuilder\Concatenate;
10+
11+
use Eightfold\XMLBuilder\Element;
12+
13+
class ConcatenateBaselineTest extends TestCase
14+
{
15+
/**
16+
* @test
17+
*/
18+
public function concatenate_expected_content(): void
19+
{
20+
$expected = '<p>Hello, World!</p> Testing additional string.';
21+
22+
$result = (string) Concatenate::create(
23+
Element::p('Hello, World!'),
24+
' Testing additional string.'
25+
);
26+
27+
$this->assertSame(
28+
$expected,
29+
$result
30+
);
31+
}
32+
}

0 commit comments

Comments
 (0)