Completed
Push — master ( 737862...3fd823 )
by Wim
9s
created

testUseGroupDeclaration()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
cc 2
eloc 20
nc 2
nop 0
dl 0
loc 24
rs 8.9713
c 2
b 1
f 1
1
<?php
2
/**
3
 * New use group declaration sniff tests
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * New use group declaration sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Wim Godden <[email protected]>
15
 */
16
class NewGroupUseDeclarationsSniffTest extends BaseSniffTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
17
{
18
19
    const TEST_FILE = 'sniff-examples/new_group_use_declarations.php';
20
21
    protected function setUp()
22
    {
23
        if (version_compare(PHP_CodeSniffer::VERSION, '2.3.4', '<')) {
24
            $this->markTestSkipped();
25
        }
26
        else {
27
            parent::setUp();
28
        }
29
    }
30
31
    /**
32
     * testGroupUseDeclaration
33
     *
34
     * @dataProvider dataGroupUseDeclaration
35
     *
36
     * @param int $line The line number.
37
     *
38
     * @return void
39
     */
40
    public function testGroupUseDeclaration($line)
41
    {
42
        $file = $this->sniffFile(self::TEST_FILE, '5.6');
43
        $this->assertError($file, $line, 'Group use declarations are not allowed in PHP 5.6 or earlier');
44
45
        $file = $this->sniffFile(self::TEST_FILE, '7.0');
46
        $this->assertNoViolation($file, $line);
47
    }
48
49
    /**
50
     * Data provider.
51
     *
52
     * @see testGroupUseDeclaration()
53
     *
54
     * @return array
55
     */
56
    public function dataGroupUseDeclaration()
57
    {
58
        return array(
59
            array(13),
60
            array(14),
61
        );
62
    }
63
64
65
    /**
66
     * testValidUseDeclaration
67
     *
68
     * @dataProvider dataValidUseDeclaration
69
     *
70
     * @param int $line The line number.
71
     *
72
     * @return void
73
     */
74
    public function testValidUseDeclaration($line)
75
    {
76
        $file = $this->sniffFile(self::TEST_FILE);
77
        $this->assertNoViolation($file, $line);
78
    }
79
80
    /**
81
     * Data provider.
82
     *
83
     * @see testValidUseDeclaration()
84
     *
85
     * @return array
86
     */
87
    public function dataValidUseDeclaration()
88
    {
89
        return array(
90
            array(4),
91
            array(5),
92
            array(6),
93
            array(8),
94
            array(9),
95
            array(10),
96
        );
97
    }
98
}
99