-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathAssertPropertyExistsRector.php
More file actions
58 lines (52 loc) · 1.67 KB
/
AssertPropertyExistsRector.php
File metadata and controls
58 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
declare(strict_types=1);
namespace Rector\PHPUnit\CodeQuality\Rector\MethodCall;
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @deprecated as this assert method was removed in PHPUnit 10 @see https://github.com/sebastianbergmann/phpunit/issues/4601
*/
final class AssertPropertyExistsRector extends AbstractRector
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Turns `property_exists` comparisons to their method name alternatives in PHPUnit TestCase',
[
new CodeSample(
<<<'CODE_SAMPLE'
$this->assertFalse(property_exists(new Class, "property"));
$this->assertTrue(property_exists(new Class, "property"));
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
$this->assertClassHasAttribute("property", "Class");
$this->assertClassNotHasAttribute("property", "Class");
CODE_SAMPLE
),
]
);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [MethodCall::class, StaticCall::class];
}
/**
* @param MethodCall|StaticCall $node
*/
public function refactor(Node $node): ?Node
{
throw new ShouldNotHappenException(sprintf(
'"%s" rule is deprecated as the attribute exists assert method was removed in PHPUnit 10.',
self::class
));
}
}