Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHPUnit 10] Remove AssertIssetToAssertObjectHasPropertyRector #405

Merged
merged 1 commit into from
Nov 10, 2024

Conversation

samsonasik
Copy link
Member

This rule is apply invalid transformation, since isset() is verify if property has null value as well, see https://3v4l.org/KBkr3

so the transformation is invalid.

For transform to assertObjectHasProperty, there is already configured config for that, see

// https://github.com/sebastianbergmann/phpunit/issues/5220
new MethodCallRename('PHPUnit\Framework\Assert', 'assertObjectHasAttribute', 'assertObjectHasProperty'),
new MethodCallRename('PHPUnit\Framework\Assert', 'assertObjectNotHasAttribute', 'assertObjectNotHasProperty'),

which transformable from AssertPropertyExistsRector rule for that, see

final class AssertPropertyExistsRector extends AbstractRector

final class MyTest2 extends \PHPUnit\Framework\TestCase
{
public function test()
{
$response = new \Namespaced\Response();
$this->assertFalse(property_exists($response, 'property'));
}
}
?>
-----
<?php
namespace Rector\PHPUnit\Tests\CodeQuality\Rector\MethodCall\AssertPropertyExistsRector\Fixture;
final class MyTest2 extends \PHPUnit\Framework\TestCase
{
public function test()
{
$response = new \Namespaced\Response();
$this->assertObjectNotHasAttribute('property', $response);
}
}

so combine them will apply the syntax transformation.

@samsonasik
Copy link
Member Author

@TomasVotruba Ready to merge 👍

@TomasVotruba
Copy link
Member

Makes sense, thank you ☺️

@TomasVotruba TomasVotruba merged commit 1e74358 into main Nov 10, 2024
6 checks passed
@TomasVotruba TomasVotruba deleted the remove-assert-isset branch November 10, 2024 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants