1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: victor |
5
|
|
|
* Date: 10/04/16 |
6
|
|
|
* Time: 02:08 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Test\DiTesto; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
use LazyEight\BasicTypes\Stringy; |
13
|
|
|
use LazyEight\DiTesto\ValueObject\File; |
14
|
|
|
use LazyEight\DiTesto\ValueObject\FileContent; |
15
|
|
|
use LazyEight\DiTesto\ValueObject\FileLocation; |
16
|
|
|
|
17
|
|
|
class FileTest extends \PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $file = './tests/files/urls.txt'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @covers \LazyEight\DiTesto\ValueObject\File::__construct |
26
|
|
|
* @covers \LazyEight\DiTesto\ValueObject\FileLocation::__construct |
27
|
|
|
* @covers \LazyEight\DiTesto\ValueObject\FileContent::__construct |
28
|
|
|
* @uses \LazyEight\DiTesto\ValueObject\File |
29
|
|
|
* @return \LazyEight\DiTesto\ValueObject\File |
30
|
|
|
*/ |
31
|
|
|
public function testCanBeCreated() |
32
|
|
|
{ |
33
|
|
|
$location = new FileLocation(new Stringy($this->file)); |
34
|
|
|
$content = new FileContent(new Stringy(file_get_contents($this->file))); |
35
|
|
|
$instance = new File($location, $content); |
36
|
|
|
$this->assertInstanceOf(File::class, $instance); |
37
|
|
|
return $instance; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @covers \LazyEight\DiTesto\ValueObject\File::getLocation |
42
|
|
|
* @covers \LazyEight\DiTesto\ValueObject\FileLocation::getValue |
43
|
|
|
* @uses \LazyEight\DiTesto\ValueObject\File |
44
|
|
|
* @depends testCanBeCreated |
45
|
|
|
* @uses \LazyEight\DiTesto\ValueObject\File |
46
|
|
|
* @param \LazyEight\DiTesto\ValueObject\File |
47
|
|
|
*/ |
48
|
|
|
public function testLocationCanBeRetrieved(File $file) |
49
|
|
|
{ |
50
|
|
|
$location = new FileLocation(new Stringy($this->file)); |
51
|
|
|
$this->assertEquals($location, $file->getLocation()); |
52
|
|
|
$this->assertNotEquals($location->getValue(), $file->getLocation()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @covers \LazyEight\DiTesto\ValueObject\File::getRawContent |
57
|
|
|
* @covers \LazyEight\DiTesto\ValueObject\FileContent::getValue |
58
|
|
|
* @uses \LazyEight\DiTesto\ValueObject\File |
59
|
|
|
* @depends testCanBeCreated |
60
|
|
|
* @uses \LazyEight\DiTesto\ValueObject\File |
61
|
|
|
* @param \LazyEight\DiTesto\ValueObject\File |
62
|
|
|
*/ |
63
|
|
|
public function testContentCanBeRetrieved(File $file) |
64
|
|
|
{ |
65
|
|
|
$content = new FileContent(new Stringy(file_get_contents($this->file))); |
66
|
|
|
$this->assertEquals($content, $file->getRawContent()); |
67
|
|
|
$this->assertNotEquals($content->getValue(), $file->getRawContent()); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @covers \LazyEight\DiTesto\ValueObject\File::__toString |
72
|
|
|
* @depends testCanBeCreated |
73
|
|
|
* @uses \LazyEight\DiTesto\ValueObject\File |
74
|
|
|
* @param \LazyEight\DiTesto\ValueObject\File |
75
|
|
|
*/ |
76
|
|
|
public function testToString(File $file) |
77
|
|
|
{ |
78
|
|
|
$this->assertEquals($file->__toString(), file_get_contents($this->file)); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|