Passed
Pull Request — master (#45)
by X
02:29
created

xKerman_Restricted_Test_SourceTest::testMatch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @coversDefaultClass \xKerman\Restricted\Source
5
 */
6
class xKerman_Restricted_Test_SourceTest 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...
7
{
8
    /**
9
     * @expectedException InvalidArgumentException
10
     */
11
    public function testConstructFailed()
12
    {
13
        new xKerman_Restricted_Source(2);
14
    }
15
    public function provideConsumeSucceeded()
16
    {
17
        return array(array('input' => 'hello', 'consumption' => 'h'), array('input' => 'hello', 'consumption' => 'he'));
18
    }
19
    /**
20
     * @covers ::consume
21
     * @dataProvider provideConsumeSucceeded
22
     */
23
    public function testConsumeSucceeded($input, $consumption)
24
    {
25
        $source = new xKerman_Restricted_Source($input);
26
        $source->consume($consumption, strlen($consumption));
27
        $this->assertTrue(true);
28
    }
29
    /**
30
     * @expectedException xKerman_Restricted_UnserializeFailedException
31
     */
32
    public function testConsumeFailure()
33
    {
34
        $source = new xKerman_Restricted_Source('hello');
35
        $source->consume('e', strlen('e'));
36
    }
37
    /**
38
     * @covres ::read
39
     */
40
    public function testRead()
41
    {
42
        $source = new xKerman_Restricted_Source('abcdefg');
43
        $actual = $source->read(5);
44
        $this->assertSame('abcde', $actual);
45
    }
46
    public function provideReadFailure()
47
    {
48
        return array(array('input' => 'abc', 'length' => 5), array('input' => 'abc', 'length' => -1));
49
    }
50
    /**
51
     * @covers ::read
52
     * @expectedException xKerman_Restricted_UnserializeFailedException
53
     * @dataProvider provideReadFailure
54
     */
55
    public function testReadFailure($input, $length)
56
    {
57
        $source = new xKerman_Restricted_Source($input);
58
        $source->read($length);
59
    }
60
    /**
61
     * @covers ::match
62
     */
63
    public function testMatch()
64
    {
65
        $source = new xKerman_Restricted_Source('1234hoge');
66
        $result = $source->match('/\\G1([0-9]+)/');
67
        $this->assertSame('234', $result[0]);
68
    }
69
    /**
70
     * @covers ::match
71
     * @expectedException xKerman_Restricted_UnserializeFailedException
72
     */
73
    public function testMatchFailure()
74
    {
75
        $source = new xKerman_Restricted_Source('abcde12345');
76
        $result = $source->match('/\\G\\d/');
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
77
    }
78
}