Browse Source

PhpUnitDedicateAssertFixer - remove `is_resource`.

Pol Dellaiera 3 years ago
parent
commit
2b1ecae344

+ 0 - 1
src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php

@@ -144,7 +144,6 @@ final class PhpUnitDedicateAssertFixer extends AbstractPhpUnitFixer implements C
                 'is_numeric',
                 'is_numeric',
                 'is_object',
                 'is_object',
                 'is_real',
                 'is_real',
-                'is_resource',
                 'is_scalar',
                 'is_scalar',
                 'is_string',
                 'is_string',
             ]);
             ]);

+ 8 - 1
tests/Fixer/PhpUnit/PhpUnitDedicateAssertFixerTest.php

@@ -159,7 +159,7 @@ $this->assertTrue(is_readable($a));
             ],
             ],
         ];
         ];
 
 
-        foreach (['array', 'bool', 'callable', 'double', 'float', 'int', 'integer', 'long', 'numeric', 'object', 'resource', 'real', 'scalar', 'string'] as $type) {
+        foreach (['array', 'bool', 'callable', 'double', 'float', 'int', 'integer', 'long', 'numeric', 'object', 'real', 'scalar', 'string'] as $type) {
             yield [
             yield [
                 self::generateTest(sprintf('$this->assertInternalType(\'%s\', $a);', $type)),
                 self::generateTest(sprintf('$this->assertInternalType(\'%s\', $a);', $type)),
                 self::generateTest(sprintf('$this->assertTrue(is_%s($a));', $type)),
                 self::generateTest(sprintf('$this->assertTrue(is_%s($a));', $type)),
@@ -307,6 +307,13 @@ $a#
         yield 'not in class' => [
         yield 'not in class' => [
             '<?php self::assertTrue(is_null($a));',
             '<?php self::assertTrue(is_null($a));',
         ];
         ];
+
+        // Do not replace is_resource() by assertIsResource().
+        // is_resource() also checks if the resource is open or closed,
+        // while assertIsResource() does not.
+        yield 'Do not replace is_resource' => [
+            self::generateTest('self::assertTrue(is_resource($resource));'),
+        ];
     }
     }
 
 
     public function testInvalidConfig(): void
     public function testInvalidConfig(): void