ReflectionLanguageConstructTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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\Reflection;
  11. use Psy\Reflection\ReflectionLanguageConstruct;
  12. class ReflectionLanguageConstructTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @dataProvider languageConstructs
  16. */
  17. public function testConstruction($keyword)
  18. {
  19. $refl = new ReflectionLanguageConstruct($keyword);
  20. $this->assertEquals($keyword, $refl->getName());
  21. $this->assertEquals($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. * @expectedException \RuntimeException
  57. */
  58. public function testExportThrows($keyword)
  59. {
  60. ReflectionLanguageConstruct::export($keyword);
  61. }
  62. public function languageConstructs()
  63. {
  64. return [
  65. ['isset'],
  66. ['unset'],
  67. ['empty'],
  68. ['echo'],
  69. ['print'],
  70. ['die'],
  71. ['exit'],
  72. ];
  73. }
  74. /**
  75. * @dataProvider unknownLanguageConstructs
  76. * @expectedException \InvalidArgumentException
  77. */
  78. public function testUnknownLanguageConstructsThrowExceptions($keyword)
  79. {
  80. new ReflectionLanguageConstruct($keyword);
  81. }
  82. public function unknownLanguageConstructs()
  83. {
  84. return [
  85. ['async'],
  86. ['await'],
  87. ['comefrom'],
  88. ];
  89. }
  90. }