1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Classname determination test file |
4
|
|
|
* |
5
|
|
|
* @package PHPCompatibility |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Classname determination function tests |
11
|
|
|
* |
12
|
|
|
* @uses BaseClass_MethodTestFrame |
13
|
|
|
* @package PHPCompatibility |
14
|
|
|
*/ |
15
|
|
|
class BaseClass_GetFQClassNameFromNewTokenTest extends BaseClass_MethodTestFrame |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
public $filename = '../sniff-examples/utility-functions/get_fqclassname_from_new_token.php'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* testGetFQClassNameFromNewToken |
22
|
|
|
* |
23
|
|
|
* @group utilityFunctions |
24
|
|
|
* |
25
|
|
|
* @requires PHP 5.3 |
26
|
|
|
* |
27
|
|
|
* @dataProvider dataGetFQClassNameFromNewToken |
28
|
|
|
* |
29
|
|
|
* @covers PHPCompatibility_Sniff::getFQClassNameFromNewToken |
30
|
|
|
* |
31
|
|
|
* @param int $stackPtr Stack pointer for a T_NEW token in the test file. |
32
|
|
|
* @param string $expected The expected fully qualified class name. |
33
|
|
|
*/ |
34
|
|
|
public function testGetFQClassNameFromNewToken($stackPtr, $expected) { |
35
|
|
|
$result = $this->helperClass->getFQClassNameFromNewToken($this->_phpcsFile, $stackPtr); |
36
|
|
|
$this->assertSame($expected, $result); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* dataGetFQClassNameFromNewToken |
41
|
|
|
* |
42
|
|
|
* @see testGetFQClassNameFromNewToken() |
43
|
|
|
* |
44
|
|
|
* @return array |
45
|
|
|
*/ |
46
|
|
|
public function dataGetFQClassNameFromNewToken() |
47
|
|
|
{ |
48
|
|
|
return array( |
49
|
|
|
array(7, '\MyTesting\DateTime'), |
50
|
|
|
array(16, '\MyTesting\DateTime'), |
51
|
|
|
array(21, '\DateTime'), |
52
|
|
|
array(29, '\MyTesting\anotherNS\DateTime'), |
53
|
|
|
array(38, '\FQNS\DateTime'), |
54
|
|
|
array(56, '\AnotherTesting\DateTime'), |
55
|
|
|
array(66, '\AnotherTesting\DateTime'), |
56
|
|
|
array(72, '\DateTime'), |
57
|
|
|
array(81, '\AnotherTesting\anotherNS\DateTime'), |
58
|
|
|
array(91, '\FQNS\DateTime'), |
59
|
|
|
array(104, '\DateTime'), |
60
|
|
|
array(109, '\DateTime'), |
61
|
|
|
array(115, '\AnotherTesting\DateTime'), |
62
|
|
|
array(133, ''), |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
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.