Completed
Push — master ( 097411...81da4d )
by Jefersson
13s queued 11s
created

it_should_not_fail_when_cant_find_files_to_validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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