1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\DiTesto; |
4
|
|
|
|
5
|
|
|
use LazyEight\DiTesto\File; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
class FileTest extends TestCase |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* @var string |
12
|
|
|
*/ |
13
|
|
|
protected $file = './tests/files/urls.txt'; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @covers \LazyEight\DiTesto\File::__construct |
17
|
|
|
* @uses \LazyEight\DiTesto\File |
18
|
|
|
* @return File |
19
|
|
|
*/ |
20
|
|
|
public function testCanBeCreated() |
21
|
|
|
{ |
22
|
|
|
$instance = new File($this->file); |
23
|
|
|
$this->assertInstanceOf(File::class, $instance); |
24
|
|
|
|
25
|
|
|
return $instance; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @covers \LazyEight\DiTesto\File::__construct |
30
|
|
|
* @covers \LazyEight\DiTesto\File::getRawContent |
31
|
|
|
* @uses \LazyEight\DiTesto\File |
32
|
|
|
*/ |
33
|
|
|
public function testCanBeInitWithContent() |
34
|
|
|
{ |
35
|
|
|
$content = file_get_contents($this->file); |
36
|
|
|
$instance = new File($this->file, $content); |
37
|
|
|
|
38
|
|
|
$this->assertInstanceOf(File::class, $instance); |
39
|
|
|
$this->assertEquals($content, $instance->getRawContent()); |
40
|
|
|
|
41
|
|
|
return $instance; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @covers \LazyEight\DiTesto\File::getPath |
46
|
|
|
* @uses \LazyEight\DiTesto\File |
47
|
|
|
* @depends testCanBeCreated |
48
|
|
|
* @param File $file |
49
|
|
|
*/ |
50
|
|
|
public function testGetPath(File $file) |
51
|
|
|
{ |
52
|
|
|
$this->assertEquals($this->file, $file->getPath()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @covers \LazyEight\DiTesto\File::getPath |
57
|
|
|
* @uses \LazyEight\DiTesto\File |
58
|
|
|
* @depends testCanBeCreated |
59
|
|
|
* @param File $file |
60
|
|
|
*/ |
61
|
|
|
public function testCantGetPath(File $file) |
62
|
|
|
{ |
63
|
|
|
$this->assertNotEquals('', $file->getPath()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @covers \LazyEight\DiTesto\File::getRawContent |
68
|
|
|
* @uses \LazyEight\DiTesto\File |
69
|
|
|
* @depends testCanBeInitWithContent |
70
|
|
|
* @param File $file |
71
|
|
|
*/ |
72
|
|
|
public function testGetRawContent(File $file) |
73
|
|
|
{ |
74
|
|
|
$content = file_get_contents($this->file); |
75
|
|
|
$this->assertEquals($content, $file->getRawContent()); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @covers \LazyEight\DiTesto\File::getRawContent |
80
|
|
|
* @uses \LazyEight\DiTesto\File |
81
|
|
|
* @depends testCanBeInitWithContent |
82
|
|
|
* @param File $file |
83
|
|
|
*/ |
84
|
|
|
public function testCantGetRawContent(File $file) |
85
|
|
|
{ |
86
|
|
|
$this->assertNotEquals('', $file->getRawContent()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* @covers \LazyEight\DiTesto\File::setRawContent |
91
|
|
|
* @covers \LazyEight\DiTesto\File::getRawContent |
92
|
|
|
* @uses \LazyEight\DiTesto\File |
93
|
|
|
* @depends testCanBeCreated |
94
|
|
|
* @param File $file |
95
|
|
|
*/ |
96
|
|
|
public function testSetRawContent(File $file) |
97
|
|
|
{ |
98
|
|
|
$file->setRawContent($content = file_get_contents($this->file)); |
99
|
|
|
$this->assertEquals($content, $file->getRawContent()); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @covers \LazyEight\DiTesto\File::__toString |
104
|
|
|
* @uses \LazyEight\DiTesto\File |
105
|
|
|
* @depends testCanBeInitWithContent |
106
|
|
|
* @param File $file |
107
|
|
|
*/ |
108
|
|
|
public function testToString(File $file) |
109
|
|
|
{ |
110
|
|
|
$content = file_get_contents($this->file); |
111
|
|
|
$this->assertEquals($content, $file->__toString()); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|