|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: victor |
|
5
|
|
|
* Date: 09/04/16 |
|
6
|
|
|
* Time: 21:09 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Test\DiTesto; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
use LazyEight\BasicTypes\Stringy; |
|
13
|
|
|
use LazyEight\DiTesto\Exceptions\InvalidFileLocationException; |
|
14
|
|
|
use LazyEight\DiTesto\Exceptions\InvalidFileTypeException; |
|
15
|
|
|
use LazyEight\DiTesto\TextFileValidator; |
|
16
|
|
|
use LazyEight\DiTesto\ValueObject\FileLocation; |
|
17
|
|
|
|
|
18
|
|
|
class TextFileValidatorTest 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\TextFileValidator::__construct |
|
32
|
|
|
* @uses \LazyEight\DiTesto\TextFileValidator |
|
33
|
|
|
* @return \LazyEight\DiTesto\TextFileValidator |
|
34
|
|
|
*/ |
|
35
|
|
|
public function testCanBeCreated() |
|
36
|
|
|
{ |
|
37
|
|
|
$filename = new Stringy($this->file); |
|
38
|
|
|
$instance = new TextFileValidator(new FileLocation($filename)); |
|
39
|
|
|
$this->assertInstanceOf(TextFileValidator::class, $instance); |
|
40
|
|
|
return $instance; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @covers \LazyEight\DiTesto\TextFileValidator::validate |
|
45
|
|
|
* @uses \LazyEight\DiTesto\TextFileValidator |
|
46
|
|
|
* @depends testCanBeCreated |
|
47
|
|
|
* @uses \LazyEight\DiTesto\TextFileValidator |
|
48
|
|
|
* @param \LazyEight\DiTesto\TextFileValidator |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testValidationSuccess(TextFileValidator $validator) |
|
51
|
|
|
{ |
|
52
|
|
|
$this->assertTrue($validator->validate()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @covers \LazyEight\DiTesto\TextFileValidator::validate |
|
57
|
|
|
* @expectedException \LazyEight\DiTesto\Exceptions\InvalidFileLocationException |
|
58
|
|
|
* @uses \LazyEight\DiTesto\TextFileValidator |
|
59
|
|
|
*/ |
|
60
|
|
|
public function testLocationValidation() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->expectException(InvalidFileLocationException::class); |
|
63
|
|
|
$fileLocationError = new Stringy('abc/' . $this->file); |
|
64
|
|
|
(new TextFileValidator(new FileLocation($fileLocationError)))->validate(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* @covers \LazyEight\DiTesto\TextFileValidator::validate |
|
69
|
|
|
* @expectedException \LazyEight\DiTesto\Exceptions\InvalidFileTypeException |
|
70
|
|
|
* @uses \LazyEight\DiTesto\TextFileValidator |
|
71
|
|
|
*/ |
|
72
|
|
|
public function testFileTypeValidation() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->expectException(InvalidFileTypeException::class); |
|
75
|
|
|
$fileLocationError = new Stringy($this->imageFile); |
|
76
|
|
|
(new TextFileValidator(new FileLocation($fileLocationError)))->validate(); |
|
77
|
|
|
} |
|
78
|
|
|
} |