FileReaderTest::testCanRead()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Test\DiTesto;
4
5
use LazyEight\DiTesto\FileSystem\Exceptions\FileSystemException;
6
use LazyEight\DiTesto\FileSystem\FileSystemHandler;
7
use LazyEight\DiTesto\TextFile;
8
use LazyEight\DiTesto\FileReader;
9
use PHPUnit\Framework\TestCase;
10
11
class FileReaderTest extends TestCase
12
{
13
    /**
14
     * @var string
15
     */
16
    protected $file = './tests/files/urls.txt';
17
18
    /**
19
     * @var string
20
     */
21
    protected $imageFile = './tests/files/images.jpg';
22
23
    /**
24
     * @var string
25
     */
26
    protected $notReadable = './tests/files/urls_not_readable.txt';
27
28
    /**
29
     * @covers \LazyEight\DiTesto\FileReader::__construct
30
     * @covers \LazyEight\DiTesto\FileReader::readFile
31
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::readable
32
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::read
33
     * @uses \LazyEight\DiTesto\FileReader
34
     * @uses \LazyEight\DiTesto\FileReader
35
     * @param \LazyEight\DiTesto\TextFileLoader
36
     */
37
    public function testCanRead()
38
    {
39
        $textFile = new TextFile($this->file);
40
        (new FileReader($textFile, new FileSystemHandler($textFile->getPath())))->readFile();
41
42
        $arrFile = explode(PHP_EOL, file_get_contents($this->file));
43
        $this->assertTrue(count($arrFile) === count($textFile));
44
    }
45
46
    /**
47
     * @covers \LazyEight\DiTesto\FileReader::readFile
48
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::readable
49
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::read
50
     * @expectedException \LazyEight\DiTesto\FileSystem\Exceptions\FileSystemException
51
     * @uses \LazyEight\DiTesto\FileReader
52
     */
53
    public function testCantBeLoaded()
54
    {
55
        $this->expectException(\Throwable::class);
56
        (new FileReader(new TextFile(''), new FileSystemHandler('')))->readFile();
57
    }
58
59
    /**
60
     * @covers \LazyEight\DiTesto\FileReader::readFile
61
     * @expectedException \LazyEight\DiTesto\FileSystem\Exceptions\FileSystemException
62
     */
63
    public function testCantRead()
64
    {
65
        chmod($this->notReadable, 0000);
66
67
        $this->expectException(FileSystemException::class);
68
        (new FileReader(new TextFile($this->notReadable), new FileSystemHandler($this->notReadable)))->readFile();
69
    }
70
}
71