Nav apraksta

ValidConstantPassTest.php 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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\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. $this->parseAndTraverse($code);
  25. }
  26. public function getInvalidReferences()
  27. {
  28. return [
  29. ['Foo\BAR'],
  30. // class constant fetch
  31. ['Psy\Test\CodeCleaner\ValidConstantPassTest::FOO'],
  32. ['DateTime::BACON'],
  33. ];
  34. }
  35. /**
  36. * @dataProvider getValidReferences
  37. */
  38. public function testProcessValidConstantReferences($code)
  39. {
  40. $this->parseAndTraverse($code);
  41. $this->assertTrue(true);
  42. }
  43. public function getValidReferences()
  44. {
  45. return [
  46. ['PHP_EOL'],
  47. // class constant fetch
  48. ['NotAClass::FOO'],
  49. ['DateTime::ATOM'],
  50. ['$a = new DateTime; $a::ATOM'],
  51. ['DateTime::class'],
  52. ['$a = new DateTime; $a::class'],
  53. ];
  54. }
  55. }