AssignThisVariablePassTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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\AssignThisVariablePass;
  12. class AssignThisVariablePassTest extends CodeCleanerTestCase
  13. {
  14. public function setUp()
  15. {
  16. $this->setPass(new AssignThisVariablePass());
  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. ['$this = 3'],
  30. ['strtolower($this = "this")'],
  31. ];
  32. }
  33. /**
  34. * @dataProvider validStatements
  35. */
  36. public function testProcessStatementPasses($code)
  37. {
  38. $this->parseAndTraverse($code);
  39. $this->assertTrue(true);
  40. }
  41. public function validStatements()
  42. {
  43. return [
  44. ['$this'],
  45. ['$a = $this'],
  46. ['$a = "this"; $$a = 3'],
  47. ['$$this = "b"'],
  48. ];
  49. }
  50. }