No Description

ValidConstructorPassTest.php 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\ValidConstructorPass;
  12. class ValidConstructorPassTest extends CodeCleanerTestCase
  13. {
  14. protected function setUp()
  15. {
  16. $this->setPass(new ValidConstructorPass());
  17. }
  18. /**
  19. * @dataProvider invalidStatements
  20. * @expectedException \Psy\Exception\FatalErrorException
  21. */
  22. public function testProcessInvalidStatement($code)
  23. {
  24. $this->parseAndTraverse($code);
  25. }
  26. /**
  27. * @dataProvider invalidParserStatements
  28. * @expectedException \Psy\Exception\ParseErrorException
  29. */
  30. public function testProcessInvalidStatementCatchedByParser($code)
  31. {
  32. $this->parseAndTraverse($code);
  33. }
  34. public function invalidStatements()
  35. {
  36. $data = [
  37. ['class A { public static function A() {}}'],
  38. ['class A { public static function a() {}}'],
  39. ['class A { private static function A() {}}'],
  40. ['class A { private static function a() {}}'],
  41. ];
  42. if (\version_compare(PHP_VERSION, '7.0', '>=')) {
  43. $data[] = ['class A { public function A(): ?array {}}'];
  44. $data[] = ['class A { public function a(): ?array {}}'];
  45. }
  46. return $data;
  47. }
  48. public function invalidParserStatements()
  49. {
  50. return [
  51. ['class A { public static function __construct() {}}'],
  52. ['class A { private static function __construct() {}}'],
  53. ['class A { private static function __construct() {} public function A() {}}'],
  54. ['namespace B; class A { private static function __construct() {}}'],
  55. ];
  56. }
  57. /**
  58. * @dataProvider validStatements
  59. */
  60. public function testProcessValidStatement($code)
  61. {
  62. $this->parseAndTraverse($code);
  63. $this->assertTrue(true);
  64. }
  65. public function validStatements()
  66. {
  67. $data = [
  68. ['class A { public static function A() {} public function __construct() {}}'],
  69. ['class A { private function __construct() {} public static function A() {}}'],
  70. ['namespace B; class A { private static function A() {}}'],
  71. ];
  72. if (\version_compare(PHP_VERSION, '7.0', '>=')) {
  73. $data[] = ['class A { public static function A() {} public function __construct() {}}'];
  74. $data[] = ['class A { private function __construct() {} public static function A(): ?array {}}'];
  75. $data[] = ['namespace B; class A { private static function A(): ?array {}}'];
  76. }
  77. return $data;
  78. }
  79. }