PhpUnitMockFixerTest.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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\Fixer\PhpUnit\PhpUnitTargetVersion;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\PhpUnit\PhpUnitMockFixer
  20. */
  21. final class PhpUnitMockFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @param string $expected
  25. * @param null|string $input
  26. *
  27. * @dataProvider provideTestFixCases
  28. */
  29. public function testFix($expected, $input = null, array $config = [])
  30. {
  31. $this->fixer->configure($config);
  32. $this->doTest($expected, $input);
  33. }
  34. public function provideTestFixCases()
  35. {
  36. return [
  37. [
  38. '<?php
  39. final class MyTest extends \PHPUnit_Framework_TestCase
  40. {
  41. public function testFoo()
  42. {
  43. $this->createMock("Foo");
  44. }
  45. }',
  46. '<?php
  47. final class MyTest extends \PHPUnit_Framework_TestCase
  48. {
  49. public function testFoo()
  50. {
  51. $this->getMockWithoutInvokingTheOriginalConstructor("Foo");
  52. }
  53. }',
  54. ],
  55. [
  56. '<?php
  57. final class MyTest extends \PHPUnit_Framework_TestCase
  58. {
  59. public function testFoo()
  60. {
  61. $this->createMock("Foo");
  62. $this->createMock($foo(1, 2));
  63. $this->getMock("Foo", ["aaa"]);
  64. }
  65. }',
  66. '<?php
  67. final class MyTest extends \PHPUnit_Framework_TestCase
  68. {
  69. public function testFoo()
  70. {
  71. $this->getMock("Foo");
  72. $this->getMock($foo(1, 2));
  73. $this->getMock("Foo", ["aaa"]);
  74. }
  75. }',
  76. ['target' => PhpUnitTargetVersion::VERSION_5_4],
  77. ],
  78. [
  79. '<?php
  80. final class MyTest extends \PHPUnit_Framework_TestCase
  81. {
  82. public function testFoo()
  83. {
  84. $this->createMock("Foo");
  85. $this->createMock($foo(1, 2));
  86. $this->createPartialMock("Foo", ["aaa"]);
  87. $this->getMock("Foo", ["aaa"], ["argument"]);
  88. }
  89. }',
  90. '<?php
  91. final class MyTest extends \PHPUnit_Framework_TestCase
  92. {
  93. public function testFoo()
  94. {
  95. $this->getMock("Foo");
  96. $this->getMock($foo(1, 2));
  97. $this->getMock("Foo", ["aaa"]);
  98. $this->getMock("Foo", ["aaa"], ["argument"]);
  99. }
  100. }',
  101. ],
  102. ];
  103. }
  104. /**
  105. * @requires PHP 7.3
  106. */
  107. public function testFix73()
  108. {
  109. $this->doTest(
  110. '<?php
  111. class FooTest extends TestCase
  112. {
  113. public function testFoo()
  114. {
  115. $this->createMock("Foo",);
  116. $this->createMock("Bar" ,);
  117. $this->createMock("Baz" , );
  118. $this->createMock($foo(1, 2), );
  119. $this->createMock($foo(3, 4, ));
  120. $this->createMock($foo(5, 6, ), );
  121. $this->createPartialMock("Foo", ["aaa"], );
  122. $this->createPartialMock("Foo", ["bbb", ], );
  123. $this->getMock("Foo", ["aaa"], ["argument"], );
  124. $this->getMock("Foo", ["bbb", ], ["argument", ], );
  125. }
  126. }',
  127. '<?php
  128. class FooTest extends TestCase
  129. {
  130. public function testFoo()
  131. {
  132. $this->getMock("Foo",);
  133. $this->getMock("Bar" ,);
  134. $this->getMock("Baz" , );
  135. $this->getMock($foo(1, 2), );
  136. $this->getMock($foo(3, 4, ));
  137. $this->getMock($foo(5, 6, ), );
  138. $this->getMock("Foo", ["aaa"], );
  139. $this->getMock("Foo", ["bbb", ], );
  140. $this->getMock("Foo", ["aaa"], ["argument"], );
  141. $this->getMock("Foo", ["bbb", ], ["argument", ], );
  142. }
  143. }'
  144. );
  145. }
  146. }