Mercurial > hg > isophonics-drupal-site
comparison vendor/psy/psysh/test/Reflection/ReflectionConstantTest.php @ 16:c2387f117808
Routine composer update
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 15:07:59 +0100 |
parents | 5fb285c0d0e3 |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
15:e200cb7efeb3 | 16:c2387f117808 |
---|---|
9 * file that was distributed with this source code. | 9 * file that was distributed with this source code. |
10 */ | 10 */ |
11 | 11 |
12 namespace Psy\Test\Reflection; | 12 namespace Psy\Test\Reflection; |
13 | 13 |
14 use Psy\Reflection\ReflectionConstant; | 14 use Psy\Reflection\ReflectionConstant_; |
15 | |
16 define('Psy\\Test\\Reflection\\SOME_CONSTANT', 'yep'); | |
15 | 17 |
16 class ReflectionConstantTest extends \PHPUnit\Framework\TestCase | 18 class ReflectionConstantTest extends \PHPUnit\Framework\TestCase |
17 { | 19 { |
18 const CONSTANT_ONE = 'one'; | |
19 | |
20 public function testConstruction() | 20 public function testConstruction() |
21 { | 21 { |
22 $refl = new ReflectionConstant($this, 'CONSTANT_ONE'); | 22 $refl = new ReflectionConstant_('Psy\\Test\\Reflection\\SOME_CONSTANT'); |
23 $class = $refl->getDeclaringClass(); | |
24 | 23 |
25 $this->assertInstanceOf('ReflectionClass', $class); | 24 $this->assertFalse($refl->getDocComment()); |
26 $this->assertSame('Psy\Test\Reflection\ReflectionConstantTest', $class->getName()); | 25 $this->assertEquals('Psy\\Test\\Reflection\\SOME_CONSTANT', $refl->getName()); |
27 $this->assertSame('CONSTANT_ONE', $refl->getName()); | 26 $this->assertEquals('Psy\\Test\\Reflection', $refl->getNamespaceName()); |
28 $this->assertSame('CONSTANT_ONE', (string) $refl); | 27 $this->assertEquals('yep', $refl->getValue()); |
29 $this->assertSame('one', $refl->getValue()); | 28 $this->assertTrue($refl->inNamespace()); |
29 $this->assertEquals('Psy\\Test\\Reflection\\SOME_CONSTANT', (string) $refl); | |
30 $this->assertNull($refl->getFileName()); | 30 $this->assertNull($refl->getFileName()); |
31 $this->assertFalse($refl->getDocComment()); | 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 ]; | |
32 } | 69 } |
33 | 70 |
34 /** | 71 /** |
35 * @expectedException \InvalidArgumentException | 72 * @expectedException \InvalidArgumentException |
36 */ | 73 */ |
37 public function testUnknownConstantThrowsException() | 74 public function testUnknownConstantThrowsException() |
38 { | 75 { |
39 new ReflectionConstant($this, 'UNKNOWN_CONSTANT'); | 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()); | |
40 } | 95 } |
41 | 96 |
42 /** | 97 /** |
43 * @expectedException \RuntimeException | 98 * @expectedException \RuntimeException |
44 * @dataProvider notYetImplemented | 99 * @dataProvider notYetImplemented |
45 */ | 100 */ |
46 public function testNotYetImplemented($method) | 101 public function testNotYetImplemented($method) |
47 { | 102 { |
48 $refl = new ReflectionConstant($this, 'CONSTANT_ONE'); | 103 $refl = new ReflectionConstant_('Psy\\Test\\Reflection\\SOME_CONSTANT'); |
49 $refl->$method(); | 104 $refl->$method(); |
50 } | 105 } |
51 | 106 |
52 public function notYetImplemented() | 107 public function notYetImplemented() |
53 { | 108 { |
54 return [ | 109 return [ |
55 ['getStartLine'], | 110 ['getStartLine'], |
56 ['getEndLine'], | 111 ['getEndLine'], |
57 ['export'], | |
58 ]; | 112 ]; |
59 } | 113 } |
60 } | 114 } |