Completed
Pull Request — develop (#27)
by Chris
12:16
created

StreamTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 48
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testRead() 0 6 1
A testReadEmptyLine() 0 6 1
A testReadSameLine() 0 4 1
A testWrite() 0 6 1
A dataProvider() 0 8 1
A createStream() 0 4 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Tests\Stream;
4
5
use PHPUnit\Framework\TestCase;
6
use Chrisyue\PhpM3u8\Stream\AbstractStream;
7
8
class StreamTest extends TestCase
9
{
10
    /**
11
     * @dataProvider dataProvider
12
     */
13
    public function testRead($line, $info)
14
    {
15
        $stream = $this->createStream();
16
        $stream->method('getLine')->willReturn($line);
17
        $this->assertSame($info, $stream->read());
18
    }
19
20
    public function testReadEmptyLine()
21
    {
22
        $stream = $this->createStream();
23
        $stream->method('getLine')->willReturn('  ');
24
        $this->assertNull($stream->read());
25
    }
26
27
    public function testReadSameLine()
28
    {
29
        $stream = $this->createStream();
0 ignored issues
show
Unused Code introduced by
$stream 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...
30
    }
31
32
    /**
33
     * @dataProvider dataProvider
34
     */
35
    public function testWrite($line, $info)
36
    {
37
        $stream = $this->createStream();
38
        $stream->method('putLine')->with($this->equalTo($line));
39
        $stream->write($info);
40
    }
41
42
    public function dataProvider()
43
    {
44
        return [
45
            ['#TAG:VALUE', ['tag' => '#TAG', 'value' => 'VALUE']],
46
            ['#TAG', ['tag' => '#TAG', 'value' => '']],
47
            ['VALUE', ['value' => 'VALUE']],
48
        ];
49
    }
50
51
    private function createStream()
52
    {
53
        return $this->getMockForAbstractClass(AbstractStream::class);
54
    }
55
}
56