1 | <?php |
||
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 |