AbstractClassPassTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 PhpParser\NodeTraverser;
  12. use Psy\CodeCleaner\AbstractClassPass;
  13. class AbstractClassPassTest extends CodeCleanerTestCase
  14. {
  15. public function setUp()
  16. {
  17. $this->pass = new AbstractClassPass();
  18. $this->traverser = new NodeTraverser();
  19. $this->traverser->addVisitor($this->pass);
  20. }
  21. /**
  22. * @dataProvider invalidStatements
  23. * @expectedException \Psy\Exception\FatalErrorException
  24. */
  25. public function testProcessStatementFails($code)
  26. {
  27. $stmts = $this->parse($code);
  28. $this->traverser->traverse($stmts);
  29. }
  30. public function invalidStatements()
  31. {
  32. return array(
  33. array('class A { abstract function a(); }'),
  34. array('abstract class B { abstract function b() {} }'),
  35. array('abstract class B { abstract function b() { echo "yep"; } }'),
  36. );
  37. }
  38. /**
  39. * @dataProvider validStatements
  40. */
  41. public function testProcessStatementPasses($code)
  42. {
  43. $stmts = $this->parse($code);
  44. $this->traverser->traverse($stmts);
  45. }
  46. public function validStatements()
  47. {
  48. return array(
  49. array('abstract class C { function c() {} }'),
  50. array('abstract class D { abstract function d(); }'),
  51. );
  52. }
  53. }