LeavePsyshAlonePassTest.php 1.5 KB

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