ReflectionClassConstantTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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\ReflectionClassConstant;
  12. class ReflectionClassConstantTest extends \Psy\Test\TestCase
  13. {
  14. const CONSTANT_ONE = 'one';
  15. public function testConstruction()
  16. {
  17. $refl = new ReflectionClassConstant($this, 'CONSTANT_ONE');
  18. $class = $refl->getDeclaringClass();
  19. $this->assertInstanceOf(\ReflectionClass::class, $class);
  20. $this->assertSame(self::class, $class->getName());
  21. $this->assertSame('CONSTANT_ONE', $refl->getName());
  22. $this->assertSame('CONSTANT_ONE', (string) $refl);
  23. $this->assertSame('one', $refl->getValue());
  24. $this->assertNull($refl->getFileName());
  25. $this->assertFalse($refl->getDocComment());
  26. }
  27. public function testUnknownConstantThrowsException()
  28. {
  29. $this->expectException(\InvalidArgumentException::class);
  30. new ReflectionClassConstant($this, 'UNKNOWN_CONSTANT');
  31. $this->fail();
  32. }
  33. public function testExport()
  34. {
  35. $ret = ReflectionClassConstant::export($this, 'CONSTANT_ONE', true);
  36. $this->assertSame($ret, 'Constant [ public string CONSTANT_ONE ] { one }');
  37. }
  38. public function testExportOutput()
  39. {
  40. $this->expectOutputString("Constant [ public string CONSTANT_ONE ] { one }\n");
  41. ReflectionClassConstant::export($this, 'CONSTANT_ONE', false);
  42. }
  43. public function testModifiers()
  44. {
  45. $refl = new ReflectionClassConstant($this, 'CONSTANT_ONE');
  46. $this->assertSame(\ReflectionMethod::IS_PUBLIC, $refl->getModifiers());
  47. $this->assertFalse($refl->isPrivate());
  48. $this->assertFalse($refl->isProtected());
  49. $this->assertTrue($refl->isPublic());
  50. }
  51. /**
  52. * @dataProvider notYetImplemented
  53. */
  54. public function testNotYetImplemented($method)
  55. {
  56. $this->expectException(\RuntimeException::class);
  57. $refl = new ReflectionClassConstant($this, 'CONSTANT_ONE');
  58. $refl->$method();
  59. $this->fail();
  60. }
  61. public function notYetImplemented()
  62. {
  63. return [
  64. ['getStartLine'],
  65. ['getEndLine'],
  66. ];
  67. }
  68. }