Skip to content

Commit

Permalink
Covert expectations mock invoke as well
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Nov 19, 2024
1 parent 0a9f7c9 commit 68f76ce
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"php": ">=8.2"
},
"require-dev": {
"rector/rector-src": "dev-main#e3ba39d",
"rector/rector-src": "dev-main",
"phpunit/phpunit": "^10.5",
"phpstan/phpstan": "^1.12",
"symplify/phpstan-rules": "^13.0",
Expand All @@ -17,7 +17,7 @@
"phpstan/phpstan-webmozart-assert": "^1.2",
"symplify/vendor-patches": "^11.3",
"tracy/tracy": "^2.10",
"tomasvotruba/class-leak": "^1.1.2",
"tomasvotruba/class-leak": "^1.2",
"rector/type-perfect": "^1.0",
"rector/swiss-knife": "^1.0"
},
Expand Down
11 changes: 4 additions & 7 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\PHPUnit\Set\PHPUnitSetList;

return RectorConfig::configure()
->withImportNames(removeUnusedImports: true)
Expand All @@ -30,7 +29,8 @@
__DIR__ . '/src/NodeFinder/DataProviderClassMethodFinder.php',
],
])
->withPhpSets(php82: true)
->withPhpSets()
->withAttributesSets(all: true)
->withPreparedSets(
deadCode: true,
codeQuality: true,
Expand All @@ -39,12 +39,9 @@
naming: true,
typeDeclarations: true,
privatization: true,
rectorPreset: true
rectorPreset: true,
phpunitCodeQuality: true
)
->withSets([
PHPUnitSetList::PHPUNIT_100,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
])
->withConfiguredRule(StringClassNameToClassConstantRector::class, [
// keep unprefixed to protected from downgrade
'PHPUnit\Framework\*',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector\Fixture;

use PHPUnit\Framework\TestCase;

final class AtLeastOnce extends TestCase
{
public function testMe()
{
$matcher = self::once();
$matcher = self::atLeast(5);
$matcher = self::never();
$matcher = self::atLeastOnce();
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\Class_\PreferPHPUnitThisCallRector\Fixture;

use PHPUnit\Framework\TestCase;

final class AtLeastOnce extends TestCase
{
public function testMe()
{
$matcher = $this->once();
$matcher = $this->atLeast(5);
$matcher = $this->never();
$matcher = $this->atLeastOnce();
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class PreferPHPUnitThisCallRector extends AbstractRector
/**
* @var string[]
*/
private const NON_ASSERT_STATIC_METHODS = ['createMock'];
private const NON_ASSERT_STATIC_METHODS = ['createMock', 'atLeast', 'atLeastOnce', 'once', 'never'];

public function __construct(
private readonly TestsNodeAnalyzer $testsNodeAnalyzer,
Expand Down Expand Up @@ -95,7 +95,6 @@ public function refactor(Node $node): ?Node
return null;
}


$methodName = $this->getName($node->name);
if (! is_string($methodName)) {
return null;
Expand Down

0 comments on commit 68f76ce

Please sign in to comment.