AssignThisVariablePassTest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\AssignThisVariablePass;
  12. /**
  13. * @group isolation-fail
  14. */
  15. class AssignThisVariablePassTest extends CodeCleanerTestCase
  16. {
  17. /**
  18. * @before
  19. */
  20. public function getReady()
  21. {
  22. $this->setPass(new AssignThisVariablePass());
  23. }
  24. /**
  25. * @dataProvider invalidStatements
  26. */
  27. public function testProcessStatementFails($code)
  28. {
  29. $this->expectException(\Psy\Exception\FatalErrorException::class);
  30. $this->parseAndTraverse($code);
  31. $this->fail();
  32. }
  33. public function invalidStatements()
  34. {
  35. return [
  36. ['$this = 3'],
  37. ['strtolower($this = "this")'],
  38. ];
  39. }
  40. /**
  41. * @dataProvider validStatements
  42. */
  43. public function testProcessStatementPasses($code)
  44. {
  45. $this->parseAndTraverse($code);
  46. $this->assertTrue(true);
  47. }
  48. public function validStatements()
  49. {
  50. return [
  51. ['$this'],
  52. ['$a = $this'],
  53. ['$a = "this"; $$a = 3'],
  54. ['$$this = "b"'],
  55. ];
  56. }
  57. }