mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
[MockistaToMockery] Drop as mockista is completely dead package (#5758)
This commit is contained in:
parent
f3cdb06adf
commit
c1dab30664
2
.github/workflows/rector.yaml
vendored
2
.github/workflows/rector.yaml
vendored
@ -24,7 +24,7 @@ jobs:
|
||||
#- rules
|
||||
- rules/arguments rules/autodiscovery rules/cakephp rules/carbon rules/code-quality rules/code-quality-strict rules/coding-style rules/composer rules/dead-code rules/dead-doc-block rules/defluent rules/dependency-injection rules/doctrine rules/doctrine-code-quality rules/doctrine-gedmo-to-knplabs rules/downgrade-php70 rules/downgrade-php71 rules/downgrade-php72 rules/downgrade-php73 rules/naming rules/nette rules/nette-code-quality rules/nette-kdyby
|
||||
|
||||
- rules/downgrade-php74 rules/downgrade-php80 rules/early-return rules/generics rules/laravel rules/legacy rules/mockery-to-prophecy rules/mockista-to-mockery rules/mysql-to-mysqli rules/symfony3 rules/symfony4 rules/symfony5 rules/transform rules/type-declaration rules/visibility
|
||||
- rules/downgrade-php74 rules/downgrade-php80 rules/early-return rules/generics rules/laravel rules/legacy rules/mockery-to-prophecy rules/mysql-to-mysqli rules/symfony3 rules/symfony4 rules/symfony5 rules/transform rules/type-declaration rules/visibility
|
||||
|
||||
- rules/nette-tester-to-phpunit rules/nette-to-symfony rules/nette-utils-code-quality rules/order rules/php-office rules/php-spec-to-phpunit rules/php52 rules/php53 rules/php54 rules/php55 rules/php56 rules/php70 rules/php71 rules/php72 rules/php73 rules/php74 rules/php80 rules/phpunit rules/phpunit-symfony rules/privatization rules/psr4 rules/removing rules/removing-static rules/renaming rules/restoration rules/sensio rules/symfony rules/symfony-code-quality rules/symfony-php-config rules/symfony2
|
||||
|
||||
|
@ -99,7 +99,6 @@
|
||||
"Rector\\Laravel\\": "rules/laravel/src",
|
||||
"Rector\\Legacy\\": "rules/legacy/src",
|
||||
"Rector\\MockeryToProphecy\\": "rules/mockery-to-prophecy/src",
|
||||
"Rector\\MockistaToMockery\\": "rules/mockista-to-mockery/src",
|
||||
"Rector\\MysqlToMysqli\\": "rules/mysql-to-mysqli/src",
|
||||
"Rector\\Naming\\": "rules/naming/src",
|
||||
"Rector\\NetteCodeQuality\\": "rules/nette-code-quality/src",
|
||||
@ -220,7 +219,6 @@
|
||||
"Rector\\Legacy\\Tests\\": "rules/legacy/tests",
|
||||
"Rector\\Defluent\\Tests\\": "rules/defluent/tests",
|
||||
"Rector\\MockeryToProphecy\\Tests\\": "rules/mockery-to-prophecy/tests",
|
||||
"Rector\\MockistaToMockery\\Tests\\": "rules/mockista-to-mockery/tests",
|
||||
"Rector\\MysqlToMysqli\\Tests\\": "rules/mysql-to-mysqli/tests",
|
||||
"Rector\\Naming\\Tests\\": "rules/naming/tests",
|
||||
"Rector\\DeadDocBlock\\Tests\\": "rules/dead-doc-block/tests",
|
||||
|
@ -120,7 +120,6 @@
|
||||
"Rector\\Laravel\\": "rules/laravel/src",
|
||||
"Rector\\Legacy\\": "rules/legacy/src",
|
||||
"Rector\\MockeryToProphecy\\": "rules/mockery-to-prophecy/src",
|
||||
"Rector\\MockistaToMockery\\": "rules/mockista-to-mockery/src",
|
||||
"Rector\\MysqlToMysqli\\": "rules/mysql-to-mysqli/src",
|
||||
"Rector\\Naming\\": "rules/naming/src",
|
||||
"Rector\\NetteCodeQuality\\": "rules/nette-code-quality/src",
|
||||
@ -240,7 +239,6 @@
|
||||
"Rector\\Legacy\\Tests\\": "rules/legacy/tests",
|
||||
"Rector\\Defluent\\Tests\\": "rules/defluent/tests",
|
||||
"Rector\\MockeryToProphecy\\Tests\\": "rules/mockery-to-prophecy/tests",
|
||||
"Rector\\MockistaToMockery\\Tests\\": "rules/mockista-to-mockery/tests",
|
||||
"Rector\\MysqlToMysqli\\Tests\\": "rules/mysql-to-mysqli/tests",
|
||||
"Rector\\Naming\\Tests\\": "rules/naming/tests",
|
||||
"Rector\\DeadDocBlock\\Tests\\": "rules/dead-doc-block/tests",
|
||||
|
@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Rector\MockistaToMockery\Rector\Class_\MockeryTearDownRector;
|
||||
use Rector\MockistaToMockery\Rector\ClassMethod\MockistaMockToMockeryMockRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->set(MockeryTearDownRector::class);
|
||||
|
||||
$services->set(MockistaMockToMockeryMockRector::class);
|
||||
};
|
@ -288,11 +288,6 @@ final class SetList implements SetListInterface
|
||||
*/
|
||||
public const LARAVEL_ARRAY_STR_FUNCTION_TO_STATIC_CALL = __DIR__ . '/../../../../config/set/laravel-array-str-functions-to-static-call.php';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const MOCKISTA_TO_MOCKERY = __DIR__ . '/../../../../config/set/mockista-to-mockery.php';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
|
||||
return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
$services = $containerConfigurator->services();
|
||||
|
||||
$services->defaults()
|
||||
->public()
|
||||
->autowire()
|
||||
->autoconfigure();
|
||||
|
||||
$services->load('Rector\MockistaToMockery\\', __DIR__ . '/../src')
|
||||
->exclude([__DIR__ . '/../src/Rector']);
|
||||
};
|
@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\MockistaToMockery;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Core\PhpParser\Node\BetterNodeFinder;
|
||||
use Rector\NodeNameResolver\NodeNameResolver;
|
||||
|
||||
final class MockistaDetector
|
||||
{
|
||||
/**
|
||||
* @var BetterNodeFinder
|
||||
*/
|
||||
private $betterNodeFinder;
|
||||
|
||||
/**
|
||||
* @var NodeNameResolver
|
||||
*/
|
||||
private $nodeNameResolver;
|
||||
|
||||
public function __construct(BetterNodeFinder $betterNodeFinder, NodeNameResolver $nodeNameResolver)
|
||||
{
|
||||
$this->betterNodeFinder = $betterNodeFinder;
|
||||
$this->nodeNameResolver = $nodeNameResolver;
|
||||
}
|
||||
|
||||
public function isInClass(Class_ $class): bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirst($class->stmts, function (Node $node): bool {
|
||||
if (! $node instanceof FuncCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->nodeNameResolver->isName($node, 'mock');
|
||||
});
|
||||
}
|
||||
}
|
@ -1,326 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\MockistaToMockery\Rector\ClassMethod;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\Assign;
|
||||
use PhpParser\Node\Expr\FuncCall;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Expr\PropertyFetch;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\MockeryToProphecy\Collector\MockVariableCollector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\MockistaMockToMockeryMockRectorTest
|
||||
*/
|
||||
final class MockistaMockToMockeryMockRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var string[]
|
||||
*/
|
||||
private const METHODS_TO_REMOVE = ['freeze', 'assertExpectations'];
|
||||
|
||||
/**
|
||||
* @var array<string, class-string>
|
||||
*/
|
||||
private $mockVariableTypesByNames = [];
|
||||
|
||||
/**
|
||||
* @var MockVariableCollector
|
||||
*/
|
||||
private $mockVariableCollector;
|
||||
|
||||
/**
|
||||
* @var TestsNodeAnalyzer
|
||||
*/
|
||||
private $testsNodeAnalyzer;
|
||||
|
||||
/**
|
||||
* @var ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
|
||||
public function __construct(
|
||||
MockVariableCollector $mockVariableCollector,
|
||||
TestsNodeAnalyzer $testsNodeAnalyzer,
|
||||
ReflectionProvider $reflectionProvider
|
||||
) {
|
||||
$this->mockVariableCollector = $mockVariableCollector;
|
||||
$this->testsNodeAnalyzer = $testsNodeAnalyzer;
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Change functions to static calls, so composer can autoload them',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeTest
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
$mockUser->getId()->once->andReturn(1);
|
||||
$mockUser->freeze();
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class SomeTest
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$mockUser = Mockery::mock(User::class);
|
||||
$mockUser->expects()->getId()->once()->andReturn(1);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [ClassMethod::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ClassMethod $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->testsNodeAnalyzer->isInTestClass($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->replaceMockWithMockerMockAndCollectMockVariableName($node);
|
||||
$this->replaceMethodCallOncePropertyFetch($node);
|
||||
$this->removeUnusedMethodCalls($node);
|
||||
$this->replaceMethodCallWithExpects($node);
|
||||
|
||||
$this->switchWithAnyArgsAndOnceTwice($node);
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function replaceMockWithMockerMockAndCollectMockVariableName(ClassMethod $classMethod): void
|
||||
{
|
||||
$this->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $node): ?StaticCall {
|
||||
if (! $this->nodeNameResolver->isFuncCallName($node, 'mock')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var FuncCall $node */
|
||||
$collectedVariableTypesByNames = $this->mockVariableCollector->collectMockVariableName($node);
|
||||
$this->mockVariableTypesByNames = array_merge(
|
||||
$this->mockVariableTypesByNames,
|
||||
$collectedVariableTypesByNames
|
||||
);
|
||||
|
||||
return $this->nodeFactory->createStaticCall('Mockery', 'mock', $node->args);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* $mock->getMethod()->once
|
||||
* ↓
|
||||
* $mock->getMethod()->once()
|
||||
*/
|
||||
private function replaceMethodCallOncePropertyFetch(ClassMethod $classMethod): void
|
||||
{
|
||||
$this->traverseNodesWithCallable(
|
||||
(array) $classMethod->stmts,
|
||||
function (Node $node): ?MethodCall {
|
||||
if (! $node instanceof PropertyFetch) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isNames($node->name, ['once', 'twice'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new MethodCall($node->var, $node->name);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private function removeUnusedMethodCalls(ClassMethod $classMethod): void
|
||||
{
|
||||
$this->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $node) {
|
||||
if (! $this->isMethodCallOrPropertyFetchOnMockVariable($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var PropertyFetch|MethodCall $node */
|
||||
if (! $this->isNames($node->name, self::METHODS_TO_REMOVE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->removeNode($node);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* $mock->getMethod()->once()
|
||||
* ↓
|
||||
* $mock->expects()->getMethod()->once()
|
||||
*/
|
||||
private function replaceMethodCallWithExpects(ClassMethod $classMethod): void
|
||||
{
|
||||
$this->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $node): ?MethodCall {
|
||||
if (! $this->isMethodCallOrPropertyFetchOnMockVariable($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// skip assigns
|
||||
$parent = $node->getAttribute(AttributeKey::PARENT_NODE);
|
||||
if ($parent instanceof Assign) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var MethodCall|PropertyFetch $node */
|
||||
if ($this->isNames($node->name, self::METHODS_TO_REMOVE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->isNames($node->name, ['expects', 'allows'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// probably method mock
|
||||
$expectedMethodCall = new MethodCall($node->var, 'expects');
|
||||
$methodCall = new MethodCall($expectedMethodCall, $node->name);
|
||||
|
||||
if ($node instanceof PropertyFetch) {
|
||||
return $methodCall;
|
||||
}
|
||||
|
||||
$methodCall->args = $node->args;
|
||||
|
||||
return $this->decorateWithAnyArgs($node, $methodCall);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Order correction for @see replaceMethodCallWithExpects()
|
||||
*/
|
||||
private function switchWithAnyArgsAndOnceTwice(ClassMethod $classMethod): void
|
||||
{
|
||||
$this->traverseNodesWithCallable((array) $classMethod->stmts, function (Node $node) {
|
||||
if (! $node instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! $this->isNames($node->name, ['once', 'twice'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (! $node->var instanceof MethodCall) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var MethodCall $previousMethodCall */
|
||||
$previousMethodCall = $node->var;
|
||||
if (! $this->isName($previousMethodCall->name, 'withAnyArgs')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
[$node->name, $previousMethodCall->name] = [$previousMethodCall->name, $node->name];
|
||||
});
|
||||
}
|
||||
|
||||
private function isMethodCallOrPropertyFetchOnMockVariable(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof MethodCall && ! $this->isPropertyFetchDisguisedAsMethodCall($node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var MethodCall|PropertyFetch $node */
|
||||
if (! $node->var instanceof Variable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var string $variableName */
|
||||
$variableName = $this->getName($node->var);
|
||||
|
||||
return isset($this->mockVariableTypesByNames[$variableName]);
|
||||
}
|
||||
|
||||
/**
|
||||
* $mock->someMethodWithArgs()->once()
|
||||
* ↓
|
||||
* $mock->expects()->someMethodWithArgs()->withAnyArgs()->once()
|
||||
*/
|
||||
private function decorateWithAnyArgs(MethodCall $originalMethodCall, MethodCall $expectsMethodCall): MethodCall
|
||||
{
|
||||
$variableName = $this->getName($originalMethodCall->var);
|
||||
$mockVariableType = $this->mockVariableTypesByNames[$variableName];
|
||||
|
||||
$methodName = $this->getName($originalMethodCall->name);
|
||||
if ($methodName === null) {
|
||||
return $expectsMethodCall;
|
||||
}
|
||||
|
||||
if (! $this->reflectionProvider->hasClass($mockVariableType)) {
|
||||
return $expectsMethodCall;
|
||||
}
|
||||
|
||||
$classReflection = $this->reflectionProvider->getClass($mockVariableType);
|
||||
if (! $classReflection->hasMethod($methodName)) {
|
||||
return $expectsMethodCall;
|
||||
}
|
||||
|
||||
$nativeReflectionClass = $classReflection->getNativeReflection();
|
||||
$reflectionMethod = $nativeReflectionClass->getMethod($methodName);
|
||||
if ($reflectionMethod->getNumberOfRequiredParameters() === 0) {
|
||||
return $expectsMethodCall;
|
||||
}
|
||||
|
||||
return new MethodCall($expectsMethodCall, 'withAnyArgs');
|
||||
}
|
||||
|
||||
private function isPropertyFetchDisguisedAsMethodCall(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof PropertyFetch) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($node->var instanceof MethodCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$variableName = $this->getName($node->var);
|
||||
if (! isset($this->mockVariableTypesByNames[$variableName])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$mockVariableType = $this->mockVariableTypesByNames[$variableName];
|
||||
if (! $this->reflectionProvider->hasClass($mockVariableType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$classReflection = $this->reflectionProvider->getClass($mockVariableType);
|
||||
$propertyName = $this->getName($node->name);
|
||||
if ($propertyName === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $classReflection->hasMethod($propertyName);
|
||||
}
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\MockistaToMockery\Rector\Class_;
|
||||
|
||||
use PhpParser\BuilderHelpers;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Stmt;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\ValueObject\MethodName;
|
||||
use Rector\MockistaToMockery\MockistaDetector;
|
||||
use Symplify\Astral\ValueObject\NodeBuilder\MethodBuilder;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
|
||||
/**
|
||||
* @see \Rector\MockistaToMockery\Tests\Rector\Class_\MockeryTearDownRector\MockeryTearDownRectorTest
|
||||
*/
|
||||
final class MockeryTearDownRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var MockistaDetector
|
||||
*/
|
||||
private $mockistaDetector;
|
||||
|
||||
public function __construct(MockistaDetector $mockistaDetector)
|
||||
{
|
||||
$this->mockistaDetector = $mockistaDetector;
|
||||
}
|
||||
|
||||
public function getRuleDefinition(): RuleDefinition
|
||||
{
|
||||
return new RuleDefinition(
|
||||
'Add Mockery::close() in tearDown() method if not yet',
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SomeTest extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SomeTest extends TestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Mockery::close();
|
||||
}
|
||||
public function test()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes(): array
|
||||
{
|
||||
return [Class_::class];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
if (! $this->mockistaDetector->isInClass($node)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$tearDownClassMethod = $node->getMethod(MethodName::TEAR_DOWN);
|
||||
if (! $tearDownClassMethod instanceof ClassMethod) {
|
||||
$node->stmts[] = $this->createTearDownMethodWithMockeryClose();
|
||||
} elseif (! $this->containsMockeryClose($tearDownClassMethod)) {
|
||||
$tearDownClassMethod->stmts[] = $this->createMockeryClose();
|
||||
}
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function createTearDownMethodWithMockeryClose(): ClassMethod
|
||||
{
|
||||
$methodBuilder = new MethodBuilder(MethodName::TEAR_DOWN);
|
||||
$methodBuilder->setReturnType('void');
|
||||
$methodBuilder->makeProtected();
|
||||
|
||||
$staticCall = $this->createMockeryClose();
|
||||
$methodBuilder->addStmt($staticCall);
|
||||
|
||||
return $methodBuilder->getNode();
|
||||
}
|
||||
|
||||
private function containsMockeryClose(ClassMethod $classMethod): bool
|
||||
{
|
||||
return (bool) $this->betterNodeFinder->findFirst((array) $classMethod->stmts, function (Node $node): bool {
|
||||
if (! $node instanceof StaticCall) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $this->isName($node->class, 'Mockery')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->isName($node->name, 'close');
|
||||
});
|
||||
}
|
||||
|
||||
private function createMockeryClose(): Stmt
|
||||
{
|
||||
$staticCall = $this->nodeFactory->createStaticCall('Mockery', 'close');
|
||||
|
||||
return BuilderHelpers::normalizeStmt($staticCall);
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SomeTest extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
$mockUser->getId()->once->andReturn(1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SomeTest extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = \Mockery::mock(User::class);
|
||||
$mockUser->expects()->getId()->once()->andReturn(1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MethodArgs extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
$mockUser->getId(1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MethodArgs extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = \Mockery::mock(User::class);
|
||||
$mockUser->expects()->getId(1);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Source\User;
|
||||
|
||||
class MethodWithArgsWithoutAny extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
$mockUser->methodWithArg()->once();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Source\User;
|
||||
|
||||
class MethodWithArgsWithoutAny extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = \Mockery::mock(User::class);
|
||||
$mockUser->expects()->methodWithArg()->once()->withAnyArgs();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MethodsToRemove extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
$mockUser->freeze();
|
||||
$mockUser->assertExpectations();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MethodsToRemove extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = \Mockery::mock(User::class);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Source\User;
|
||||
|
||||
class PropertyOrMethod extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
$mockUser->insert->once;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Source\User;
|
||||
|
||||
class PropertyOrMethod extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = \Mockery::mock(User::class);
|
||||
$mockUser->expects()->insert()->once();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SetValue extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
$mockUser->id = 5;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SetValue extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = \Mockery::mock(User::class);
|
||||
$mockUser->id = 5;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Source\User;
|
||||
|
||||
class Twice extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
$mockUser->insert->twice;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Source\User;
|
||||
|
||||
class Twice extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = \Mockery::mock(User::class);
|
||||
$mockUser->expects()->insert()->twice();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,37 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Source\User;
|
||||
|
||||
class UseValue extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
$mockUser->id = 5;
|
||||
$mockUser->run($mockUser->id);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Source\User;
|
||||
|
||||
class UseValue extends TestCase
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
$mockUser = \Mockery::mock(User::class);
|
||||
$mockUser->id = 5;
|
||||
$mockUser->expects()->run($mockUser->id);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\MockistaToMockery\Rector\ClassMethod\MockistaMockToMockeryMockRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class MockistaMockToMockeryMockRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return MockistaMockToMockeryMockRector::class;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\ClassMethod\MockistaMockToMockeryMockRector\Source;
|
||||
|
||||
final class User
|
||||
{
|
||||
public function insert()
|
||||
{
|
||||
}
|
||||
|
||||
public function methodWithArg($values)
|
||||
{
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\Class_\MockeryTearDownRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AddToExistingTearDownTest extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
}
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$value = 5;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\Class_\MockeryTearDownRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AddToExistingTearDownTest extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
}
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$value = 5;
|
||||
\Mockery::close();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\Class_\MockeryTearDownRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SomeTest extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\Class_\MockeryTearDownRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SomeTest extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$mockUser = mock(User::class);
|
||||
}
|
||||
protected function tearDown(): void
|
||||
{
|
||||
\Mockery::close();
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -1,17 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\Class_\MockeryTearDownRector\Fixture;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class SkipExisting extends TestCase
|
||||
{
|
||||
public function test()
|
||||
{
|
||||
$mockUser = \mock(User::class);
|
||||
}
|
||||
protected function tearDown(): void
|
||||
{
|
||||
\Mockery::close();
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\MockistaToMockery\Tests\Rector\Class_\MockeryTearDownRector;
|
||||
|
||||
use Iterator;
|
||||
use Rector\MockistaToMockery\Rector\Class_\MockeryTearDownRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
|
||||
final class MockeryTearDownRectorTest extends AbstractRectorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider provideData()
|
||||
*/
|
||||
public function test(SmartFileInfo $fileInfo): void
|
||||
{
|
||||
$this->doTestFileInfo($fileInfo);
|
||||
}
|
||||
|
||||
public function provideData(): Iterator
|
||||
{
|
||||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
|
||||
}
|
||||
|
||||
protected function getRectorClass(): string
|
||||
{
|
||||
return MockeryTearDownRector::class;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user