PhpUnitStrictFixerTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Fixer\PhpUnit;
  12. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  13. /**
  14. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  15. *
  16. * @internal
  17. *
  18. * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitStrictFixer
  19. */
  20. final class PhpUnitStrictFixerTest extends AbstractFixerTestCase
  21. {
  22. /**
  23. * @param string $expected
  24. * @param null|string $input
  25. *
  26. * @dataProvider provideTestFixCases
  27. */
  28. public function testFix($expected, $input = null)
  29. {
  30. $this->doTest($expected, $input);
  31. $this->fixer->configure(['assertions' => [
  32. 'assertAttributeEquals',
  33. 'assertAttributeNotEquals',
  34. 'assertEquals',
  35. 'assertNotEquals',
  36. ]]);
  37. $this->doTest($expected, $input);
  38. }
  39. public function provideTestFixCases()
  40. {
  41. $methodsMap = [
  42. 'assertAttributeEquals' => 'assertAttributeSame',
  43. 'assertAttributeNotEquals' => 'assertAttributeNotSame',
  44. 'assertEquals' => 'assertSame',
  45. 'assertNotEquals' => 'assertNotSame',
  46. ];
  47. $cases = [
  48. ['<?php $self->foo();'],
  49. ];
  50. foreach ($methodsMap as $methodBefore => $methodAfter) {
  51. $cases[] = ["<?php \$sth->${methodBefore}(1, 1);"];
  52. $cases[] = ["<?php \$sth->${methodAfter}(1, 1);"];
  53. $cases[] = [
  54. "<?php \$this->${methodAfter}(1, 2);",
  55. "<?php \$this->${methodBefore}(1, 2);",
  56. ];
  57. $cases[] = [
  58. "<?php \$this->${methodAfter}(1, 2); \$this->${methodAfter}(1, 2);",
  59. "<?php \$this->${methodBefore}(1, 2); \$this->${methodBefore}(1, 2);",
  60. ];
  61. $cases[] = [
  62. "<?php \$this->${methodAfter}(1, 2, 'descr');",
  63. "<?php \$this->${methodBefore}(1, 2, 'descr');",
  64. ];
  65. $cases[] = [
  66. "<?php \$this->/*aaa*/${methodAfter} \t /**bbb*/ ( /*ccc*/1 , 2);",
  67. "<?php \$this->/*aaa*/${methodBefore} \t /**bbb*/ ( /*ccc*/1 , 2);",
  68. ];
  69. $cases[] = [
  70. "<?php \$this->${methodAfter}(\$expectedTokens->count() + 10, \$tokens->count() ? 10 : 20 , 'Test');",
  71. "<?php \$this->${methodBefore}(\$expectedTokens->count() + 10, \$tokens->count() ? 10 : 20 , 'Test');",
  72. ];
  73. }
  74. return $cases;
  75. }
  76. public function testInvalidConfig()
  77. {
  78. $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class);
  79. $this->expectExceptionMessageRegExp('/^\[php_unit_strict\] Invalid configuration: The option "assertions" .*\.$/');
  80. $this->fixer->configure(['assertions' => ['__TEST__']]);
  81. }
  82. }