1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: Victor Ribeiro <[email protected]> |
5
|
|
|
* Date: 09/04/16 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace Test\DiTesto; |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
use LazyEight\BasicTypes\Stringy; |
12
|
|
|
use LazyEight\DiTesto\Exceptions\InvalidFileLocationException; |
13
|
|
|
use LazyEight\DiTesto\TextFileLoader; |
14
|
|
|
use LazyEight\DiTesto\ValueObject\FileLocation; |
15
|
|
|
use LazyEight\DiTesto\Exceptions\InvalidFileTypeException; |
16
|
|
|
use LazyEight\DiTesto\ValueObject\TextFile\TextFile; |
17
|
|
|
|
18
|
|
|
class TextFileLoaderTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $file = './tests/files/urls.txt'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $imageFile = './tests/files/images.jpg'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @covers \LazyEight\DiTesto\TextFileLoader::__construct |
32
|
|
|
* @uses \LazyEight\DiTesto\TextFileLoader |
33
|
|
|
* @return \LazyEight\DiTesto\TextFileLoader |
34
|
|
|
*/ |
35
|
|
|
public function testCanBeCreated() |
36
|
|
|
{ |
37
|
|
|
$filename = new Stringy($this->file); |
38
|
|
|
$instance = new TextFileLoader(new FileLocation($filename)); |
39
|
|
|
$this->assertInstanceOf(TextFileLoader::class, $instance); |
40
|
|
|
return $instance; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @covers \LazyEight\DiTesto\TextFileLoader::loadFile |
45
|
|
|
* @uses \LazyEight\DiTesto\TextFileLoader |
46
|
|
|
* @depends testCanBeCreated |
47
|
|
|
* @uses \LazyEight\DiTesto\TextFileLoader |
48
|
|
|
* @param \LazyEight\DiTesto\TextFileLoader |
49
|
|
|
*/ |
50
|
|
|
public function testCanBeLoaded(TextFileLoader $loader) |
51
|
|
|
{ |
52
|
|
|
$this->assertInstanceOf(TextFile::class, $loader->loadFile()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @covers \LazyEight\DiTesto\TextFileLoader::loadFile |
57
|
|
|
* @expectedException \LazyEight\DiTesto\Exceptions\InvalidFileTypeException |
58
|
|
|
* @uses \LazyEight\DiTesto\TextFileLoader |
59
|
|
|
*/ |
60
|
|
|
public function testCantBeLoaded() |
61
|
|
|
{ |
62
|
|
|
$textLoader = new TextFileLoader(new FileLocation(new Stringy($this->imageFile))); |
63
|
|
|
$this->expectException(InvalidFileTypeException::class); |
64
|
|
|
$textLoader->loadFile(); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @covers \LazyEight\DiTesto\TextFileLoader::loadFile |
69
|
|
|
* @expectedException \LazyEight\DiTesto\Exceptions\InvalidFileLocationException |
70
|
|
|
* @uses \LazyEight\DiTesto\TextFileLoader |
71
|
|
|
*/ |
72
|
|
|
public function testCantBeLoadedInvaidLocation() |
73
|
|
|
{ |
74
|
|
|
$textLoader = new TextFileLoader(new FileLocation(new Stringy('abc_'.$this->imageFile))); |
75
|
|
|
$this->expectException(InvalidFileLocationException::class); |
76
|
|
|
$textLoader->loadFile(); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|