Completed
Push — master ( 49c7da...61b9c9 )
by Victor
13s
created

FileReaderTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 4
dl 0
loc 59
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanRead() 0 8 1
A testCantBeLoaded() 0 5 1
A testCantRead() 0 7 1
1
<?php
2
3
namespace Test\DiTesto;
4
5
use LazyEight\DiTesto\Exceptions\IOException;
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::readFile
30
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::isReadable
31
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::read
32
     * @uses \LazyEight\DiTesto\FileReader
33
     * @uses \LazyEight\DiTesto\FileReader
34
     * @param \LazyEight\DiTesto\TextFileLoader
35
     */
36
    public function testCanRead()
37
    {
38
        $textFile = new TextFile($this->file);
39
        (new FileReader())->readFile($textFile, new FileSystemHandler());
40
41
        $arrFile = explode(PHP_EOL, file_get_contents($this->file));
42
        $this->assertTrue(count($arrFile) === count($textFile));
43
    }
44
45
    /**
46
     * @covers \LazyEight\DiTesto\FileReader::readFile
47
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::isReadable
48
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemHandler::read
49
     * @expectedException \LazyEight\DiTesto\Exceptions\IOException
50
     * @uses \LazyEight\DiTesto\FileReader
51
     */
52
    public function testCantBeLoaded()
53
    {
54
        $this->expectException(IOException::class);
55
        (new FileReader())->readFile(new TextFile(''), new FileSystemHandler());
56
    }
57
58
    /**
59
     * @covers \LazyEight\DiTesto\FileReader::readFile
60
     * @expectedException \LazyEight\DiTesto\Exceptions\IOException
61
     */
62
    public function testCantRead()
63
    {
64
        chmod($this->notReadable, 0000);
65
66
        $this->expectException(IOException::class);
67
        (new FileReader())->readFile(new TextFile($this->notReadable), new FileSystemHandler());
68
    }
69
}
70