ValidFunctionNamePassTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2015 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Psy\Test\CodeCleaner;
  11. use Psy\CodeCleaner\ValidFunctionNamePass;
  12. class ValidFunctionNamePassTest extends CodeCleanerTestCase
  13. {
  14. public function setUp()
  15. {
  16. $this->setPass(new ValidFunctionNamePass());
  17. }
  18. /**
  19. * @dataProvider getInvalidFunctions
  20. * @expectedException \Psy\Exception\FatalErrorException
  21. */
  22. public function testProcessInvalidFunctionCallsAndDeclarations($code)
  23. {
  24. $stmts = $this->parse($code);
  25. $this->traverse($stmts);
  26. }
  27. public function getInvalidFunctions()
  28. {
  29. return array(
  30. // function declarations
  31. array('function array_merge() {}'),
  32. array('function Array_Merge() {}'),
  33. array('
  34. function psy_test_codecleaner_validfunctionnamepass_alpha() {}
  35. function psy_test_codecleaner_validfunctionnamepass_alpha() {}
  36. '),
  37. array('
  38. namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
  39. function beta() {}
  40. }
  41. namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
  42. function beta() {}
  43. }
  44. '),
  45. // function calls
  46. array('psy_test_codecleaner_validfunctionnamepass_gamma()'),
  47. array('
  48. namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
  49. delta();
  50. }
  51. '),
  52. // recursion
  53. array('function a() { a(); } function a() {}'),
  54. );
  55. }
  56. /**
  57. * @dataProvider getValidFunctions
  58. */
  59. public function testProcessValidFunctionCallsAndDeclarations($code)
  60. {
  61. $stmts = $this->parse($code);
  62. $this->traverse($stmts);
  63. }
  64. public function getValidFunctions()
  65. {
  66. return array(
  67. array('function psy_test_codecleaner_validfunctionnamepass_epsilon() {}'),
  68. array('
  69. namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
  70. function zeta() {}
  71. }
  72. '),
  73. array('
  74. namespace {
  75. function psy_test_codecleaner_validfunctionnamepass_eta() {}
  76. }
  77. namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
  78. function psy_test_codecleaner_validfunctionnamepass_eta() {}
  79. }
  80. '),
  81. array('
  82. namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
  83. function psy_test_codecleaner_validfunctionnamepass_eta() {}
  84. }
  85. namespace {
  86. function psy_test_codecleaner_validfunctionnamepass_eta() {}
  87. }
  88. '),
  89. array('
  90. namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
  91. function array_merge() {}
  92. }
  93. '),
  94. // function calls
  95. array('array_merge();'),
  96. array('
  97. namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
  98. function theta() {}
  99. }
  100. namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
  101. theta();
  102. }
  103. '),
  104. // closures
  105. array('$test = function(){};$test()'),
  106. array('
  107. namespace Psy\\Test\\CodeCleaner\\ValidFunctionNamePass {
  108. function theta() {}
  109. }
  110. namespace {
  111. Psy\\Test\\CodeCleaner\\ValidFunctionNamePass\\theta();
  112. }
  113. '),
  114. // recursion
  115. array('function a() { a(); }'),
  116. );
  117. }
  118. }