ValidConstantPassTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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\ValidConstantPass;
  12. class ValidConstantPassTest extends CodeCleanerTestCase
  13. {
  14. public function setUp()
  15. {
  16. $this->setPass(new ValidConstantPass());
  17. }
  18. /**
  19. * @dataProvider getInvalidReferences
  20. * @expectedException \Psy\Exception\FatalErrorException
  21. */
  22. public function testProcessInvalidConstantReferences($code)
  23. {
  24. $stmts = $this->parse($code);
  25. $this->traverse($stmts);
  26. }
  27. public function getInvalidReferences()
  28. {
  29. return array(
  30. array('Foo\BAR'),
  31. // class constant fetch
  32. array('Psy\Test\CodeCleaner\ValidConstantPassTest::FOO'),
  33. array('DateTime::BACON'),
  34. );
  35. }
  36. /**
  37. * @dataProvider getValidReferences
  38. */
  39. public function testProcessValidConstantReferences($code)
  40. {
  41. $stmts = $this->parse($code);
  42. $this->traverse($stmts);
  43. }
  44. public function getValidReferences()
  45. {
  46. return array(
  47. array('PHP_EOL'),
  48. // class constant fetch
  49. array('NotAClass::FOO'),
  50. array('DateTime::ATOM'),
  51. array('$a = new DateTime; $a::ATOM'),
  52. array('DateTime::class'),
  53. array('$a = new DateTime; $a::class'),
  54. );
  55. }
  56. }