InstanceOfPassTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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\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. $stmts = $this->parse($code);
  25. $this->traverser->traverse($stmts);
  26. }
  27. public function invalidStatements()
  28. {
  29. return array(
  30. array('null instanceof stdClass'),
  31. array('true instanceof stdClass'),
  32. array('9 instanceof stdClass'),
  33. array('1.0 instanceof stdClass'),
  34. array('"foo" instanceof stdClass'),
  35. array('__DIR__ instanceof stdClass'),
  36. array('PHP_SAPI instanceof stdClass'),
  37. array('1+1 instanceof stdClass'),
  38. array('true && false instanceof stdClass'),
  39. array('"a"."b" instanceof stdClass'),
  40. array('!5 instanceof stdClass'),
  41. );
  42. }
  43. /**
  44. * @dataProvider validStatements
  45. */
  46. public function testProcessValidStatement($code)
  47. {
  48. $stmts = $this->parse($code);
  49. $this->traverser->traverse($stmts);
  50. }
  51. public function validStatements()
  52. {
  53. $data = array(
  54. array('$a instanceof stdClass'),
  55. array('strtolower("foo") instanceof stdClass'),
  56. array('array(1) instanceof stdClass'),
  57. array('(string) "foo" instanceof stdClass'),
  58. array('(1+1) instanceof stdClass'),
  59. array('"foo ${foo} $bar" instanceof stdClass'),
  60. array('DateTime::ISO8601 instanceof stdClass'),
  61. );
  62. return $data;
  63. }
  64. }