Completed
Pull Request — develop (#24)
by Ben
06:57 queued 04:18
created

StringBuilderTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 2
dl 0
loc 68
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testConstruction() 0 8 1
A testAppend() 0 5 1
A testIndexOf() 0 7 1
A testInsert() 0 8 1
A testReplace() 0 8 1
A testDeleteCharAt() 0 8 1
A testSubstring() 0 6 1
1
<?php
2
3
use GroupByInc\API\Util\StringBuilder;
4
5
class StringBuilderTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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