-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringBuilderTest.php
More file actions
59 lines (43 loc) · 1.48 KB
/
StringBuilderTest.php
File metadata and controls
59 lines (43 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php declare(strict_types=1);
namespace Parable\Query\Tests;
use Parable\Query\QueryException;
use Parable\Query\StringBuilder;
use PHPUnit\Framework\TestCase;
class StringBuilderTest extends TestCase
{
public function testBasicUsageWithDefaultGlue(): void
{
$parts = new StringBuilder();
$parts->add('1');
$parts->add('2');
self::assertSame('1 2', $parts->__toString());
}
public function testFromArray(): void
{
$parts = StringBuilder::fromArray(['1', '2']);
self::assertSame('1 2', $parts->__toString());
}
public function testPrependActuallyPrepends(): void
{
$parts = new StringBuilder();
$parts->add('1');
$parts->add('2');
$parts->prepend('3');
self::assertSame('3 1 2', $parts->__toString());
}
public function testMergeWorksCorrectly(): void
{
$parts1 = StringBuilder::fromArray(['1', '2']);
$parts2 = StringBuilder::fromArray(['3', '4']);
$partsMerged = $parts1->merge($parts2);
self::assertSame('1 2 3 4', $partsMerged->__toString());
}
public function testMergeBreaksWhenDifferentGluesDetected(): void
{
$parts1 = StringBuilder::fromArray(['1', '2'], ' ');
$parts2 = StringBuilder::fromArray(['3', '4'], ',');
$this->expectException(QueryException::class);
$this->expectExceptionMessage('Cannot merge StringBuilder with different glues.');
$parts1->merge($parts2);
}
}