Completed
Pull Request — master (#149)
by Juliette
02:28
created

TernaryOperatorsSniffTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testStandardTernaryOperators() 0 5 1
A testMissingMiddleExpression5dot2() 0 6 1
A testMissingMiddleExpression5dot3() 0 6 1
1
<?php
2
/**
3
 * Ternary Operators Sniff test file
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
9
/**
10
 * Ternary Operators Sniff tests
11
 *
12
 * @uses BaseSniffTest
13
 * @package PHPCompatibility
14
 * @author Jansen Price <[email protected]>
15
 */
16
class TernaryOperatorsSniffTest 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
     * Sniffed file
20
     *
21
     * @var PHP_CodeSniffer_File
22
     */
23
    protected $_sniffFile;
24
25
    /**
26
     * Test ternary operators that are acceptable in all PHP versions.
27
     *
28
     * @return void
29
     */
30
    public function testStandardTernaryOperators()
31
    {
32
        $this->_sniffFile = $this->sniffFile('sniff-examples/ternary_operator.php');
33
        $this->assertNoViolation($this->_sniffFile, 5);
34
    }
35
36
    /**
37
     * 5.2 doesn't support elvis operator.
38
     *
39
     * @return void
40
     */
41
    public function testMissingMiddleExpression5dot2()
42
    {
43
        $this->_sniffFile = $this->sniffFile('sniff-examples/ternary_operator.php', '5.2');
44
        $this->assertWarning($this->_sniffFile, 8,
45
                "Middle may not be omitted from ternary operators in PHP < 5.3");
46
    }
47
48
    /**
49
     * 5.3 does support elvis operator.
50
     *
51
     * @return void
52
     */
53
    public function testMissingMiddleExpression5dot3()
54
    {
55
        $this->_sniffFile = $this->sniffFile('sniff-examples/ternary_operator.php', '5.3');
56
        $this->assertNoViolation($this->_sniffFile, 8,
57
                "Middle may not be omitted from ternary operators in PHP < 5.3");
58
    }
59
60
}
61