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
|
|
|
|