1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Classname determination test file |
4
|
|
|
* |
5
|
|
|
* @package PHPCompatibility |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Classname determination function tests |
11
|
|
|
* |
12
|
|
|
* @uses BaseSniffTest |
13
|
|
|
* @package PHPCompatibility |
14
|
|
|
*/ |
15
|
|
View Code Duplication |
class GetFQClassNameFromNewTokenTest extends BaseAbstractClassMethodTest |
|
|
|
|
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
|
|
|
* @param int $stackPtr Stack pointer for a T_NEW token in the test file. |
30
|
|
|
* @param string $expected The expected fully qualified class name. |
31
|
|
|
*/ |
32
|
|
|
public function testGetFQClassNameFromNewToken($stackPtr, $expected) { |
33
|
|
|
$result = $this->helperClass->getFQClassNameFromNewToken($this->_phpcsFile, $stackPtr); |
34
|
|
|
$this->assertSame($expected, $result); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* dataGetFQClassNameFromNewToken |
39
|
|
|
* |
40
|
|
|
* @see testGetFQClassNameFromNewToken() |
41
|
|
|
* |
42
|
|
|
* @return array |
43
|
|
|
*/ |
44
|
|
|
public function dataGetFQClassNameFromNewToken() |
45
|
|
|
{ |
46
|
|
|
return array( |
47
|
|
|
array(7, '\MyTesting\DateTime'), |
48
|
|
|
array(16, '\MyTesting\DateTime'), |
49
|
|
|
array(21, '\DateTime'), |
50
|
|
|
array(29, '\MyTesting\anotherNS\DateTime'), |
51
|
|
|
array(38, '\FQNS\DateTime'), |
52
|
|
|
array(56, '\AnotherTesting\DateTime'), |
53
|
|
|
array(66, '\AnotherTesting\DateTime'), |
54
|
|
|
array(72, '\DateTime'), |
55
|
|
|
array(81, '\AnotherTesting\anotherNS\DateTime'), |
56
|
|
|
array(91, '\FQNS\DateTime'), |
57
|
|
|
array(104, '\DateTime'), |
58
|
|
|
array(109, '\DateTime'), |
59
|
|
|
array(115, '\AnotherTesting\DateTime'), |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
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.