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

PhpUnitDedicateAssertFixer is replacing functions with deprecated/removed method names of PHPUnit v9.1+ #7968

Open
2 tasks done
hdcore opened this issue Apr 24, 2024 · 0 comments
Labels
kind/bug status/to verify issue needs to be confirmed or analysed to continue

Comments

@hdcore
Copy link

hdcore commented Apr 24, 2024

Problem description

Since PHPUnit version 9.1 some of the dedicated asserts methods are renamed to a more readable name.
E.g. assertDirectoryNotExists() is renamed to assertDirectoryDoesNotExists()
(see list on https://github.com/sebastianbergmann/phpunit/blob/9.1.0/ChangeLog-9.1.md)
Since PHPUnit version 10 these deprecated methods are removed.

The PhpUnitDedicateAssertFixer is still referencing to the old names
https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php.
So when i'm using PHPUnit version 10+ the fixer will break my code.
it will not work anymore.

Minimal reproducer

Using the rulset: @PHPUnit100Migration:risky with this code:

declare(strict_types=1);

use PHPUnit\Framework\TestCase;

final class test extends TestCase
{
    public function testNotDirectory(): void
    {
        self::assertFalse(is_dir('/doesnotexists'));
        self::assertFalse(file_exists('/doesnotexists.txt'));
    }
}

Result:

C:\xxxxx\test.php (php_unit_dedicate_assert)
      ---------- begin diff ----------
--- C:\xxxx\test.php
+++ C:\xxxxx\test.php
@@ -8,7 +8,7 @@
 {
     public function testNotDirectory(): void
     {
-        self::assertFalse(is_dir('/doesnotexists'));
-        self::assertFalse(file_exists('/doesnotexists.txt'));
+        self::assertDirectoryNotExists('/doesnotexists');
+        self::assertFileNotExists('/doesnotexists.txt');
     }
 }

      ----------- end diff -----------

Must be when using PHPUnit 9.1+:

C:\xxxxx\test.php (php_unit_dedicate_assert)
      ---------- begin diff ----------
--- C:\xxxx\test.php
+++ C:\xxxxx\test.php
@@ -8,7 +8,7 @@
 {
     public function testNotDirectory(): void
     {
-        self::assertFalse(is_dir('/doesnotexists'));
-        self::assertFalse(file_exists('/doesnotexists.txt'));
+        self::assertDirectoryDoesNotExist('/doesnotexists');
+        self::assertFileDoesNotExist('/doesnotexists.txt');
     }
 }

      ----------- end diff -----------

Fixer version

3.54.0

PHP version

8.3.6

How do you run Fixer?

Composer package

Contribution Checks

  • I have verified if this problem was already reported
  • I am familiar with "Feature or bug?"
@hdcore hdcore added kind/bug status/to verify issue needs to be confirmed or analysed to continue labels Apr 24, 2024
krzysztof-ciszewski added a commit to krzysztof-ciszewski/PHP-CS-Fixer that referenced this issue May 8, 2024
krzysztof-ciszewski added a commit to krzysztof-ciszewski/PHP-CS-Fixer that referenced this issue May 8, 2024
krzysztof-ciszewski added a commit to krzysztof-ciszewski/PHP-CS-Fixer that referenced this issue May 8, 2024
krzysztof-ciszewski added a commit to krzysztof-ciszewski/PHP-CS-Fixer that referenced this issue May 9, 2024
krzysztof-ciszewski added a commit to krzysztof-ciszewski/PHP-CS-Fixer that referenced this issue May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug status/to verify issue needs to be confirmed or analysed to continue
Projects
None yet
Development

No branches or pull requests

1 participant