Completed
Push — master ( 5d9942...f2e7a7 )
by Victor
01:48
created

TextFileValidatorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 1 Features 1
Metric Value
wmc 4
c 1
b 1
f 1
lcom 1
cbo 4
dl 0
loc 61
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanBeCreated() 0 7 1
A testValidationSuccess() 0 4 1
A testLocationValidation() 0 6 1
A testFileTypeValidation() 0 6 1
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
}