|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use GroupByInc\API\Util\StringBuilder; |
|
4
|
|
|
|
|
5
|
|
|
class StringBuilderTest extends PHPUnit_Framework_TestCase |
|
|
|
|
|
|
6
|
|
|
{ |
|
7
|
|
|
/** @var StringBuilder */ |
|
8
|
|
|
private $builder; |
|
9
|
|
|
|
|
10
|
|
|
public function setUp() |
|
11
|
|
|
{ |
|
12
|
|
|
$this->builder = new StringBuilder("some words"); |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
public function testConstruction() |
|
16
|
|
|
{ |
|
17
|
|
|
$builder = new StringBuilder(); |
|
18
|
|
|
$this->assertEquals("", $builder); |
|
19
|
|
|
|
|
20
|
|
|
$builder = new StringBuilder("test"); |
|
21
|
|
|
$this->assertEquals("test", $builder); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testAppend() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->builder->append(" and")->append(" some")->append(" more"); |
|
27
|
|
|
$this->assertEquals("some words and some more", $this->builder); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testIndexOf() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->assertEquals(0, $this->builder->indexOf("some")); |
|
33
|
|
|
$this->assertEquals(1, $this->builder->indexOf("ome")); |
|
34
|
|
|
$this->assertEquals(6, $this->builder->indexOf("o", 2)); |
|
35
|
|
|
$this->assertEquals(-1, $this->builder->indexOf("whale")); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function testInsert() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->builder->insert(0, "before "); |
|
41
|
|
|
$this->assertEquals("before some words", $this->builder); |
|
42
|
|
|
|
|
43
|
|
|
$this->builder->insert(12, "other "); |
|
44
|
|
|
$this->assertEquals("before some other words", $this->builder); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testReplace() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->builder->replace(0, 4, "a whole bunch of"); |
|
50
|
|
|
$this->assertEquals("a whole bunch of words", $this->builder); |
|
51
|
|
|
|
|
52
|
|
|
$this->builder->replace(0, strlen($this->builder), "solitude"); |
|
53
|
|
|
$this->assertEquals("solitude", $this->builder); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testDeleteCharAt() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->builder->deleteCharAt(0); |
|
59
|
|
|
$this->assertEquals("ome words", $this->builder); |
|
60
|
|
|
|
|
61
|
|
|
$this->builder->deleteCharAt(4); |
|
62
|
|
|
$this->assertEquals("ome ords", $this->builder); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function testSubstring() |
|
66
|
|
|
{ |
|
67
|
|
|
$this->assertEquals("some words", $this->builder->substring(0, strlen($this->builder))); |
|
68
|
|
|
$this->assertEquals("some", $this->builder->substring(0, 4)); |
|
69
|
|
|
$this->assertEquals("words", $this->builder->substring(5)); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.