AssignThisVariablePassTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 PhpParser\NodeTraverser;
  12. use Psy\CodeCleaner\AssignThisVariablePass;
  13. class AssignThisVariablePassTest extends CodeCleanerTestCase
  14. {
  15. public function setUp()
  16. {
  17. $this->pass = new AssignThisVariablePass();
  18. $this->traverser = new NodeTraverser();
  19. $this->traverser->addVisitor($this->pass);
  20. }
  21. /**
  22. * @dataProvider invalidStatements
  23. * @expectedException \Psy\Exception\FatalErrorException
  24. */
  25. public function testProcessStatementFails($code)
  26. {
  27. $stmts = $this->parse($code);
  28. $this->traverser->traverse($stmts);
  29. }
  30. public function invalidStatements()
  31. {
  32. return array(
  33. array('$this = 3'),
  34. array('strtolower($this = "this")'),
  35. );
  36. }
  37. /**
  38. * @dataProvider validStatements
  39. */
  40. public function testProcessStatementPasses($code)
  41. {
  42. $stmts = $this->parse($code);
  43. $this->traverser->traverse($stmts);
  44. }
  45. public function validStatements()
  46. {
  47. return array(
  48. array('$this'),
  49. array('$a = $this'),
  50. array('$a = "this"; $$a = 3'),
  51. array('$$this = "b"'),
  52. );
  53. }
  54. }