FileSystemReaderTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 97
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanCreate() 0 7 1
A testCanRead() 0 6 1
A testCantBeLoaded() 0 6 1
A testCantLoadDirectory() 0 6 1
A testCantRead() 0 6 1
A testIsReadable() 0 9 1
1
<?php
2
3
namespace Test\DiTesto\FileSystem;
4
5
use LazyEight\DiTesto\FileSystem\Exceptions\FileSystemException;
6
use LazyEight\DiTesto\FileSystem\FileSystemPath;
7
use LazyEight\DiTesto\FileSystem\FileSystemReader;
8
use PHPUnit\Framework\TestCase;
9
use LazyEight\DiTesto\FileSystem\Exceptions\InvalidPathException;
10
11
class FileSystemReaderTest 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
     * @var string
30
     */
31
    protected $directory = './tests/files/';
32
33
    /**
34
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemReader::__construct
35
     * @return FileSystemReader
36
     */
37
    public function testCanCreate()
38
    {
39
        $instance = new FileSystemReader(new FileSystemPath($this->file));
40
        $this->assertInstanceOf(FileSystemReader::class, $instance);
41
42
        return $instance;
43
    }
44
45
    /**
46
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemReader::read
47
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemReader::validate
48
     * @param \LazyEight\DiTesto\TextFileLoader
49
     */
50
    public function testCanRead()
51
    {
52
        $fileReader = new FileSystemReader(new FileSystemPath($this->file));
53
        $fileContent = $fileReader->read();
54
        $this->assertEquals(file_get_contents($this->file), $fileContent);
55
    }
56
57
    /**
58
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemReader::read
59
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemReader::validate
60
     * @expectedException \LazyEight\DiTesto\FileSystem\Exceptions\FileSystemException
61
     * @uses \LazyEight\DiTesto\FileReader
62
     */
63
    public function testCantBeLoaded()
64
    {
65
        $fileReader = new FileSystemReader(new FileSystemPath(''));
66
        $this->expectException(FileSystemException::class);
67
        $fileReader->read();
68
    }
69
70
    /**
71
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemReader::read
72
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemReader::validate
73
     * @expectedException \LazyEight\DiTesto\FileSystem\Exceptions\InvalidPathException
74
     * @uses \LazyEight\DiTesto\FileReader
75
     */
76
    public function testCantLoadDirectory()
77
    {
78
        $fileReader = new FileSystemReader(new FileSystemPath($this->directory));
79
        $this->expectException(InvalidPathException::class);
80
        $fileReader->read();
81
    }
82
83
    /**
84
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemReader::read
85
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemReader::validate
86
     * @expectedException \LazyEight\DiTesto\FileSystem\Exceptions\FileSystemException
87
     */
88
    public function testCantRead()
89
    {
90
        chmod($this->notReadable, 0000);
91
        $this->expectException(FileSystemException::class);
92
        (new FileSystemReader(new FileSystemPath($this->notReadable)))->read();
93
    }
94
95
    /**
96
     * @covers \LazyEight\DiTesto\FileSystem\FileSystemReader::isReadable
97
     */
98
    public function testIsReadable()
99
    {
100
        $fileReader = new FileSystemReader(new FileSystemPath($this->file));
101
        $this->assertTrue($fileReader->isReadable());
102
103
        chmod($this->notReadable, 0000);
104
        $fileReader = new FileSystemReader(new FileSystemPath($this->notReadable));
105
        $this->assertFalse($fileReader->isReadable());
106
    }
107
}
108