Repository navigation
Expand file tree
/
Copy pathConfiguredMockEntityToSetterObjectRector.php
More file actions
78 lines (70 loc) · 2.07 KB
/
Copy pathConfiguredMockEntityToSetterObjectRector.php
File metadata and controls
78 lines (70 loc) · 2.07 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
declare(strict_types=1);
namespace Rector\PHPUnit\CodeQuality\Rector\Expression;
use PhpParser\Node;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
use Rector\Exception\ShouldNotHappenException;
use Rector\Rector\AbstractRector;
use Rector\RuleDoc\CodeSample\CodeSample;
use Rector\RuleDoc\RuleDefinition;
/**
* @deprecated This rule is deprecated as experimental. It can generate broken code - it drops non-"get" config keys silently and assumes a matching setter exists. Handle it in a custom way or keep the code untouched.
*/
final class ConfiguredMockEntityToSetterObjectRector extends AbstractRector implements DeprecatedInterface
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
'Change createConfigureMock() on Entity/Document object to direct new instance with setters',
[
new CodeSample(
<<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestClass
{
public function test()
{
$someObject = $this->createConfiguredMock(SomeObject::class, [
'name' => 'John',
'surname' => 'Doe',
]);
}
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestClass
{
public function test()
{
$someObject = new SomeObject();
$someObject->setName('John');
$someObject->setSurname('Doe');
}
}
CODE_SAMPLE
),
]
);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes(): array
{
return [Expression::class, Return_::class];
}
/**
* @param Expression|Return_ $node
*/
public function refactor(Node $node): ?Node
{
throw new ShouldNotHappenException(sprintf(
'"%s" is deprecated and should not be used anymore. Remove it from your config files.',
self::class,
));
}
}