PassableByReferencePassTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2018 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\PassableByReferencePass;
  12. class PassableByReferencePassTest extends CodeCleanerTestCase
  13. {
  14. public function setUp()
  15. {
  16. $this->setPass(new PassableByReferencePass());
  17. }
  18. /**
  19. * @dataProvider invalidStatements
  20. * @expectedException \Psy\Exception\FatalErrorException
  21. */
  22. public function testProcessStatementFails($code)
  23. {
  24. $this->parseAndTraverse($code);
  25. }
  26. public function invalidStatements()
  27. {
  28. return [
  29. ['array_pop(array())'],
  30. ['array_pop(array($foo))'],
  31. ['array_shift(array())'],
  32. ];
  33. }
  34. /**
  35. * @dataProvider validStatements
  36. */
  37. public function testProcessStatementPasses($code)
  38. {
  39. $this->parseAndTraverse($code);
  40. $this->assertTrue(true);
  41. }
  42. public function validStatements()
  43. {
  44. return [
  45. ['array_pop(json_decode("[]"))'],
  46. ['array_pop($foo)'],
  47. ['array_pop($foo->bar)'],
  48. ['array_pop($foo::baz)'],
  49. ['array_pop(Foo::qux)'],
  50. ];
  51. }
  52. /**
  53. * @dataProvider validArrayMultisort
  54. */
  55. public function testArrayMultisort($code)
  56. {
  57. $this->parseAndTraverse($code);
  58. $this->assertTrue(true);
  59. }
  60. public function validArrayMultisort()
  61. {
  62. return [
  63. ['array_multisort($a)'],
  64. ['array_multisort($a, $b)'],
  65. ['array_multisort($a, SORT_NATURAL, $b)'],
  66. ['array_multisort($a, SORT_NATURAL | SORT_FLAG_CASE, $b)'],
  67. ['array_multisort($a, SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE, $b)'],
  68. ['array_multisort($a, SORT_NATURAL | SORT_FLAG_CASE, SORT_ASC, $b)'],
  69. ['array_multisort($a, $b, SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE)'],
  70. ['array_multisort($a, SORT_NATURAL | SORT_FLAG_CASE, $b, SORT_ASC, SORT_NATURAL | SORT_FLAG_CASE)'],
  71. ['array_multisort($a, 1, $b)'],
  72. ['array_multisort($a, 1 + 2, $b)'],
  73. ['array_multisort($a, getMultisortFlags(), $b)'],
  74. ];
  75. }
  76. /**
  77. * @dataProvider invalidArrayMultisort
  78. * @expectedException \Psy\Exception\FatalErrorException
  79. */
  80. public function testInvalidArrayMultisort($code)
  81. {
  82. $this->parseAndTraverse($code);
  83. }
  84. public function invalidArrayMultisort()
  85. {
  86. return [
  87. ['array_multisort(1)'],
  88. ['array_multisort(array(1, 2, 3))'],
  89. ['array_multisort($a, SORT_NATURAL, SORT_ASC, SORT_NATURAL, $b)'],
  90. ];
  91. }
  92. }