4 * This file is part of Psy Shell.
6 * (c) 2012-2018 Justin Hileman
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Psy\Test\Reflection;
14 use Psy\Reflection\ReflectionConstant_;
16 \define('Psy\\Test\\Reflection\\SOME_CONSTANT', 'yep');
18 class ReflectionConstantTest extends \PHPUnit\Framework\TestCase
20 public function testConstruction()
22 $refl = new ReflectionConstant_('Psy\\Test\\Reflection\\SOME_CONSTANT');
24 $this->assertFalse($refl->getDocComment());
25 $this->assertEquals('Psy\\Test\\Reflection\\SOME_CONSTANT', $refl->getName());
26 $this->assertEquals('Psy\\Test\\Reflection', $refl->getNamespaceName());
27 $this->assertEquals('yep', $refl->getValue());
28 $this->assertTrue($refl->inNamespace());
29 $this->assertEquals('Psy\\Test\\Reflection\\SOME_CONSTANT', (string) $refl);
30 $this->assertNull($refl->getFileName());
33 public function testBuiltInConstant()
35 $refl = new ReflectionConstant_('PHP_VERSION');
37 $this->assertEquals('PHP_VERSION', $refl->getName());
38 $this->assertEquals('PHP_VERSION', (string) $refl);
39 $this->assertEquals(PHP_VERSION, $refl->getValue());
40 $this->assertFalse($refl->inNamespace());
41 $this->assertSame('', $refl->getNamespaceName());
45 * @dataProvider magicConstants
47 public function testIsMagicConstant($name, $is)
49 $this->assertEquals($is, ReflectionConstant_::isMagicConstant($name));
52 public function magicConstants()
58 ['__FUNCTION__', true],
62 ['__NAMESPACE__', true],
63 ['__COMPILER_HALT_OFFSET__', true],
64 ['PHP_VERSION', false],
66 ['Psy\\Test\\Reflection\\SOME_CONSTANT', false],
67 ['What if it isn\'t even a valid constant name?', false],
72 * @expectedException \InvalidArgumentException
74 public function testUnknownConstantThrowsException()
76 new ReflectionConstant_('UNKNOWN_CONSTANT');
79 public function testExport()
81 $ret = ReflectionConstant_::export('Psy\\Test\\Reflection\\SOME_CONSTANT', true);
82 $this->assertEquals($ret, 'Constant [ string Psy\\Test\\Reflection\\SOME_CONSTANT ] { yep }');
85 public function testExportOutput()
87 $this->expectOutputString("Constant [ string Psy\\Test\\Reflection\\SOME_CONSTANT ] { yep }\n");
88 ReflectionConstant_::export('Psy\\Test\\Reflection\\SOME_CONSTANT', false);
91 public function testGetFileName()
93 $refl = new ReflectionConstant_('Psy\\Test\\Reflection\\SOME_CONSTANT');
94 $this->assertNull($refl->getFileName());
98 * @expectedException \RuntimeException
99 * @dataProvider notYetImplemented
101 public function testNotYetImplemented($method)
103 $refl = new ReflectionConstant_('Psy\\Test\\Reflection\\SOME_CONSTANT');
107 public function notYetImplemented()