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

TextContentParserTest::testCanBeCreated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
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