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 8] Add rule to cope with PHPUnit deprecating assertArraySubset #2138

Closed
DaveLiddament opened this issue Oct 10, 2019 · 2 comments · Fixed by #2326

Comments

@DaveLiddament
Copy link
Collaborator

@DaveLiddament DaveLiddament commented Oct 10, 2019

PHPUnit has deprecated in v8. It will be removed in v9. It seems like a lot of people, myself included, use this assertion.

The solution proposed is to use dms/phpunit-arraysubset-asserts

NOTE: Composer needs to be run before this rule will work:

composer require --dev dms/phpunit-arraysubset-asserts

Diff

  <?php
  declare(strict_types=1);

  namespace Acme\Tests;

+ use DMS\PHPUnitExtensions\ArraySubset\Assert as AssertArraySubset;
  use PHPUnit\Framework\TestCase;


  final class AssertTest extends TestCase
  {
   
    public function testPreviouslyStaticCall(): void
    {
-    self::assertArraySubset(['bar' => 0], ['bar' => '0'], true);
+    AssertArraySubset::assertArraySubset(['bar' => 0], ['bar' => '0'], true);
    }

    public function testPreviouslyCalledWithThis(): void
    {
-    $this->assertArraySubset(['bar' => 0], ['bar' => '0'], true);
+    AssertArraySubset::assertArraySubset(['bar' => 0], ['bar' => '0'], true);
    }
 }
@TomasVotruba TomasVotruba changed the title Add rule to cope with PHPUnit deprecating assertArraySubset [PHPUnit 8] Add rule to cope with PHPUnit deprecating assertArraySubset Oct 10, 2019
@TomasVotruba

This comment has been minimized.

Copy link
Member

@TomasVotruba TomasVotruba commented Oct 11, 2019

Well, default rules don't need any composer/CLI intervention, so running this would break rules.

Instead we might add it to phpunit80-dms with warning message, it needs to install particula package.

@DaveLiddament

This comment has been minimized.

Copy link
Collaborator Author

@DaveLiddament DaveLiddament commented Oct 12, 2019

@TomasVotruba are you happy for me to have a go at writing this rule?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.