Completed
Pull Request — master (#11)
by Jefersson
01:42
created

testItShouldFailToValidateMissingHeaderOnFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
/*
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
namespace DocHeaderTest\Command;
19
20
use DocHeader\Command\Checker;
21
use Symfony\Component\Console\Input\StringInput;
22
use Symfony\Component\Console\Output\StreamOutput;
23
24
/**
25
 * Tests for {@see \DocHeader\Command\Checker}.
26
 *
27
 * @group   Unitary
28
 * @author  Jefersson Nathan <[email protected]>
29
 * @license MIT
30
 *
31
 * @covers  \DocHeader\Command\Checker
32
 */
33
final class CheckerTest extends \PHPUnit_Framework_TestCase
34
{
35
    private $expectedDocHeader = <<<'DOCHEADER'
36
/*
37
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
48
 *
49
 * This software consists of voluntary contributions made by many individuals
50
 * and is licensed under the MIT license.
51
 */
52
DOCHEADER;
53
54
    /**
55
     * @var Checker
56
     */
57
    private $checker;
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    protected function setUp()
63
    {
64
        parent::setUp();
65
66
        $this->checker = new Checker('test', $this->expectedDocHeader);
67
    }
68
69
70
    public function testItShouldNotFailWhenCantFindFilesToValidate()
71
    {
72
        $directory      = sys_get_temp_dir() . '/' . microtime(true);
73
        $outputResource = tmpfile();
74
75
        $input  = new StringInput($directory);
76
        $output = new StreamOutput($outputResource);
77
78
        $this->checker->run($input, $output);
79
80
        $this->assertFalse(defined('FAILED'));
81
    }
82
83
    public function testItShouldValidateFile()
84
    {
85
        $directory      = __DIR__ . '/../../assets/CorrectHeader.php';
86
        $outputResource = tmpfile();
87
88
        $input  = new StringInput($directory);
89
        $output = new StreamOutput($outputResource);
90
91
        $this->checker->run($input, $output);
92
93
        $this->assertFalse(defined('FAILED'));
94
    }
95
96
    public function testItShouldFailToValidateMissingHeaderOnFiles()
97
    {
98
        $directory      = __DIR__ . '/../../assets/MissingHeader.php';
99
        $outputResource = tmpfile();
100
101
        $input  = new StringInput($directory);
102
        $output = new StreamOutput($outputResource);
103
104
        $this->assertSame(1, $this->checker->run($input, $output));
105
        $this->assertTrue(defined('FAILED'));
106
    }
107
}
108