Completed
Push — magic-autoload-deprecations ( 6419e3 )
by Wim
01:42
created

testIsDeprecated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * __autoload deprecation for PHP 7.2 sniff test
4
 *
5
 * @package PHPCompatibility
6
 */
7
8
/**
9
 * __autoload deprecation for PHP 7.2 sniff test
10
 *
11
 * @uses BaseSniffTest
12
 * @package PHPCompatibility
13
 * @author Wim Godden <[email protected]>
14
 */
15
class DeprecatedMagicAutoloadSniffTest 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...
16
{
17
    const TEST_FILE = 'sniff-examples/deprecated_magic_autoload.php';
18
19
    /**
20
     * Test PHP4 style constructors.
21
     *
22
     * @group deprecatedPHP4Constructors
23
     *
24
     * @dataProvider dataIsDeprecated
25
     *
26
     * @param int $line Line number where the error should occur.
27
     *
28
     * @return void
29
     */
30
    public function testIsDeprecated($line)
31
    {
32
        $file = $this->sniffFile(self::TEST_FILE, '7.1');
33
        $this->assertNoViolation($file, $line);
34
35
        $file = $this->sniffFile(self::TEST_FILE, '7.2');
36
        $this->assertWarning($file, $line, 'Use of __autoload() function is deprecated since PHP 7.2');
37
    }
38
39
    /**
40
     * dataIsDeprecated
41
     *
42
     * @see testIsDeprecated()
43
     *
44
     * @return array
45
     */
46
    public function dataIsDeprecated()
47
	{
48
        return array(
49
            array(3),
50
            array(8),
51
        );
52
    }
53
54
55
    /**
56
     * Test valid methods with the same name as the class.
57
     *
58
     * @group deprecatedPHP4Constructors
59
     *
60
     * @dataProvider dataValidMethods
61
     *
62
     * @param int $line Line number where the error should occur.
63
     *
64
     * @return void
65
     */
66
    public function testValidMethods($line)
67
    {
68
        $file = $this->sniffFile(self::TEST_FILE, '7.0');
69
        $this->assertNoViolation($file, $line);
70
    }
71
72
    /**
73
     * dataValidMethods
74
     *
75
     * @see testValidMethods()
76
     *
77
     * @return array
78
     */
79
    public function dataValidMethods()
80
	{
81
        $testCases = array(
82
            array(9),
83
        );
84
85
        // Add an additional testscase which will only be 'no violation' if namespaces are recognized.
86
        if (version_compare(phpversion(), '5.3', '>=')) {
87
            $testCases[] = array(26);
88
        }
89
90
        return $testCases;
91
    }
92
}
93