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 |
|
|
|
|
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
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.