暫無描述

InstanceOfPassTest.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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\InstanceOfPass;
  12. class InstanceOfPassTest extends CodeCleanerTestCase
  13. {
  14. protected function setUp()
  15. {
  16. $this->setPass(new InstanceOfPass());
  17. }
  18. /**
  19. * @dataProvider invalidStatements
  20. * @expectedException \Psy\Exception\FatalErrorException
  21. */
  22. public function testProcessInvalidStatement($code)
  23. {
  24. $this->parseAndTraverse($code);
  25. }
  26. public function invalidStatements()
  27. {
  28. return [
  29. ['null instanceof stdClass'],
  30. ['true instanceof stdClass'],
  31. ['9 instanceof stdClass'],
  32. ['1.0 instanceof stdClass'],
  33. ['"foo" instanceof stdClass'],
  34. ['__DIR__ instanceof stdClass'],
  35. ['PHP_SAPI instanceof stdClass'],
  36. ['1+1 instanceof stdClass'],
  37. ['true && false instanceof stdClass'],
  38. ['"a"."b" instanceof stdClass'],
  39. ['!5 instanceof stdClass'],
  40. ];
  41. }
  42. /**
  43. * @dataProvider validStatements
  44. */
  45. public function testProcessValidStatement($code)
  46. {
  47. $this->parseAndTraverse($code);
  48. $this->assertTrue(true);
  49. }
  50. public function validStatements()
  51. {
  52. $data = [
  53. ['$a instanceof stdClass'],
  54. ['strtolower("foo") instanceof stdClass'],
  55. ['array(1) instanceof stdClass'],
  56. ['(string) "foo" instanceof stdClass'],
  57. ['(1+1) instanceof stdClass'],
  58. ['"foo ${foo} $bar" instanceof stdClass'],
  59. ['DateTime::ISO8601 instanceof stdClass'],
  60. ];
  61. return $data;
  62. }
  63. }