Passed
Push — master ( 601cfd...7bcbf1 )
by Michiel
22:46
created

PhpLintTaskTest::testSyntaxOK()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
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 LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19
20
namespace Phing\Task\System;
21
22
use Phing\Support\BuildFileTest;
23
24
/**
25
 * Unit tests for PhpLintTask
26
 *
27
 * @package phing.tasks.ext
28
 */
29
class PhpLintTaskTest extends BuildFileTest
30
{
31
    public function setUp(): void
32
    {
33
        $this->configureProject(PHING_TEST_BASE . "/etc/tasks/ext/phplint/build.xml");
34
    }
35
36
    public function tearDown(): void
37
    {
38
        @unlink(PHING_TEST_BASE . '/tmp/phplint_file.php');
1 ignored issue
show
Security Best Practice introduced by
It seems like you do not handle an error condition for unlink(). This can introduce security issues, and is generally not recommended. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unhandled  annotation

38
        /** @scrutinizer ignore-unhandled */ @unlink(PHING_TEST_BASE . '/tmp/phplint_file.php');

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
39
    }
40
41
    public function testSyntaxOK()
42
    {
43
        file_put_contents(PHING_TEST_BASE . '/tmp/phplint_file.php', "<?php echo 'Hello world'; ?>");
44
45
        $this->executeTarget(__FUNCTION__);
46
        $this->assertInLogs("phplint_file.php: No syntax errors detected");
47
    }
48
49
    public function testSyntaxError()
50
    {
51
        file_put_contents(PHING_TEST_BASE . '/tmp/phplint_file.php', "<?php echo 'Hello world; ?>");
52
53
        $this->executeTarget(__FUNCTION__);
54
        $this->assertInLogs("syntax error, unexpected");
55
    }
56
57
    /**
58
     * Regression test for ticket http://www.phing.info/trac/ticket/590
59
     *
60
     * @requires PHP < 7.0
61
     */
62
    public function testDeprecated()
63
    {
64
        file_put_contents(
65
            PHING_TEST_BASE . '/tmp/phplint_file.php',
66
            '<?php class TestClass {}; $t = & new TestClass();'
67
        );
68
69
        $this->executeTarget(__FUNCTION__);
70
        $this->assertInLogs("Assigning the return value of new by reference is deprecated in");
71
    }
72
73
    public function testHaltOnFailure()
74
    {
75
        file_put_contents(PHING_TEST_BASE . '/tmp/phplint_file.php', "<?php echo 'Hello world; ?>");
76
77
        $this->expectBuildException(
78
            __FUNCTION__,
79
            " Syntax error(s) in PHP files: " . PHING_TEST_BASE . "/tmp/phplint_file.php" .
80
            "=Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE in " . PHING_TEST_BASE . "/tmp/phplint_file.php on line 2"
81
        );
82
    }
83
}
84