02c1a8442ef6ffef1b8e826bbe01925644f4de2f
[yaffs-website] / vendor / psy / psysh / test / Reflection / ReflectionConstantTest.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2018 Justin Hileman
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Psy\Test\Reflection;
13
14 use Psy\Reflection\ReflectionConstant_;
15
16 \define('Psy\\Test\\Reflection\\SOME_CONSTANT', 'yep');
17
18 class ReflectionConstantTest extends \PHPUnit\Framework\TestCase
19 {
20     public function testConstruction()
21     {
22         $refl = new ReflectionConstant_('Psy\\Test\\Reflection\\SOME_CONSTANT');
23
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());
31     }
32
33     public function testBuiltInConstant()
34     {
35         $refl = new ReflectionConstant_('PHP_VERSION');
36
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());
42     }
43
44     /**
45      * @dataProvider magicConstants
46      */
47     public function testIsMagicConstant($name, $is)
48     {
49         $this->assertEquals($is, ReflectionConstant_::isMagicConstant($name));
50     }
51
52     public function magicConstants()
53     {
54         return [
55             ['__LINE__', true],
56             ['__FILE__', true],
57             ['__DIR__', true],
58             ['__FUNCTION__', true],
59             ['__CLASS__', true],
60             ['__TRAIT__', true],
61             ['__METHOD__', true],
62             ['__NAMESPACE__', true],
63             ['__COMPILER_HALT_OFFSET__', true],
64             ['PHP_VERSION', false],
65             ['PHP_EOL', false],
66             ['Psy\\Test\\Reflection\\SOME_CONSTANT', false],
67             ['What if it isn\'t even a valid constant name?', false],
68         ];
69     }
70
71     /**
72      * @expectedException \InvalidArgumentException
73      */
74     public function testUnknownConstantThrowsException()
75     {
76         new ReflectionConstant_('UNKNOWN_CONSTANT');
77     }
78
79     public function testExport()
80     {
81         $ret = ReflectionConstant_::export('Psy\\Test\\Reflection\\SOME_CONSTANT', true);
82         $this->assertEquals($ret, 'Constant [ string Psy\\Test\\Reflection\\SOME_CONSTANT ] { yep }');
83     }
84
85     public function testExportOutput()
86     {
87         $this->expectOutputString("Constant [ string Psy\\Test\\Reflection\\SOME_CONSTANT ] { yep }\n");
88         ReflectionConstant_::export('Psy\\Test\\Reflection\\SOME_CONSTANT', false);
89     }
90
91     public function testGetFileName()
92     {
93         $refl = new ReflectionConstant_('Psy\\Test\\Reflection\\SOME_CONSTANT');
94         $this->assertNull($refl->getFileName());
95     }
96
97     /**
98      * @expectedException \RuntimeException
99      * @dataProvider notYetImplemented
100      */
101     public function testNotYetImplemented($method)
102     {
103         $refl = new ReflectionConstant_('Psy\\Test\\Reflection\\SOME_CONSTANT');
104         $refl->$method();
105     }
106
107     public function notYetImplemented()
108     {
109         return [
110             ['getStartLine'],
111             ['getEndLine'],
112         ];
113     }
114 }