No Description

StaticConstructorPassTest.php 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /*
  3. * This file is part of Psy Shell
  4. *
  5. * (c) 2012-2014 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\StaticConstructorPass;
  12. class StaticConstructorPassTest extends CodeCleanerTestCase
  13. {
  14. protected function setUp()
  15. {
  16. $this->setPass(new StaticConstructorPass());
  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. /**
  28. * @dataProvider invalidParserStatements
  29. * @expectedException \Psy\Exception\ParseErrorException
  30. */
  31. public function testProcessInvalidStatementCatchedByParser($code)
  32. {
  33. $stmts = $this->parse($code);
  34. $this->traverser->traverse($stmts);
  35. }
  36. public function invalidStatements()
  37. {
  38. $statements = array(
  39. array('class A { public static function A() {}}'),
  40. array('class A { private static function A() {}}'),
  41. );
  42. if (version_compare(PHP_VERSION, '5.3.3', '<')) {
  43. $statements[] = array('namespace B; class A { private static function A() {}}');
  44. }
  45. return $statements;
  46. }
  47. public function invalidParserStatements()
  48. {
  49. $statements = array(
  50. array('class A { public static function __construct() {}}'),
  51. array('class A { private static function __construct() {}}'),
  52. array('class A { private static function __construct() {} public function A() {}}'),
  53. array('namespace B; class A { private static function __construct() {}}'),
  54. );
  55. return $statements;
  56. }
  57. /**
  58. * @dataProvider validStatements
  59. */
  60. public function testProcessValidStatement($code)
  61. {
  62. $stmts = $this->parse($code);
  63. $this->traverser->traverse($stmts);
  64. }
  65. public function validStatements()
  66. {
  67. $statements = array(
  68. array('class A { public static function A() {} public function __construct() {}}'),
  69. array('class A { private function __construct() {} public static function A() {}}'),
  70. );
  71. if (version_compare(PHP_VERSION, '5.3.3', '>=')) {
  72. $statements[] = array('namespace B; class A { private static function A() {}}');
  73. }
  74. return $statements;
  75. }
  76. }