ReflectionLanguageConstructTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /*
  3. * This file is part of Psy Shell.
  4. *
  5. * (c) 2012-2023 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\Reflection;
  11. use Psy\Reflection\ReflectionLanguageConstruct;
  12. class ReflectionLanguageConstructTest extends \Psy\Test\TestCase
  13. {
  14. /**
  15. * @dataProvider languageConstructs
  16. */
  17. public function testConstruction($keyword)
  18. {
  19. $refl = new ReflectionLanguageConstruct($keyword);
  20. $this->assertSame($keyword, $refl->getName());
  21. $this->assertSame($keyword, (string) $refl);
  22. }
  23. /**
  24. * @dataProvider languageConstructs
  25. */
  26. public function testKnownLanguageConstructs($keyword)
  27. {
  28. $this->assertTrue(ReflectionLanguageConstruct::isLanguageConstruct($keyword));
  29. }
  30. /**
  31. * @dataProvider languageConstructs
  32. */
  33. public function testFileName($keyword)
  34. {
  35. $refl = new ReflectionLanguageConstruct($keyword);
  36. $this->assertFalse($refl->getFileName());
  37. }
  38. /**
  39. * @dataProvider languageConstructs
  40. */
  41. public function testReturnsReference($keyword)
  42. {
  43. $refl = new ReflectionLanguageConstruct($keyword);
  44. $this->assertFalse($refl->returnsReference());
  45. }
  46. /**
  47. * @dataProvider languageConstructs
  48. */
  49. public function testGetParameters($keyword)
  50. {
  51. $refl = new ReflectionLanguageConstruct($keyword);
  52. $this->assertNotEmpty($refl->getParameters());
  53. }
  54. /**
  55. * @dataProvider languageConstructs
  56. */
  57. public function testExportThrows($keyword)
  58. {
  59. $this->expectException(\RuntimeException::class);
  60. ReflectionLanguageConstruct::export($keyword);
  61. $this->fail();
  62. }
  63. public function languageConstructs()
  64. {
  65. return [
  66. ['isset'],
  67. ['unset'],
  68. ['empty'],
  69. ['echo'],
  70. ['print'],
  71. ['die'],
  72. ['exit'],
  73. ];
  74. }
  75. /**
  76. * @dataProvider unknownLanguageConstructs
  77. */
  78. public function testUnknownLanguageConstructsThrowExceptions($keyword)
  79. {
  80. $this->expectException(\InvalidArgumentException::class);
  81. new ReflectionLanguageConstruct($keyword);
  82. $this->fail();
  83. }
  84. public function unknownLanguageConstructs()
  85. {
  86. return [
  87. ['async'],
  88. ['await'],
  89. ['comefrom'],
  90. ];
  91. }
  92. }