Completed
Push — master ( f2e7a7...9c404b )
by Victor
01:52
created

TextContentParserTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 1
cbo 6
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanBeCreated() 0 7 1
A testCanBeParsed() 0 7 1
A getLinesArray() 0 9 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: victor
5
 * Date: 10/04/16
6
 * Time: 01:38
7
 */
8
9
namespace Test\DiTesto;
10
11
12
use LazyEight\BasicTypes\Stringy;
13
use LazyEight\DiTesto\Parser\TextContentParser;
14
use LazyEight\DiTesto\ValueObject\FileContent;
15
use LazyEight\DiTesto\ValueObject\TextFile\Line;
16
17
class TextContentParserTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @var string
21
     */
22
    protected $file = './tests/files/urls.txt';
23
24
    /**
25
     * @covers \LazyEight\DiTesto\Parser\TextContentParser::__construct
26
     * @uses \LazyEight\DiTesto\Parser\TextContentParser
27
     * @return \LazyEight\DiTesto\Parser\TextContentParser
28
     */
29
    public function testCanBeCreated()
30
    {
31
        $content = new Stringy(file_get_contents($this->file));
32
        $instance = new TextContentParser(new FileContent($content));
33
        $this->assertInstanceOf(TextContentParser::class, $instance);
34
        return $instance;
35
    }
36
37
    /**
38
     * @covers \LazyEight\DiTesto\Parser\TextContentParser::parse
39
     * @covers \LazyEight\DiTesto\Parser\TextContentParser::getValue
40
     * @covers \LazyEight\DiTesto\Parser\TextContentParser::getLines
41
     * @uses \LazyEight\DiTesto\Parser\TextContentParser
42
     * @depends testCanBeCreated
43
     * @uses \LazyEight\DiTesto\Parser\TextContentParser
44
     * @param \LazyEight\DiTesto\Parser\TextContentParser
45
     */
46
    public function testCanBeParsed(TextContentParser $loader)
47
    {
48
        $content = new Stringy(file_get_contents($this->file));
49
        $textContent = $loader->parse();
50
        $this->assertEquals($textContent->getValue(), $content);
51
        $this->assertArraySubset($this->getLinesArray($content), $textContent->getLines());
52
    }
53
54
    private function getLinesArray(Stringy $content)
55
    {
56
        $linesArr = $content->split('\n');
57
        $linesCount = count($linesArr);
58
        for ($i = 0; $i < $linesCount; $i++) {
59
            $linesArr[$i] = new Line($linesArr[$i]);
60
        }
61
        return $linesArr;
62
    }
63
}
64