FinalClassPassTest.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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\FinalClassPass;
  12. class FinalClassPassTest extends CodeCleanerTestCase
  13. {
  14. public function setUp()
  15. {
  16. $this->setPass(new FinalClassPass());
  17. }
  18. /**
  19. * @dataProvider invalidStatements
  20. * @expectedException \Psy\Exception\FatalErrorException
  21. */
  22. public function testProcessStatementFails($code)
  23. {
  24. $this->parseAndTraverse($code);
  25. }
  26. public function invalidStatements()
  27. {
  28. $data = [
  29. ['final class A {} class B extends A {}'],
  30. ['class A {} final class B extends A {} class C extends B {}'],
  31. // array('namespace A { final class B {} } namespace C { class D extends \\A\\B {} }'),
  32. ];
  33. if (!\defined('HHVM_VERSION')) {
  34. // For some reason Closure isn't final in HHVM?
  35. $data[] = ['class A extends \\Closure {}'];
  36. }
  37. return $data;
  38. }
  39. /**
  40. * @dataProvider validStatements
  41. */
  42. public function testProcessStatementPasses($code)
  43. {
  44. $this->parseAndTraverse($code);
  45. $this->assertTrue(true);
  46. }
  47. public function validStatements()
  48. {
  49. return [
  50. ['class A extends \\stdClass {}'],
  51. ['final class A extends \\stdClass {}'],
  52. ['class A {} class B extends A {}'],
  53. ];
  54. }
  55. }