PhpUnitDedicateAssertInternalTypeFixerTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Fixer\PhpUnit;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Filippo Tessarotto <zoeslam@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertInternalTypeFixer
  20. *
  21. * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertInternalTypeFixer>
  22. *
  23. * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertInternalTypeFixer
  24. */
  25. final class PhpUnitDedicateAssertInternalTypeFixerTest extends AbstractFixerTestCase
  26. {
  27. /**
  28. * @dataProvider provideFixCases
  29. */
  30. public function testFix(string $expected, ?string $input = null): void
  31. {
  32. $this->doTest($expected, $input);
  33. }
  34. /**
  35. * @return iterable<string, array{0: string, 1?: string}>
  36. */
  37. public static function provideFixCases(): iterable
  38. {
  39. yield 'skip cases' => [
  40. '<?php
  41. final class MyTest extends \PhpUnit\FrameWork\TestCase
  42. {
  43. public function testMe()
  44. {
  45. $this->assertInternalType(gettype($expectedVar), $var);
  46. $this->assertNotInternalType(gettype($expectedVar), $var);
  47. $this->assertInternalType("foo", $var);
  48. $this->assertNotInternalType("bar", $var);
  49. $this->assertInternalType();
  50. $this->assertNotInternalType();
  51. $this->assertInternalType("array" . "foo", $var);
  52. $this->assertNotInternalType(\'bool\' . "bar", $var);
  53. }
  54. }
  55. ',
  56. ];
  57. yield 'expected normal cases' => [
  58. '<?php
  59. final class MyTest extends \PhpUnit\FrameWork\TestCase
  60. {
  61. public function testMe()
  62. {
  63. $this->assertIsArray($var);
  64. $this->assertIsBool($var);
  65. $this->assertIsBool($var);
  66. $this->assertIsFloat($var);
  67. $this->assertIsFloat($var);
  68. $this->assertIsInt($var);
  69. $this->assertIsInt($var);
  70. $this->assertNull($var);
  71. $this->assertIsNumeric($var);
  72. $this->assertIsObject($var);
  73. $this->assertIsFloat($var);
  74. $this->assertIsResource($var);
  75. $this->assertIsString($var);
  76. $this->assertIsScalar($var);
  77. $this->assertIsCallable($var);
  78. $this->assertIsIterable($var);
  79. $this->assertIsNotArray($var);
  80. $this->assertIsNotBool($var);
  81. $this->assertIsNotBool($var);
  82. $this->assertIsNotFloat($var);
  83. $this->assertIsNotFloat($var);
  84. $this->assertIsNotInt($var);
  85. $this->assertIsNotInt($var);
  86. $this->assertNotNull($var);
  87. $this->assertIsNotNumeric($var);
  88. $this->assertIsNotObject($var);
  89. $this->assertIsNotFloat($var);
  90. $this->assertIsNotResource($var);
  91. $this->assertIsNotString($var);
  92. $this->assertIsNotScalar($var);
  93. $this->assertIsNotCallable($var);
  94. $this->assertIsNotIterable($var);
  95. }
  96. }
  97. ',
  98. '<?php
  99. final class MyTest extends \PhpUnit\FrameWork\TestCase
  100. {
  101. public function testMe()
  102. {
  103. $this->assertInternalType(\'array\', $var);
  104. $this->assertInternalType("boolean", $var);
  105. $this->assertInternalType("bool", $var);
  106. $this->assertInternalType("double", $var);
  107. $this->assertInternalType("float", $var);
  108. $this->assertInternalType("integer", $var);
  109. $this->assertInternalType("int", $var);
  110. $this->assertInternalType("null", $var);
  111. $this->assertInternalType("numeric", $var);
  112. $this->assertInternalType("object", $var);
  113. $this->assertInternalType("real", $var);
  114. $this->assertInternalType("resource", $var);
  115. $this->assertInternalType("string", $var);
  116. $this->assertInternalType("scalar", $var);
  117. $this->assertInternalType("callable", $var);
  118. $this->assertInternalType("iterable", $var);
  119. $this->assertNotInternalType("array", $var);
  120. $this->assertNotInternalType("boolean", $var);
  121. $this->assertNotInternalType("bool", $var);
  122. $this->assertNotInternalType("double", $var);
  123. $this->assertNotInternalType("float", $var);
  124. $this->assertNotInternalType("integer", $var);
  125. $this->assertNotInternalType("int", $var);
  126. $this->assertNotInternalType("null", $var);
  127. $this->assertNotInternalType("numeric", $var);
  128. $this->assertNotInternalType("object", $var);
  129. $this->assertNotInternalType("real", $var);
  130. $this->assertNotInternalType("resource", $var);
  131. $this->assertNotInternalType("string", $var);
  132. $this->assertNotInternalType("scalar", $var);
  133. $this->assertNotInternalType("callable", $var);
  134. $this->assertNotInternalType("iterable", $var);
  135. }
  136. }
  137. ',
  138. ];
  139. yield 'false positive cases' => [
  140. '<?php
  141. final class MyTest extends \PhpUnit\FrameWork\TestCase
  142. {
  143. public function testMe()
  144. {
  145. $this->assertInternalType = 42;
  146. $this->assertNotInternalType = 43;
  147. }
  148. }
  149. ',
  150. ];
  151. yield 'anonymous class false positive case' => [
  152. '<?php
  153. final class MyTest extends \PhpUnit\FrameWork\TestCase
  154. {
  155. public function testMe()
  156. {
  157. $class = new class {
  158. private function assertInternalType()
  159. {}
  160. private function foo(){
  161. $this->assertInternalType("array", $var);
  162. }
  163. };
  164. }
  165. }
  166. ',
  167. ];
  168. }
  169. }