1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of PHP Mess Detector. |
4
|
|
|
* |
5
|
|
|
* Copyright (c) Manuel Pichler <[email protected]>. |
6
|
|
|
* All rights reserved. |
7
|
|
|
* |
8
|
|
|
* Licensed under BSD License |
9
|
|
|
* For full copyright and license information, please see the LICENSE file. |
10
|
|
|
* Redistributions of files must retain the above copyright notice. |
11
|
|
|
* |
12
|
|
|
* @author Manuel Pichler <[email protected]> |
13
|
|
|
* @copyright Manuel Pichler. All rights reserved. |
14
|
|
|
* @license https://opensource.org/licenses/bsd-license.php BSD License |
15
|
|
|
* @link http://phpmd.org/ |
16
|
|
|
*/ |
17
|
|
|
|
18
|
|
|
namespace PHPMD\Rule\CleanCode; |
19
|
|
|
|
20
|
|
|
use PHPMD\AbstractTest; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* MissingImport Tests |
24
|
|
|
* |
25
|
|
|
* @coversDefaultClass \PHPMD\Rule\CleanCode\MissingImport |
26
|
|
|
*/ |
27
|
|
|
class MissingImportTest extends AbstractTest |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Get the rule under test. |
31
|
|
|
* |
32
|
|
|
* @return MissingImport |
33
|
|
|
*/ |
34
|
|
|
public function getRule() |
35
|
|
|
{ |
36
|
|
|
$rule = new MissingImport(); |
37
|
|
|
$rule->addProperty('ignore-global', false); |
|
|
|
|
38
|
|
|
return $rule; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Tests the rule for cases where it should apply. |
43
|
|
|
* |
44
|
|
|
* @param string $file The test file to test against. |
45
|
|
|
* @return void |
46
|
|
|
* @dataProvider getApplyingCases |
47
|
|
|
*/ |
48
|
|
|
public function testRuleAppliesTo($file) |
49
|
|
|
{ |
50
|
|
|
$this->expectRuleHasViolationsForFile($this->getRule(), static::ONE_VIOLATION, $file); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Tests the rule for cases where it should not apply. |
55
|
|
|
* |
56
|
|
|
* @param string $file The test file to test against. |
57
|
|
|
* @return void |
58
|
|
|
* @dataProvider getNotApplyingCases |
59
|
|
|
*/ |
60
|
|
|
public function testRuleDoesNotApplyTo($file) |
61
|
|
|
{ |
62
|
|
|
$this->expectRuleHasViolationsForFile($this->getRule(), static::NO_VIOLATION, $file); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Tests that it applies to a class that has fully qualified class names |
67
|
|
|
* |
68
|
|
|
* @return void |
69
|
|
|
* @covers ::apply |
70
|
|
|
* @covers ::isSelfReference |
71
|
|
|
*/ |
72
|
|
|
public function testRuleAppliesTwiceToClassWithNotImportedDependencies() |
73
|
|
|
{ |
74
|
|
|
$rule = $this->getRule(); |
75
|
|
|
$rule->setReport($this->getReportMock(2)); |
|
|
|
|
76
|
|
|
$rule->apply($this->getMethod()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Tests the rule ignores classes in global namespace with `ignore-global`. |
81
|
|
|
* |
82
|
|
|
* @param string $file The test file to test against. |
83
|
|
|
* @return void |
84
|
|
|
* @dataProvider getApplyingCases |
85
|
|
|
*/ |
86
|
|
|
public function testRuleDoesNotApplyWithIgnoreGlobalProperty($file) |
87
|
|
|
{ |
88
|
|
|
$rule = $this->getRule(); |
89
|
|
|
$rule->addProperty('ignore-global', true); |
|
|
|
|
90
|
|
|
$this->expectRuleHasViolationsForFile($rule, static::NO_VIOLATION, $file); |
91
|
|
|
} |
92
|
|
|
} |
93
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: