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