Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector\Fixture;

use PHPUnit\Framework\TestCase;

final class KeepDeltaMessage extends TestCase
{
public function test()
{
$value = 10.20001;
$this->assertSame(10.20, $value, 'Some message');
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertEqualsOrAssertSameFloatParameterToSpecificMethodsTypeRector\Fixture;

use PHPUnit\Framework\TestCase;

final class KeepDeltaMessage extends TestCase
{
public function test()
{
$value = 10.20001;
$this->assertEqualsWithDelta(10.20, $value, PHP_FLOAT_EPSILON, 'Some message');
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,12 @@ public function getRuleDefinition(): RuleDefinition
// code before
<<<'CODE_SAMPLE'
$this->assertSame(10.20, $value);
$this->assertEquals(10.20, $value);
$this->assertEquals(10.200, $value);
$this->assertSame(10, $value);
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
$this->assertEqualsWithDelta(10.20, $value, PHP_FLOAT_EPSILON);
$this->assertEqualsWithDelta(10.20, $value, PHP_FLOAT_EPSILON);
$this->assertEqualsWithDelta(10.200, $value, PHP_FLOAT_EPSILON);
$this->assertSame(10, $value);
CODE_SAMPLE
),
]
Expand Down Expand Up @@ -82,11 +78,17 @@ public function refactor(Node $node): ?Node
return null;
}

$customMessageArg = $args[2] ?? null;

$newMethodCall = $this->assertCallFactory->createCallWithName($node, 'assertEqualsWithDelta');
$newMethodCall->args[0] = $args[0];
$newMethodCall->args[1] = $args[1];
$newMethodCall->args[2] = new Arg(new ConstFetch(new Name('PHP_FLOAT_EPSILON')));

if ($customMessageArg instanceof Arg) {
$newMethodCall->args[] = $customMessageArg;
}

return $newMethodCall;
}

Expand Down
Loading