From 81c0e8413cdde4411c535ac15652d2e291ff930d Mon Sep 17 00:00:00 2001 From: Jonathan Vollebregt Date: Sun, 18 Aug 2024 22:34:17 +0200 Subject: [PATCH] FQCN rewrite --- src/Kint.php | 6 +- src/Parser/ClassMethodsPlugin.php | 2 +- src/Parser/ToStringPlugin.php | 6 +- src/Parser/XmlPlugin.php | 4 +- src/Renderer/PlainRenderer.php | 6 +- tests/IntegrationTest.php | 2 +- tests/KintTest.php | 51 +++++++-------- tests/Parser/ArrayLimitPluginTest.php | 11 ++-- tests/Parser/BlacklistPluginTest.php | 6 +- tests/Parser/FsPathPluginTest.php | 2 +- tests/Parser/ParserTest.php | 34 +++++----- tests/Parser/SerializePluginTest.php | 5 +- tests/Parser/ToStringPluginTest.php | 2 +- tests/Parser/TracePluginTest.php | 4 +- tests/UtilsTest.php | 14 ++--- tests/Zval/BlobValueTest.php | 2 +- tests/Zval/InstanceValueTest.php | 2 +- tests/Zval/MethodValueTest.php | 62 ++++++++++--------- tests/Zval/ParameterHoldingTraitTest.php | 16 ++--- .../ColorRepresentationTest.php | 29 ++++----- .../SplFileInfoRepresentationTest.php | 2 +- tests/bootstrap.php | 2 +- 22 files changed, 141 insertions(+), 129 deletions(-) diff --git a/src/Kint.php b/src/Kint.php index f169474a7..bf4fbbd59 100644 --- a/src/Kint.php +++ b/src/Kint.php @@ -135,9 +135,9 @@ class Kint implements FacadeInterface * @var array Kint aliases. Add debug functions in Kint wrappers here to fix modifiers and backtraces */ public static array $aliases = [ - ['Kint\\Kint', 'dump'], - ['Kint\\Kint', 'trace'], - ['Kint\\Kint', 'dumpAll'], + [self::class, 'dump'], + [self::class, 'trace'], + [self::class, 'dumpAll'], ]; /** diff --git a/src/Parser/ClassMethodsPlugin.php b/src/Parser/ClassMethodsPlugin.php index f74c4fc54..2f6ffffe0 100644 --- a/src/Parser/ClassMethodsPlugin.php +++ b/src/Parser/ClassMethodsPlugin.php @@ -75,7 +75,7 @@ public function parse(&$var, Value &$o, int $trigger): void * @psalm-suppress InvalidArgument * Appears to have been fixed in master */ - \usort($methods, ['Kint\\Parser\\ClassMethodsPlugin', 'sort']); + \usort($methods, [self::class, 'sort']); self::$cache[$class] = $methods; } diff --git a/src/Parser/ToStringPlugin.php b/src/Parser/ToStringPlugin.php index eac35d398..106760f6a 100644 --- a/src/Parser/ToStringPlugin.php +++ b/src/Parser/ToStringPlugin.php @@ -30,12 +30,14 @@ use Kint\Zval\Representation\Representation; use Kint\Zval\Value; use ReflectionClass; +use SimpleXMLElement; +use SplFileObject; class ToStringPlugin extends AbstractPlugin { public static array $blacklist = [ - 'SimpleXMLElement', - 'SplFileObject', + SimpleXMLElement::class, + SplFileObject::class, ]; public function getTypes(): array diff --git a/src/Parser/XmlPlugin.php b/src/Parser/XmlPlugin.php index 0bd749906..f23eabab0 100644 --- a/src/Parser/XmlPlugin.php +++ b/src/Parser/XmlPlugin.php @@ -61,11 +61,11 @@ public function parse(&$var, Value &$o, int $trigger): void return; } - if (!\method_exists(\get_class($this), 'xmlTo'.self::$parse_method)) { + if (!\method_exists(self::class, 'xmlTo'.self::$parse_method)) { return; } - $xml = \call_user_func([\get_class($this), 'xmlTo'.self::$parse_method], $var, $o->access_path); + $xml = \call_user_func([self::class, 'xmlTo'.self::$parse_method], $var, $o->access_path); if (empty($xml)) { return; diff --git a/src/Renderer/PlainRenderer.php b/src/Renderer/PlainRenderer.php index db0f6db98..a2c52092e 100644 --- a/src/Renderer/PlainRenderer.php +++ b/src/Renderer/PlainRenderer.php @@ -35,11 +35,11 @@ class PlainRenderer extends TextRenderer { public static array $pre_render_sources = [ 'script' => [ - ['Kint\\Renderer\\PlainRenderer', 'renderJs'], - ['Kint\\Renderer\\Text\\MicrotimePlugin', 'renderJs'], + [self::class, 'renderJs'], + [Text\MicrotimePlugin::class, 'renderJs'], ], 'style' => [ - ['Kint\\Renderer\\PlainRenderer', 'renderCss'], + [self::class, 'renderCss'], ], 'raw' => [], ]; diff --git a/tests/IntegrationTest.php b/tests/IntegrationTest.php index b33b9f4ef..d8d88f53d 100644 --- a/tests/IntegrationTest.php +++ b/tests/IntegrationTest.php @@ -529,7 +529,7 @@ public function testToplevelTracedumpNoCallerMatch() $bt = \debug_backtrace(); $d2 = Kint::trace(); - Kint::$aliases = [['Kint\\Kint', 'dump']]; + Kint::$aliases = [[Kint::class, 'dump']]; $d1 = \preg_replace('/^\\$bt\\b/', 'Kint\\Kint::trace()', Kint::dump($bt)); $this->assertSame($d1, $d2); diff --git a/tests/KintTest.php b/tests/KintTest.php index 062531cc7..cae2da6c1 100644 --- a/tests/KintTest.php +++ b/tests/KintTest.php @@ -27,6 +27,7 @@ namespace Kint\Test; +use InvalidArgumentException; use Kint\Kint; use Kint\Parser\ConstructablePluginInterface; use Kint\Parser\Parser; @@ -149,7 +150,7 @@ public function testSetStatesFromStatics() */ public function testSetStatesFromStaticsStringPlugins() { - $r = new ReflectionProperty('Kint\\Kint', 'plugin_pool'); + $r = new ReflectionProperty(Kint::class, 'plugin_pool'); $r->setAccessible(true); $r->setValue([]); @@ -159,8 +160,8 @@ public function testSetStatesFromStaticsStringPlugins() $statics = [ 'plugins' => [ - 'Kint\\Parser\\TimestampPlugin', - 'Kint\\Parser\\MicrotimePlugin', + TimestampPlugin::class, + \Kint\Parser\MicrotimePlugin::class, ], ]; @@ -310,7 +311,7 @@ public function testDumpNothing() */ public function testDumpAllUnmatchingArgs() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $p = new Parser(); $r = new TextRenderer(); @@ -324,7 +325,7 @@ public function testDumpAllUnmatchingArgs() */ public function testDumpAllIncorrectBase() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $p = new Parser(); $r = new TextRenderer(); @@ -367,12 +368,12 @@ public function staticModeProvider() 'cli_detection' => false, 'mode_default_cli' => 43, 'renderers' => [ - 42 => 'Kint\\Renderer\\RichRenderer', - 43 => 'Kint\\Renderer\\CliRenderer', - 44 => 'Kint\\Renderer\\PlainRenderer', + 42 => \Kint\Renderer\RichRenderer::class, + 43 => \Kint\Renderer\CliRenderer::class, + 44 => \Kint\Renderer\PlainRenderer::class, ], ], - 'Kint\\Renderer\\RichRenderer', + \Kint\Renderer\RichRenderer::class, ], 'auto with cli' => [ [ @@ -381,12 +382,12 @@ public function staticModeProvider() 'cli_detection' => true, 'mode_default_cli' => 43, 'renderers' => [ - 42 => 'Kint\\Renderer\\RichRenderer', - 43 => 'Kint\\Renderer\\CliRenderer', - 44 => 'Kint\\Renderer\\PlainRenderer', + 42 => \Kint\Renderer\RichRenderer::class, + 43 => \Kint\Renderer\CliRenderer::class, + 44 => \Kint\Renderer\PlainRenderer::class, ], ], - 'Kint\\Renderer\\CliRenderer', + \Kint\Renderer\CliRenderer::class, ], 'specific' => [ [ @@ -395,12 +396,12 @@ public function staticModeProvider() 'cli_detection' => true, 'mode_default_cli' => 43, 'renderers' => [ - 42 => 'Kint\\Renderer\\RichRenderer', - 43 => 'Kint\\Renderer\\CliRenderer', - 44 => 'Kint\\Renderer\\PlainRenderer', + 42 => \Kint\Renderer\RichRenderer::class, + 43 => \Kint\Renderer\CliRenderer::class, + 44 => \Kint\Renderer\PlainRenderer::class, ], ], - 'Kint\\Renderer\\PlainRenderer', + \Kint\Renderer\PlainRenderer::class, ], 'disabled' => [ ['enabled_mode' => false], @@ -413,12 +414,12 @@ public function staticModeProvider() 'cli_detection' => true, 'mode_default_cli' => 43, 'renderers' => [ - 42 => 'Kint\\Renderer\\RichRenderer', - 43 => 'Kint\\Renderer\\CliRenderer', - 44 => 'Kint\\Renderer\\PlainRenderer', + 42 => \Kint\Renderer\RichRenderer::class, + 43 => \Kint\Renderer\CliRenderer::class, + 44 => \Kint\Renderer\PlainRenderer::class, ], ], - 'Kint\\Renderer\\TextRenderer', + TextRenderer::class, ], 'falsey renderer' => [ [ @@ -427,12 +428,12 @@ public function staticModeProvider() 'cli_detection' => false, 'mode_default_cli' => 1, 'renderers' => [ - 0 => 'Kint\\Renderer\\RichRenderer', - 1 => 'Kint\\Renderer\\CliRenderer', - 2 => 'Kint\\Renderer\\PlainRenderer', + 0 => \Kint\Renderer\RichRenderer::class, + 1 => \Kint\Renderer\CliRenderer::class, + 2 => \Kint\Renderer\PlainRenderer::class, ], ], - 'Kint\\Renderer\\RichRenderer', + \Kint\Renderer\RichRenderer::class, ], ]; } diff --git a/tests/Parser/ArrayLimitPluginTest.php b/tests/Parser/ArrayLimitPluginTest.php index 152729855..d8214d662 100644 --- a/tests/Parser/ArrayLimitPluginTest.php +++ b/tests/Parser/ArrayLimitPluginTest.php @@ -27,6 +27,7 @@ namespace Kint\Test\Parser; +use InvalidArgumentException; use Kint\Parser\ArrayLimitPlugin; use Kint\Parser\JsonPlugin; use Kint\Parser\Parser; @@ -204,10 +205,10 @@ public function testParseManipulated() $subv = \end($o->value->contents); $this->assertNotContains('array_limit', $subv->hints); $subv = $subv->getRepresentation('json'); - $this->assertInstanceOf('Kint\\Zval\\Representation\\Representation', $subv); + $this->assertInstanceOf(\Kint\Zval\Representation\Representation::class, $subv); // array $subv = $subv->contents; - $this->assertInstanceOf('Kint\\Zval\\Value', $subv); + $this->assertInstanceOf(Value::class, $subv); $this->assertContains('array_limit', $subv->hints); // Testing manipulated topography with arrays as representation contents @@ -232,14 +233,14 @@ public function testParseManipulated() $subv = \end($o->value->contents); $this->assertNotContains('array_limit', $subv->hints); $subv = $subv->getRepresentation('json'); - $this->assertInstanceOf('Kint\\Zval\\Representation\\Representation', $subv); + $this->assertInstanceOf(\Kint\Zval\Representation\Representation::class, $subv); // wrapped array $subv = $subv->contents; $this->assertSame('array', \gettype($subv)); $this->assertCount(1, $subv); // array $subv = \reset($subv); - $this->assertInstanceOf('Kint\\Zval\\Value', $subv); + $this->assertInstanceOf(Value::class, $subv); $this->assertContains('array_limit', $subv->hints); } @@ -249,7 +250,7 @@ public function testParseManipulated() */ public function testInvalidSettings() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); ArrayLimitPlugin::$trigger = 20; ArrayLimitPlugin::$limit = 30; diff --git a/tests/Parser/BlacklistPluginTest.php b/tests/Parser/BlacklistPluginTest.php index f21c075ef..6c9dfc457 100644 --- a/tests/Parser/BlacklistPluginTest.php +++ b/tests/Parser/BlacklistPluginTest.php @@ -89,7 +89,7 @@ function () use (&$completed) { $this->assertNotContains('blacklist', $o->hints); $this->assertTrue($completed); - BlacklistPlugin::$shallow_blacklist[] = 'Kint\\Test\\Fixtures\\TestClass'; + BlacklistPlugin::$shallow_blacklist[] = \Kint\Test\Fixtures\TestClass::class; $completed = false; $o = $p->parse($v, clone $b); @@ -106,12 +106,12 @@ function () use (&$completed) { $this->assertContains('blacklist', $bo->hints); $this->assertFalse($completed); - $this->assertInstanceOf('Kint\\Zval\\InstanceValue', $bo); + $this->assertInstanceOf(\Kint\Zval\InstanceValue::class, $bo); $this->assertSame($o->spl_object_hash, $bo->spl_object_hash); $this->assertSame($o->classname, $bo->classname); $v = \reset($v); - BlacklistPlugin::$blacklist[] = 'Kint\\Test\\Fixtures\\TestClass'; + BlacklistPlugin::$blacklist[] = \Kint\Test\Fixtures\TestClass::class; $completed = false; $bo = $p->parse($v, clone $b); diff --git a/tests/Parser/FsPathPluginTest.php b/tests/Parser/FsPathPluginTest.php index 3dbebbe66..ebdeb6aea 100644 --- a/tests/Parser/FsPathPluginTest.php +++ b/tests/Parser/FsPathPluginTest.php @@ -137,7 +137,7 @@ public function testParse($path, $expect) if ($expect) { $this->assertInstanceOf( - '\\Kint\\Zval\\Representation\\SplFileInfoRepresentation', + \Kint\Zval\Representation\SplFileInfoRepresentation::class, $obj->getRepresentation('splfileinfo') ); diff --git a/tests/Parser/ParserTest.php b/tests/Parser/ParserTest.php index 67b4e2304..abe91ef33 100644 --- a/tests/Parser/ParserTest.php +++ b/tests/Parser/ParserTest.php @@ -27,8 +27,10 @@ namespace Kint\Test\Parser; +use __PHP_Incomplete_Class; use DomainException; use Exception; +use InvalidArgumentException; use Kint\Parser\Parser; use Kint\Parser\ProxyPlugin; use Kint\Test\Fixtures\ChildTestClass; @@ -65,7 +67,7 @@ public function testTriggerComplete() */ public function testConstruct() { - $marker = new ReflectionProperty('Kint\\Parser\\Parser', 'marker'); + $marker = new ReflectionProperty(Parser::class, 'marker'); $marker->setAccessible(true); @@ -180,8 +182,8 @@ public function testParseInteger() $this->assertSame('$v', $o->access_path); $this->assertSame('$v', $o->name); $this->assertSame('integer', $o->type); - $this->assertSame('Kint\\Zval\\Value', \get_class($o)); - $this->assertSame('Kint\\Zval\\Representation\\Representation', \get_class($o->value)); + $this->assertSame(Value::class, \get_class($o)); + $this->assertSame(Representation::class, \get_class($o->value)); $this->assertSame(1234, $o->value->contents); $this->assertSame(1234, $v); $this->assertSame(0, $o->depth); @@ -253,7 +255,7 @@ public function testParseString() $o = $p->parse($v, clone $b); - $this->assertInstanceOf('Kint\\Zval\\BlobValue', $o); + $this->assertInstanceOf(\Kint\Zval\BlobValue::class, $o); $this->assertSame('string', $o->type); $this->assertSame($v, $o->value->contents); @@ -267,7 +269,7 @@ public function testParseString() $o = $p->parse($v, clone $b); - $this->assertInstanceOf('Kint\\Zval\\BlobValue', $o); + $this->assertInstanceOf(\Kint\Zval\BlobValue::class, $o); $this->assertSame($v, $o->value->contents); $this->assertSame('UTF-8', $o->encoding); @@ -286,7 +288,7 @@ public function testParseResource() $o = $p->parse($v, clone $b); - $this->assertInstanceOf('Kint\\Zval\\ResourceValue', $o); + $this->assertInstanceOf(\Kint\Zval\ResourceValue::class, $o); $this->assertSame('resource', $o->type); $this->assertNull($o->value); @@ -332,7 +334,7 @@ public function testParseArray() $o = $p->parse($v, clone $b); - $this->assertInstanceOf('Kint\\Zval\\Representation\\Representation', $o->value); + $this->assertInstanceOf(Representation::class, $o->value); $this->assertCount(0, $o->value->contents); } @@ -349,7 +351,7 @@ public function testParseObject() $o = $p->parse($v, clone $b); - $this->assertInstanceOf('Kint\\Zval\\InstanceValue', $o); + $this->assertInstanceOf(InstanceValue::class, $o); $this->assertSame('object', $o->type); $this->assertSame('List', $o->name); @@ -471,11 +473,11 @@ public function testParseObjectIncomplete() $o = $p->parse($v, clone $b); - $this->assertInstanceOf('Kint\\Zval\\InstanceValue', $o); + $this->assertInstanceOf(InstanceValue::class, $o); $this->assertSame('object', $o->type); $this->assertSame('List', $o->name); - $this->assertSame('__PHP_Incomplete_Class', $o->classname); + $this->assertSame(__PHP_Incomplete_Class::class, $o->classname); $this->assertSame(\spl_object_hash($v), $o->spl_object_hash); $this->assertContains('object', $o->hints); $this->assertNotNull($o->access_path); @@ -796,7 +798,7 @@ public function testParseAccessPathAvailability() $this->assertNull($properties['pro']->access_path); $this->assertNull($properties['pri']->access_path); - $p = new Parser(0, 'Kint\\Test\\Fixtures\\ChildTestClass'); + $p = new Parser(0, ChildTestClass::class); $o = $p->parse($v, clone $b); $properties = []; foreach ($o->value->contents as $prop) { @@ -806,7 +808,7 @@ public function testParseAccessPathAvailability() $this->assertSame('$v->pro', $properties['pro']->access_path); $this->assertNull($properties['pri']->access_path); - $p = new Parser(0, 'Kint\\Test\\Fixtures\\TestClass'); + $p = new Parser(0, TestClass::class); $o = $p->parse($v, clone $b); $properties = []; foreach ($o->value->contents as $prop) { @@ -1009,7 +1011,7 @@ public function childHasPathProvider() ], ], 'protected parser' => [ - new Parser(0, 'Kint\\Test\\Fixtures\\ChildTestClass'), + new Parser(0, ChildTestClass::class), [ 'props' => ['$v', false, false, true, true, false], 'statics' => ['$v', true, false, true, true, false], @@ -1020,7 +1022,7 @@ public function childHasPathProvider() ], ], 'private parser' => [ - new Parser(0, 'Kint\\Test\\Fixtures\\TestClass'), + new Parser(0, TestClass::class), [ 'props' => ['$v', false, false, true, true, true], 'statics' => ['$v', true, false, true, true, true], @@ -1052,7 +1054,7 @@ public function childHasPathProvider() $prop = new Value($name); $r->contents = [$prop]; - $prop->owner_class = 'Kint\\Test\\Fixtures\\TestClass'; + $prop->owner_class = TestClass::class; $parent->access_path = $path; $prop->static = $static; @@ -1093,7 +1095,7 @@ public function testInvalidChildHasPath() $child = new Value('child'); $child->access = Value::ACCESS_PROTECTED; - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $p->childHasPath($parent, $child); } diff --git a/tests/Parser/SerializePluginTest.php b/tests/Parser/SerializePluginTest.php index e47f33dac..760b98931 100644 --- a/tests/Parser/SerializePluginTest.php +++ b/tests/Parser/SerializePluginTest.php @@ -27,6 +27,7 @@ namespace Kint\Test\Parser; +use __PHP_Incomplete_Class; use Kint\Parser\Parser; use Kint\Parser\SerializePlugin; use Kint\Test\KintTestCase; @@ -78,7 +79,7 @@ public function testParse() SerializePlugin::$safe_mode = false; $obj = $p->parse($v, clone $b); $this->assertSame('obj', $obj->getRepresentation('serialized')->contents->value->contents[0]->name); - $this->assertSame('__PHP_Incomplete_Class', $obj->getRepresentation('serialized')->contents->value->contents[0]->classname); + $this->assertSame(__PHP_Incomplete_Class::class, $obj->getRepresentation('serialized')->contents->value->contents[0]->classname); $this->assertSame( 'unserialize($v, '.\var_export(['allowed_classes' => false], true).')[\'obj\']', $obj->getRepresentation('serialized')->contents->value->contents[0]->access_path @@ -86,7 +87,7 @@ public function testParse() SerializePlugin::$allowed_classes = [self::class]; $obj = $p->parse($v, clone $b); - $this->assertSame('__PHP_Incomplete_Class', $obj->getRepresentation('serialized')->contents->value->contents[0]->classname); + $this->assertSame(__PHP_Incomplete_Class::class, $obj->getRepresentation('serialized')->contents->value->contents[0]->classname); $this->assertSame( 'unserialize($v, '.\var_export(['allowed_classes' => [self::class]], true).')[\'obj\']', $obj->getRepresentation('serialized')->contents->value->contents[0]->access_path diff --git a/tests/Parser/ToStringPluginTest.php b/tests/Parser/ToStringPluginTest.php index eb6ba2c04..75ec102f8 100644 --- a/tests/Parser/ToStringPluginTest.php +++ b/tests/Parser/ToStringPluginTest.php @@ -108,7 +108,7 @@ public function testParseBlacklist() $this->assertNotNull($obj->getRepresentation('tostring')); - ToStringPlugin::$blacklist[] = 'SplFileInfo'; + ToStringPlugin::$blacklist[] = SplFileInfo::class; $obj = $p->parse($v, clone $b); diff --git a/tests/Parser/TracePluginTest.php b/tests/Parser/TracePluginTest.php index 37099a654..5d04e80c2 100644 --- a/tests/Parser/TracePluginTest.php +++ b/tests/Parser/TracePluginTest.php @@ -52,8 +52,8 @@ public function testParse() $o = $p->parse($bt, $o); $this->assertContains('trace', $o->hints); - $this->assertInstanceOf('Kint\\Zval\\TraceValue', $o); - $this->assertInstanceOf('Kint\\Zval\\TraceFrameValue', $o->value->contents[0]); + $this->assertInstanceOf(\Kint\Zval\TraceValue::class, $o); + $this->assertInstanceOf(\Kint\Zval\TraceFrameValue::class, $o->value->contents[0]); } /** diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 323f436cc..2c6090f2c 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -69,7 +69,7 @@ protected function tearDown(): void public function testConstruct() { - $u = new ReflectionMethod('Kint\\Utils', '__construct'); + $u = new ReflectionMethod(Utils::class, '__construct'); $this->assertTrue($u->isPrivate()); } @@ -496,25 +496,25 @@ public function testTruncateString($input, $expect, $length) */ public function testGetTypeString() { - $param = new ReflectionParameter(['Kint\\Test\\Fixtures\\TestClass', 'arrayHint'], 'x'); + $param = new ReflectionParameter([Fixtures\TestClass::class, 'arrayHint'], 'x'); $this->assertSame('array', Utils::getTypeString($param->getType())); - $param = new ReflectionParameter(['Kint\\Test\\Fixtures\\Php71TestClass', 'typeHints'], 'p1'); + $param = new ReflectionParameter([Fixtures\Php71TestClass::class, 'typeHints'], 'p1'); $this->assertSame('?int', Utils::getTypeString($param->getType())); - $param = new ReflectionParameter(['Kint\\Test\\Fixtures\\Php71TestClass', 'typeHints'], 'nullable'); + $param = new ReflectionParameter([Fixtures\Php71TestClass::class, 'typeHints'], 'nullable'); $this->assertSame('?string', Utils::getTypeString($param->getType())); if (KINT_PHP80) { - $param = new ReflectionParameter(['Kint\\Test\\Fixtures\\Php8TestClass', 'typeHints'], 'p1'); + $param = new ReflectionParameter([Fixtures\Php8TestClass::class, 'typeHints'], 'p1'); $this->assertSame('string|int', Utils::getTypeString($param->getType())); - $param = new ReflectionParameter(['Kint\\Test\\Fixtures\\Php8TestClass', 'typeHints'], 'mixed'); + $param = new ReflectionParameter([Fixtures\Php8TestClass::class, 'typeHints'], 'mixed'); $this->assertSame('mixed', Utils::getTypeString($param->getType())); } if (KINT_PHP81) { - $param = new ReflectionParameter(['Kint\\Test\\Fixtures\\Php81TestClass', 'typeHints'], 'p1'); + $param = new ReflectionParameter([Fixtures\Php81TestClass::class, 'typeHints'], 'p1'); $this->assertSame('X&Y', Utils::getTypeString($param->getType())); } } diff --git a/tests/Zval/BlobValueTest.php b/tests/Zval/BlobValueTest.php index b16fec427..ef0cd5c2f 100644 --- a/tests/Zval/BlobValueTest.php +++ b/tests/Zval/BlobValueTest.php @@ -261,7 +261,7 @@ public function testTransplant() $o = $p->parse($string, clone $b); - $this->assertInstanceOf('Kint\\Zval\\BlobValue', $o); + $this->assertInstanceOf(BlobValue::class, $o); $this->assertNotFalse($o->encoding); $this->assertNotNull($o->encoding); diff --git a/tests/Zval/InstanceValueTest.php b/tests/Zval/InstanceValueTest.php index 5bda78018..0ad151100 100644 --- a/tests/Zval/InstanceValueTest.php +++ b/tests/Zval/InstanceValueTest.php @@ -95,6 +95,6 @@ public function testGetType() $o = $p->parse($v, clone $b); - $this->assertSame('Kint\\Test\\Fixtures\\ChildTestClass', $o->getType()); + $this->assertSame(ChildTestClass::class, $o->getType()); } } diff --git a/tests/Zval/MethodValueTest.php b/tests/Zval/MethodValueTest.php index 128be221a..7fcf1c558 100644 --- a/tests/Zval/MethodValueTest.php +++ b/tests/Zval/MethodValueTest.php @@ -35,6 +35,10 @@ use ReflectionFunction; use ReflectionMethod; use stdClass; +use TypeError; +use Iterator; +use Exception; +use LogicException; /** * @coversNothing @@ -46,7 +50,7 @@ class MethodValueTest extends TestCase */ public function testConstruct() { - $reflection = new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'mix'); + $reflection = new ReflectionMethod(TestClass::class, 'mix'); $m = new MethodValue($reflection); $this->assertSame('mix', $m->name); $this->assertSame($reflection->getFileName(), $m->filename); @@ -57,25 +61,25 @@ public function testConstruct() $this->assertNull($m->docstring); $this->assertSame(Value::OPERATOR_STATIC, $m->operator); $this->assertSame(Value::ACCESS_PROTECTED, $m->access); - $this->assertSame('Kint\\Test\\Fixtures\\TestClass', $m->owner_class); + $this->assertSame(TestClass::class, $m->owner_class); $this->assertTrue($m->static); $this->assertTrue($m->final); $this->assertFalse($m->abstract); $this->assertFalse($m->internal); - $reflection = new ReflectionMethod('Kint\\Test\\Fixtures\\ChildTestClass', '__construct'); - $parent_reflection = new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', '__construct'); + $reflection = new ReflectionMethod(\Kint\Test\Fixtures\ChildTestClass::class, '__construct'); + $parent_reflection = new ReflectionMethod(TestClass::class, '__construct'); $m = new MethodValue($reflection); $this->assertSame($parent_reflection->getDocComment(), $m->docstring); $this->assertSame(Value::OPERATOR_OBJECT, $m->operator); $this->assertSame(Value::ACCESS_PUBLIC, $m->access); - $this->assertSame('Kint\\Test\\Fixtures\\TestClass', $m->owner_class); + $this->assertSame(TestClass::class, $m->owner_class); - $reflection = new ReflectionMethod('Kint\\Test\\Fixtures\\ChildTestClass', 'classHint'); + $reflection = new ReflectionMethod(\Kint\Test\Fixtures\ChildTestClass::class, 'classHint'); $m = new MethodValue($reflection); $this->assertSame(Value::OPERATOR_OBJECT, $m->operator); $this->assertSame(Value::ACCESS_PRIVATE, $m->access); - $this->assertSame('Kint\\Test\\Fixtures\\TestClass', $m->owner_class); + $this->assertSame(TestClass::class, $m->owner_class); $reflection = new ReflectionFunction('explode'); $m = new MethodValue($reflection); @@ -90,7 +94,7 @@ public function testConstruct() */ public function testConstructWrongType() { - $this->expectException('TypeError'); + $this->expectException(TypeError::class); $m = new MethodValue(new stdClass()); } @@ -104,22 +108,22 @@ public function testSetAccessPathFrom() $o = new InstanceValue('$tc', TestClass::class, 'objhash', 314159); $o->access_path = '$tc'; - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', '__construct')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, '__construct')); $this->assertNull($m->getAccessPath()); $m->setAccessPathFrom($o); $this->assertSame('new \\Kint\\Test\\Fixtures\\TestClass()', $m->getAccessPath()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'staticMethod')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, 'staticMethod')); $this->assertNull($m->getAccessPath()); $m->setAccessPathFrom($o); $this->assertSame('\\Kint\\Test\\Fixtures\\TestClass::staticMethod()', $m->getAccessPath()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'finalMethod')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, 'finalMethod')); $this->assertNull($m->getAccessPath()); $m->setAccessPathFrom($o); $this->assertSame('$tc->finalMethod()', $m->getAccessPath()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'mix')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, 'mix')); $this->assertNull($m->getAccessPath()); $m->setAccessPathFrom($o); $this->assertSame( @@ -127,24 +131,24 @@ public function testSetAccessPathFrom() $m->getAccessPath() ); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', '__clone')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, '__clone')); $this->assertNull($m->getAccessPath()); $m->setAccessPathFrom($o); $this->assertSame('clone $tc', $m->getAccessPath()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', '__invoke')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, '__invoke')); $this->assertNull($m->getAccessPath()); $m->setAccessPathFrom($o); $this->assertSame('$tc($x)', $m->getAccessPath()); // Tests both tostring and case insensitivity - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', '__tostring')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, '__tostring')); $this->assertNull($m->getAccessPath()); $m->setAccessPathFrom($o); $this->assertSame('__ToStRiNg', $m->name); $this->assertSame('(string) $tc', $m->getAccessPath()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', '__get')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, '__get')); $this->assertNull($m->getAccessPath()); $m->setAccessPathFrom($o); $this->assertNull($m->getAccessPath()); @@ -155,7 +159,7 @@ public function testSetAccessPathFrom() */ public function testGetValueShort() { - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', '__construct')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, '__construct')); $this->assertSame( 'This is a constructor for a TestClass with the first line of the docstring split into two different lines.', $m->getValueShort() @@ -167,7 +171,7 @@ public function testGetValueShort() $m = new MethodValue(new ReflectionFunction('explode')); $this->assertNull($m->getValueShort()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'arrayHint')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, 'arrayHint')); $this->assertNull($m->getValueShort()); } @@ -176,16 +180,16 @@ public function testGetValueShort() */ public function testGetModifiers() { - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'staticMethod')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, 'staticMethod')); $this->assertSame('private static', $m->getModifiers()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'finalMethod')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, 'finalMethod')); $this->assertSame('final public', $m->getModifiers()); - $m = new MethodValue(new ReflectionMethod('Iterator', 'current')); + $m = new MethodValue(new ReflectionMethod(Iterator::class, 'current')); $this->assertSame('abstract public', $m->getModifiers()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'mix')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, 'mix')); $this->assertSame('final protected static', $m->getModifiers()); $m = new MethodValue(new ReflectionFunction('explode')); @@ -197,7 +201,7 @@ public function testGetModifiers() */ public function testGetAccessPath() { - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'arrayHint')); + $m = new MethodValue(new ReflectionMethod(TestClass::class, 'arrayHint')); $this->assertNull($m->getAccessPath()); $m->access_path = '$m->arrayHint'; $this->assertSame('$m->arrayHint(array $x)', $m->getAccessPath()); @@ -208,17 +212,17 @@ public function testGetAccessPath() */ public function testReturnType() { - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\Php7TestClass', 'typeHints')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\Php7TestClass::class, 'typeHints')); $this->assertSame('self', $m->returntype); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\Php71TestClass', 'typeHints')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\Php71TestClass::class, 'typeHints')); $this->assertSame('?self', $m->returntype); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\Php71TestClass', 'returnTypeHint')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\Php71TestClass::class, 'returnTypeHint')); $this->assertSame('?Kint\\Test\\Fixtures\\TestClass', $m->returntype); if (KINT_PHP80) { - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\Php8TestClass', 'typeHints')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\Php8TestClass::class, 'typeHints')); $this->assertSame('?static', $m->returntype); } } @@ -228,7 +232,7 @@ public function testReturnType() */ public function testGetPhpDocUrl() { - $m = new MethodValue(new ReflectionMethod('Exception', '__construct')); + $m = new MethodValue(new ReflectionMethod(Exception::class, '__construct')); $this->assertSame( 'https://secure.php.net/exception.construct', $m->getPhpDocUrl() @@ -240,7 +244,7 @@ public function testGetPhpDocUrl() */ public function testGetPhpDocUrlParent() { - $m = new MethodValue(new ReflectionMethod('LogicException', 'getMessage')); + $m = new MethodValue(new ReflectionMethod(LogicException::class, 'getMessage')); $this->assertSame( 'https://secure.php.net/exception.getmessage', $m->getPhpDocUrl() diff --git a/tests/Zval/ParameterHoldingTraitTest.php b/tests/Zval/ParameterHoldingTraitTest.php index 390fb3941..f0e45204a 100644 --- a/tests/Zval/ParameterHoldingTraitTest.php +++ b/tests/Zval/ParameterHoldingTraitTest.php @@ -49,39 +49,39 @@ public function testGetParams() $this->assertSame('$separator, $str, $limit', $m->getParams()); } - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'arrayHint')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\TestClass::class, 'arrayHint')); $this->assertSame('array $x', $m->getParams()); // Testing cache $m->parameters = []; $this->assertSame('array $x', $m->getParams()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'classHint')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\TestClass::class, 'classHint')); $this->assertSame('Kint\\Test\\Fixtures\\TestClass $x', $m->getParams()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'ref')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\TestClass::class, 'ref')); $this->assertSame('&$x', $m->getParams()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'defaultMethod')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\TestClass::class, 'defaultMethod')); $this->assertSame('$x = 1234', $m->getParams()); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\TestClass', 'mix')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\TestClass::class, 'mix')); $this->assertSame( 'array &$x, ?Kint\\Test\\Fixtures\\TestClass $y = null, $z = array(...), $_ = \'string\'', $m->getParams() ); - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\Php7TestClass', 'typeHints')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\Php7TestClass::class, 'typeHints')); $this->assertSame('string $p1, int $p2, bool $p3 = false, int $p4 = 0, int $p5 = 1', $m->getParams()); if (KINT_PHP80) { - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\Php8TestClass', 'typeHints')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\Php8TestClass::class, 'typeHints')); $this->assertSame('string|int $p1, ?int $p2, bool $p3 = false, ?string $nullable = null, string|int|null $nullable2 = null, mixed $mixed = null, $untyped = null', $m->getParams()); } if (KINT_PHP81) { - $m = new MethodValue(new ReflectionMethod('Kint\\Test\\Fixtures\\Php81TestClass', 'typeHints')); + $m = new MethodValue(new ReflectionMethod(\Kint\Test\Fixtures\Php81TestClass::class, 'typeHints')); $this->assertSame('X&Y $p1, $p2 = object(Kint\\Test\\Fixtures\\Php81TestClass)', $m->getParams()); } } diff --git a/tests/Zval/Representation/ColorRepresentationTest.php b/tests/Zval/Representation/ColorRepresentationTest.php index 8e990672e..1ad836049 100644 --- a/tests/Zval/Representation/ColorRepresentationTest.php +++ b/tests/Zval/Representation/ColorRepresentationTest.php @@ -27,6 +27,7 @@ namespace Kint\Test\Zval\Representation; +use InvalidArgumentException; use Kint\Test\KintTestCase; use Kint\Zval\Representation\ColorRepresentation; @@ -302,7 +303,7 @@ public function testConstruct($input, $r, $g, $b, $a, $variant) * */ public function testBadConstruct($input) { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $rep = new ColorRepresentation($input); } @@ -311,7 +312,7 @@ public function testBadConstruct($input) */ public function testSetValuesFromInvalidHex() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $rep = new ColorRepresentation('#g'); } @@ -321,7 +322,7 @@ public function testSetValuesFromInvalidHex() */ public function testSetValuesFromInvalidLengthHex() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $rep = new ColorRepresentation('#abcde'); } @@ -331,7 +332,7 @@ public function testSetValuesFromInvalidLengthHex() */ public function testSetValuesFromInvalidFunction() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $rep = new ColorRepresentation('asdf(1, 2, 3)'); } @@ -341,7 +342,7 @@ public function testSetValuesFromInvalidFunction() */ public function testSetValuesFromInvalidLengthFunction() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $rep = new ColorRepresentation('rgb(1, 2, 3, 4, 5)'); } @@ -351,7 +352,7 @@ public function testSetValuesFromInvalidLengthFunction() */ public function testSetValuesFromInvalidRgbRangeFunction() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $rep = new ColorRepresentation('rgb(270, -2, 4)'); } @@ -361,7 +362,7 @@ public function testSetValuesFromInvalidRgbRangeFunction() */ public function testSetValuesFromInvalidHslRangeFunction() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $rep = new ColorRepresentation('hsl(200, 2, -1)'); } @@ -371,7 +372,7 @@ public function testSetValuesFromInvalidHslRangeFunction() */ public function testSetValuesFromInvalidAlphaFunction() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $rep = new ColorRepresentation('rgba(0, 0, 0, 2)'); } @@ -411,7 +412,7 @@ public function testGetColor() $this->assertNull($rep->getColor(ColorRepresentation::COLOR_HEX_3)); $this->assertNull($rep->getColor(ColorRepresentation::COLOR_HEX_4)); - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); $rep = new ColorRepresentation("This isn't a color"); } @@ -485,7 +486,7 @@ public function testRgbToHsl() */ public function testRgbToHslInputLow() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); ColorRepresentation::rgbToHsl(0, 0, -1); } @@ -495,7 +496,7 @@ public function testRgbToHslInputLow() */ public function testRgbToHslInputHigh() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); ColorRepresentation::rgbToHsl(0, 0, 256); } @@ -505,7 +506,7 @@ public function testRgbToHslInputHigh() */ public function testHslToRgbHueHigh() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); ColorRepresentation::hslToRgb(361, 0, 0); } @@ -515,7 +516,7 @@ public function testHslToRgbHueHigh() */ public function testHslToRgbSatLightHigh() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); ColorRepresentation::hslToRgb(0, 101, 101); } @@ -525,7 +526,7 @@ public function testHslToRgbSatLightHigh() */ public function testHslToRgbInputLow() { - $this->expectException('InvalidArgumentException'); + $this->expectException(InvalidArgumentException::class); ColorRepresentation::hslToRgb(-1, 0, 0); } diff --git a/tests/Zval/Representation/SplFileInfoRepresentationTest.php b/tests/Zval/Representation/SplFileInfoRepresentationTest.php index 708cbcd30..13f415d70 100644 --- a/tests/Zval/Representation/SplFileInfoRepresentationTest.php +++ b/tests/Zval/Representation/SplFileInfoRepresentationTest.php @@ -398,7 +398,7 @@ public function testConstructBlockDevice() $owner = \fileowner($f); $group = \filegroup($f); } else { - $sfi = $this->createMock('SplFileInfo'); + $sfi = $this->createMock(SplFileInfo::class); $sfi->method('getSize')->willReturn($size = 0); $sfi->method('getCTime')->willReturn($ctime = \time()); $sfi->method('getMTime')->willReturn($mtime = \time()); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index e8a1e3966..06e5ac0dc 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -26,5 +26,5 @@ */ if (KINT_PHP81) { - \class_alias('Kint\\Test\\Fixtures\\Mysqli81TestClass', 'Kint\\Test\\Fixtures\\MysqliTestClass'); + \class_alias(Kint\Test\Fixtures\Mysqli81TestClass::class, Kint\Test\Fixtures\MysqliTestClass::class); }