X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fpsy%2Fpsysh%2Ftest%2FReflection%2FReflectionConstantTest.php;fp=vendor%2Fpsy%2Fpsysh%2Ftest%2FReflection%2FReflectionConstantTest.php;h=02c1a8442ef6ffef1b8e826bbe01925644f4de2f;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=713a7e33720194dfc13e8d61a27f4c766712c631;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/vendor/psy/psysh/test/Reflection/ReflectionConstantTest.php b/vendor/psy/psysh/test/Reflection/ReflectionConstantTest.php index 713a7e337..02c1a8442 100644 --- a/vendor/psy/psysh/test/Reflection/ReflectionConstantTest.php +++ b/vendor/psy/psysh/test/Reflection/ReflectionConstantTest.php @@ -11,24 +11,61 @@ namespace Psy\Test\Reflection; -use Psy\Reflection\ReflectionConstant; +use Psy\Reflection\ReflectionConstant_; + +\define('Psy\\Test\\Reflection\\SOME_CONSTANT', 'yep'); class ReflectionConstantTest extends \PHPUnit\Framework\TestCase { - const CONSTANT_ONE = 'one'; - public function testConstruction() { - $refl = new ReflectionConstant($this, 'CONSTANT_ONE'); - $class = $refl->getDeclaringClass(); + $refl = new ReflectionConstant_('Psy\\Test\\Reflection\\SOME_CONSTANT'); - $this->assertInstanceOf('ReflectionClass', $class); - $this->assertSame('Psy\Test\Reflection\ReflectionConstantTest', $class->getName()); - $this->assertSame('CONSTANT_ONE', $refl->getName()); - $this->assertSame('CONSTANT_ONE', (string) $refl); - $this->assertSame('one', $refl->getValue()); - $this->assertNull($refl->getFileName()); $this->assertFalse($refl->getDocComment()); + $this->assertEquals('Psy\\Test\\Reflection\\SOME_CONSTANT', $refl->getName()); + $this->assertEquals('Psy\\Test\\Reflection', $refl->getNamespaceName()); + $this->assertEquals('yep', $refl->getValue()); + $this->assertTrue($refl->inNamespace()); + $this->assertEquals('Psy\\Test\\Reflection\\SOME_CONSTANT', (string) $refl); + $this->assertNull($refl->getFileName()); + } + + public function testBuiltInConstant() + { + $refl = new ReflectionConstant_('PHP_VERSION'); + + $this->assertEquals('PHP_VERSION', $refl->getName()); + $this->assertEquals('PHP_VERSION', (string) $refl); + $this->assertEquals(PHP_VERSION, $refl->getValue()); + $this->assertFalse($refl->inNamespace()); + $this->assertSame('', $refl->getNamespaceName()); + } + + /** + * @dataProvider magicConstants + */ + public function testIsMagicConstant($name, $is) + { + $this->assertEquals($is, ReflectionConstant_::isMagicConstant($name)); + } + + public function magicConstants() + { + return [ + ['__LINE__', true], + ['__FILE__', true], + ['__DIR__', true], + ['__FUNCTION__', true], + ['__CLASS__', true], + ['__TRAIT__', true], + ['__METHOD__', true], + ['__NAMESPACE__', true], + ['__COMPILER_HALT_OFFSET__', true], + ['PHP_VERSION', false], + ['PHP_EOL', false], + ['Psy\\Test\\Reflection\\SOME_CONSTANT', false], + ['What if it isn\'t even a valid constant name?', false], + ]; } /** @@ -36,7 +73,25 @@ class ReflectionConstantTest extends \PHPUnit\Framework\TestCase */ public function testUnknownConstantThrowsException() { - new ReflectionConstant($this, 'UNKNOWN_CONSTANT'); + new ReflectionConstant_('UNKNOWN_CONSTANT'); + } + + public function testExport() + { + $ret = ReflectionConstant_::export('Psy\\Test\\Reflection\\SOME_CONSTANT', true); + $this->assertEquals($ret, 'Constant [ string Psy\\Test\\Reflection\\SOME_CONSTANT ] { yep }'); + } + + public function testExportOutput() + { + $this->expectOutputString("Constant [ string Psy\\Test\\Reflection\\SOME_CONSTANT ] { yep }\n"); + ReflectionConstant_::export('Psy\\Test\\Reflection\\SOME_CONSTANT', false); + } + + public function testGetFileName() + { + $refl = new ReflectionConstant_('Psy\\Test\\Reflection\\SOME_CONSTANT'); + $this->assertNull($refl->getFileName()); } /** @@ -45,7 +100,7 @@ class ReflectionConstantTest extends \PHPUnit\Framework\TestCase */ public function testNotYetImplemented($method) { - $refl = new ReflectionConstant($this, 'CONSTANT_ONE'); + $refl = new ReflectionConstant_('Psy\\Test\\Reflection\\SOME_CONSTANT'); $refl->$method(); } @@ -54,7 +109,6 @@ class ReflectionConstantTest extends \PHPUnit\Framework\TestCase return [ ['getStartLine'], ['getEndLine'], - ['export'], ]; } }