ReflectionClassConstantTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\ReflectionClassConstant;
  12. class ReflectionClassConstantTest extends \PHPUnit\Framework\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);
  20. $this->assertSame('Psy\Test\Reflection\ReflectionClassConstantTest', $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. /**
  28. * @expectedException \InvalidArgumentException
  29. */
  30. public function testUnknownConstantThrowsException()
  31. {
  32. new ReflectionClassConstant($this, 'UNKNOWN_CONSTANT');
  33. }
  34. public function testExport()
  35. {
  36. $ret = ReflectionClassConstant::export($this, 'CONSTANT_ONE', true);
  37. $this->assertEquals($ret, 'Constant [ public string CONSTANT_ONE ] { one }');
  38. }
  39. public function testExportOutput()
  40. {
  41. $this->expectOutputString("Constant [ public string CONSTANT_ONE ] { one }\n");
  42. ReflectionClassConstant::export($this, 'CONSTANT_ONE', false);
  43. }
  44. public function testModifiers()
  45. {
  46. $refl = new ReflectionClassConstant($this, 'CONSTANT_ONE');
  47. $this->assertEquals(\ReflectionMethod::IS_PUBLIC, $refl->getModifiers());
  48. $this->assertFalse($refl->isPrivate());
  49. $this->assertFalse($refl->isProtected());
  50. $this->assertTrue($refl->isPublic());
  51. }
  52. /**
  53. * @expectedException \RuntimeException
  54. * @dataProvider notYetImplemented
  55. */
  56. public function testNotYetImplemented($method)
  57. {
  58. $refl = new ReflectionClassConstant($this, 'CONSTANT_ONE');
  59. $refl->$method();
  60. }
  61. public function notYetImplemented()
  62. {
  63. return [
  64. ['getStartLine'],
  65. ['getEndLine'],
  66. ];
  67. }
  68. }