Completed
Push — master ( a15c22...e7ceec )
by Jefersson
13s queued 11s
created

CheckerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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