LeavePsyshAlonePassTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2023 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\LeavePsyshAlonePass;
  12. /**
  13. * @group isolation-fail
  14. */
  15. class LeavePsyshAlonePassTest extends CodeCleanerTestCase
  16. {
  17. /**
  18. * @before
  19. */
  20. public function getReady()
  21. {
  22. $this->setPass(new LeavePsyshAlonePass());
  23. }
  24. public function testPassesInlineHtmlThroughJustFine()
  25. {
  26. $inline = $this->parse('not php at all!', '');
  27. $this->traverse($inline);
  28. $this->assertTrue(true);
  29. }
  30. /**
  31. * @dataProvider validStatements
  32. */
  33. public function testProcessStatementPasses($code)
  34. {
  35. $this->parseAndTraverse($code);
  36. $this->assertTrue(true);
  37. }
  38. public function validStatements()
  39. {
  40. return [
  41. ['array_merge()'],
  42. ['__psysh__()'],
  43. ['$this'],
  44. ['$psysh'],
  45. ['$__psysh'],
  46. ['$banana'],
  47. ];
  48. }
  49. /**
  50. * @dataProvider invalidStatements
  51. */
  52. public function testProcessStatementFails($code)
  53. {
  54. $this->expectException(\Psy\Exception\RuntimeException::class);
  55. $this->parseAndTraverse($code);
  56. $this->fail();
  57. }
  58. public function invalidStatements()
  59. {
  60. return [
  61. ['$__psysh__'],
  62. ['var_dump($__psysh__)'],
  63. ['$__psysh__ = "your mom"'],
  64. ['$__psysh__->fakeFunctionCall()'],
  65. ];
  66. }
  67. }