Completed
Pull Request — master (#175)
by Juliette
03:39
created

testNamespaceSeparator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 8
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * New language constructs sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * New language constructs sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class NewLanguageConstructsSniffTest 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
    const TEST_FILE = 'sniff-examples/new_language_constructs.php';
19
20
    /**
21
     * testNamespaceSeparator
22
     *
23
     * @group NewLanguageConstructs
24
     *
25
     * @return void
26
     */
27 View Code Duplication
    public function testNamespaceSeparator()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        $file = $this->sniffFile(self::TEST_FILE, '5.2');
30
        $this->assertError($file, 3, 'the \ operator (for namespaces) is not present in PHP version 5.2 or earlier');
31
32
        $file = $this->sniffFile(self::TEST_FILE, '5.3');
33
        $this->assertNoViolation($file, 3);
34
    }
35
36
    /**
37
     * testPow
38
     *
39
     * @group NewLanguageConstructs
40
     *
41
     * @return void
42
     */
43 View Code Duplication
    public function testPow()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        $file = $this->sniffFile(self::TEST_FILE, '5.5');
46
        $this->assertError($file, 5, "power operator (**) is not present in PHP version 5.5 or earlier");
47
48
        $file = $this->sniffFile(self::TEST_FILE, '5.6');
49
        $this->assertNoViolation($file, 5);
50
    }
51
52
    /**
53
     * testPowEquals
54
     *
55
     * @group NewLanguageConstructs
56
     *
57
     * @return void
58
     */
59 View Code Duplication
    public function testPowEquals()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
    {
61
        $file = $this->sniffFile(self::TEST_FILE, '5.5');
62
        $this->assertError($file, 6, "power assignment operator (**=) is not present in PHP version 5.5 or earlier");
63
64
        $file = $this->sniffFile(self::TEST_FILE, '5.6');
65
        $this->assertNoViolation($file, 6);
66
    }
67
68
    /**
69
     * testSpaceship
70
     *
71
     * @group NewLanguageConstructs
72
     *
73
     * @return void
74
     */
75 View Code Duplication
    public function testSpaceship()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
    {
77
        $file = $this->sniffFile(self::TEST_FILE, '5.6');
78
        $this->assertError($file, 12, "spaceship operator (<=>) is not present in PHP version 5.6 or earlier");
79
80
        $file = $this->sniffFile(self::TEST_FILE, '7.0');
81
        $this->assertNoViolation($file, 12);
82
    }
83
84
    /**
85
     * Coalescing operator
86
     *
87
     * @group NewLanguageConstructs
88
     *
89
     * @return void
90
     */
91
    public function testCoalescing()
92
    {
93
        $file = $this->sniffFile(self::TEST_FILE, '5.6');
94
        $this->assertError($file, 8, "null coalescing operator (??) is not present in PHP version 5.6 or earlier");
95
        $this->assertError($file, 10, "null coalescing operator (??) is not present in PHP version 5.6 or earlier");
96
97
        $file = $this->sniffFile(self::TEST_FILE, '7.0');
98
        $this->assertNoViolation($file, 8);
99
        $this->assertNoViolation($file, 10);
100
    }
101
102
    /**
103
     * Variadic functions using ...
104
     *
105
     * @group NewLanguageConstructs
106
     *
107
     * @return void
108
     */
109 View Code Duplication
    public function testEllipsis()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
110
    {
111
        $file = $this->sniffFile(self::TEST_FILE, '5.5');
112
        $this->assertError($file, 14, "variadic functions using ... is not present in PHP version 5.5 or earlier");
113
114
        $file = $this->sniffFile(self::TEST_FILE, '5.6');
115
        $this->assertNoViolation($file, 14);
116
    }
117
}
118