Skip to content

Commit b846a61

Browse files
authored
Fix type coverage back to 100% (#654)
1 parent 2378ea1 commit b846a61

File tree

4 files changed

+21
-41
lines changed

4 files changed

+21
-41
lines changed

.dev-tools/psalm.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
xsi:schemaLocation='https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd'
66
allowStringToStandInForClass='true'
77
autoloader='../vendor/autoload.php'
8-
findUnusedCode='false'
8+
errorLevel='1'
99
findUnusedVariablesAndParams='true'
10-
resolveFromConfigFile='true'
1110
strictBinaryOperands='true'
12-
totallyTyped='true'
1311
usePhpDocMethodsWithoutMagicCall='true'
1412
>
1513
<projectFiles>

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Latest stable version](https://img.shields.io/packagist/v/kubawerlos/php-cs-fixer-custom-fixers.svg?label=current%20version)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
44
[![PHP version](https://img.shields.io/packagist/php-v/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://php.net)
55
[![License](https://img.shields.io/github/license/kubawerlos/php-cs-fixer-custom-fixers.svg)](LICENSE)
6-
![Tests](https://img.shields.io/badge/tests-3032-brightgreen.svg)
6+
![Tests](https://img.shields.io/badge/tests-3029-brightgreen.svg)
77
[![Downloads](https://img.shields.io/packagist/dt/kubawerlos/php-cs-fixer-custom-fixers.svg)](https://packagist.org/packages/kubawerlos/php-cs-fixer-custom-fixers)
88

99
[![CI Status](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/workflows/CI/badge.svg?branch=main&event=push)](https://github.com/kubawerlos/php-cs-fixer-custom-fixers/actions)

src/Fixer/PhpUnitDedicatedAssertFixer.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
final class PhpUnitDedicatedAssertFixer extends AbstractFixer
2727
{
2828
private const ASSERTIONS = [
29-
'assertEquals',
30-
'assertNotEquals',
31-
'assertSame',
32-
'assertNotSame',
29+
'assertequals' => true,
30+
'assertnotequals' => true,
31+
'assertsame' => true,
32+
'assertnotsame' => true,
3333
];
3434
private const REPLACEMENTS_MAP = [
3535
'count' => [
@@ -110,20 +110,7 @@ private function fixAssertions(Tokens $tokens, int $startIndex, int $endIndex):
110110

111111
private static function isAssertionToFix(Tokens $tokens, int $index): bool
112112
{
113-
static $assertions;
114-
115-
if ($assertions === null) {
116-
$assertions = \array_flip(
117-
\array_map(
118-
static function (string $name): string {
119-
return \strtolower($name);
120-
},
121-
self::ASSERTIONS
122-
)
123-
);
124-
}
125-
126-
if (!isset($assertions[\strtolower($tokens[$index]->getContent())])) {
113+
if (!isset(self::ASSERTIONS[\strtolower($tokens[$index]->getContent())])) {
127114
return false;
128115
}
129116

tests/Fixer/PhpUnitDedicatedAssertFixerTest.php

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
namespace Tests\Fixer;
1515

16-
use PhpCsFixerCustomFixers\Fixer\PhpUnitDedicatedAssertFixer;
17-
1816
/**
1917
* @internal
2018
*
@@ -111,23 +109,20 @@ private static function getFixCases(): iterable
111109
'$this->assertSame ( 3 , \count ( $array ) ) ;',
112110
];
113111

114-
$reflection = new \ReflectionClass(PhpUnitDedicatedAssertFixer::class);
115-
116-
/** @var array<string> $assertions */
117-
$assertions = $reflection->getConstant('ASSERTIONS');
118-
119-
foreach ($assertions as $assertion) {
120-
$expected = 'self::assertCount(3, $array);';
121-
$input = \sprintf('self::%s(3, count($array));', $assertion);
122-
123-
if (\stripos($assertion, 'Not', 6) !== false) {
124-
$expected = \str_replace('assert', 'assertNot', $expected);
125-
$expected = \str_replace('3', '4', $expected);
126-
$input = \str_replace('3', '4', $input);
127-
}
128-
129-
yield \sprintf('Test assertion "%s"', $assertion) => [$expected, $input];
130-
}
112+
yield 'fix all four assertions' => [
113+
'
114+
self::assertCount($count, $array);
115+
self::assertCount($count, $array);
116+
self::assertNotCount($count, $array);
117+
self::assertNotCount($count, $array);
118+
',
119+
'
120+
self::assertEquals($count, count($array));
121+
self::assertSame($count, count($array));
122+
self::assertNotEquals($count, count($array));
123+
self::assertNotSame($count, count($array));
124+
',
125+
];
131126

132127
yield 'fix multiple assertions' => [
133128
'

0 commit comments

Comments
 (0)