diff --git a/composer.json b/composer.json index 5af2c24..0c94e00 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "php": ">=5.6.0", "console-helpers/console-kit": "^0.3", "symfony/finder": "^2.8", - "goaop/parser-reflection": "^1.4", + "goaop/parser-reflection": "^1.4 || ^3.0 || ^4.0 || 4.0.0-RC2", "console-helpers/db-migration": "^0.1.0", "aura/sql": "^2.5 || ^3.0 || ^4.0 || ^5.0", "doctrine/cache": "^1.5", diff --git a/composer.lock b/composer.lock index 2eb40a6..5610f06 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "76cf6cd7a31554aa05fec7427bd42e1e", + "content-hash": "80d4a7a7966ea3bbb34b809cfabf177c", "packages": [ { "name": "aura/sql", @@ -2586,6 +2586,7 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { + "goaop/parser-reflection": 5, "aik099/coding-standard": 20, "console-helpers/prophecy-phpunit": 20 }, diff --git a/tests/CodeInsight/BackwardsCompatibility/Checker/ClassCheckerTest.php b/tests/CodeInsight/BackwardsCompatibility/Checker/ClassCheckerTest.php index 454dc99..ca55127 100644 --- a/tests/CodeInsight/BackwardsCompatibility/Checker/ClassCheckerTest.php +++ b/tests/CodeInsight/BackwardsCompatibility/Checker/ClassCheckerTest.php @@ -13,6 +13,7 @@ use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\AbstractChecker; use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\ClassChecker; +use PhpParser\BuilderHelpers; class ClassCheckerTest extends AbstractCheckerTestCase { @@ -24,6 +25,15 @@ public function testGetName() public function testCheck() { + if ( class_exists(BuilderHelpers::class) ) { + // The "nikic/php-parser:4.x+" doesn't prefix top level namespace classes with "\". + $type_name = 'kEvent'; + } + else { + // The "nikic/php-parser:3.x" prefixes top level namespace classes with "\". + $type_name = '\\kEvent'; + } + $this->assertArrayEquals( array( array( @@ -513,13 +523,13 @@ public function testCheck() 'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED, 'element' => 'ExampleEventHandler::OnEventSig2', 'old' => '&$event', - 'new' => '\kEvent $event', + 'new' => $type_name . ' $event', ), array( 'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED, 'element' => 'ExampleEventHandler::OnEventSig3', 'old' => '$event', - 'new' => '\kEvent $event', + 'new' => $type_name . ' $event', ), array( 'type' => ClassChecker::TYPE_METHOD_SCOPE_REDUCED, @@ -549,13 +559,13 @@ public function testCheck() 'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED, 'element' => 'AdminEventsHandler::OnEventSig2', 'old' => '&$event', - 'new' => '\kEvent $event', + 'new' => $type_name . ' $event', ), array( 'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED, 'element' => 'AdminEventsHandler::OnEventSig3', 'old' => '$event', - 'new' => '\kEvent $event', + 'new' => $type_name . ' $event', ), array( 'type' => ClassChecker::TYPE_METHOD_SCOPE_REDUCED, diff --git a/tests/CodeInsight/KnowledgeBase/DataCollector/ClassDataCollectorTest.php b/tests/CodeInsight/KnowledgeBase/DataCollector/ClassDataCollectorTest.php index d399ed9..a8fbd6a 100644 --- a/tests/CodeInsight/KnowledgeBase/DataCollector/ClassDataCollectorTest.php +++ b/tests/CodeInsight/KnowledgeBase/DataCollector/ClassDataCollectorTest.php @@ -16,6 +16,7 @@ use ConsoleHelpers\CodeInsight\KnowledgeBase\KnowledgeBase; use Go\ParserReflection\Locator\CallableLocator; use Go\ParserReflection\ReflectionEngine; +use PhpParser\BuilderHelpers; use Tests\ConsoleHelpers\CodeInsight\ProphecyToken\RegExToken; class ClassDataCollectorTest extends AbstractDataCollectorTestCase @@ -888,6 +889,15 @@ public function testClassMethodFlagChanges() public function testMethodParameterChanges() { + if ( class_exists(BuilderHelpers::class) ) { + // The "nikic/php-parser:4.x+" doesn't prefix top level namespace classes with "\". + $type_name = 'stdClass'; + } + else { + // The "nikic/php-parser:3.x" prefixes top level namespace classes with "\". + $type_name = '\\stdClass'; + } + $this->initFixture('MethodParametersBefore'); $this->collectData(); @@ -967,7 +977,7 @@ public function testMethodParameterChanges() 'Position' => '1', 'TypeClass' => 'stdClass', 'HasType' => '1', - 'TypeName' => '\\stdClass', + 'TypeName' => $type_name, 'AllowsNull' => '0', 'IsArray' => '0', 'IsCallable' => '0', @@ -1152,7 +1162,7 @@ public function testMethodParameterChanges() 'ClassId' => '1', 'Name' => 'greedyMethod', 'ParameterCount' => '8', - 'RequiredParameterCount' => '6', + 'RequiredParameterCount' => '4', 'Scope' => (string)ClassDataCollector::SCOPE_PUBLIC, 'IsAbstract' => '0', 'IsFinal' => '0', @@ -1188,7 +1198,7 @@ public function testMethodParameterChanges() 'Position' => '0', 'TypeClass' => 'stdClass', 'HasType' => '1', - 'TypeName' => '\\stdClass', + 'TypeName' => $type_name, 'AllowsNull' => '0', 'IsArray' => '0', 'IsCallable' => '0', @@ -1264,7 +1274,7 @@ public function testMethodParameterChanges() 'AllowsNull' => '1', 'IsArray' => '0', 'IsCallable' => '0', - 'IsOptional' => '0', + 'IsOptional' => '1', 'IsVariadic' => '0', 'CanBePassedByValue' => '1', 'IsPassedByReference' => '0', @@ -1282,12 +1292,12 @@ public function testMethodParameterChanges() 'AllowsNull' => '1', 'IsArray' => '0', 'IsCallable' => '0', - 'IsOptional' => '0', + 'IsOptional' => '1', 'IsVariadic' => '0', 'CanBePassedByValue' => '0', 'IsPassedByReference' => '1', - 'HasDefaultValue' => '0', - 'DefaultValue' => null, + 'HasDefaultValue' => '1', + 'DefaultValue' => 'true', 'DefaultConstant' => null, ), array( diff --git a/tests/CodeInsight/KnowledgeBase/DataCollector/FunctionDataCollectorTest.php b/tests/CodeInsight/KnowledgeBase/DataCollector/FunctionDataCollectorTest.php index 92b9f1a..9de64f4 100644 --- a/tests/CodeInsight/KnowledgeBase/DataCollector/FunctionDataCollectorTest.php +++ b/tests/CodeInsight/KnowledgeBase/DataCollector/FunctionDataCollectorTest.php @@ -13,6 +13,7 @@ use ConsoleHelpers\CodeInsight\KnowledgeBase\DataCollector\AbstractDataCollector; use ConsoleHelpers\CodeInsight\KnowledgeBase\DataCollector\FunctionDataCollector; +use PhpParser\BuilderHelpers; class FunctionDataCollectorTest extends AbstractDataCollectorTestCase { @@ -176,6 +177,15 @@ public function testFunctionFlagChanges() public function testFunctionParameterChanges() { + if ( class_exists(BuilderHelpers::class) ) { + // The "nikic/php-parser:4.x+" doesn't prefix top level namespace classes with "\". + $type_name = 'stdClass'; + } + else { + // The "nikic/php-parser:3.x" prefixes top level namespace classes with "\". + $type_name = '\\stdClass'; + } + $this->initFixture('FunctionParametersBefore'); $this->collectData(); @@ -233,7 +243,7 @@ public function testFunctionParameterChanges() 'Position' => '1', 'TypeClass' => 'stdClass', 'HasType' => '1', - 'TypeName' => '\\stdClass', + 'TypeName' => $type_name, 'AllowsNull' => '0', 'IsArray' => '0', 'IsCallable' => '0', @@ -404,7 +414,7 @@ public function testFunctionParameterChanges() 'FileId' => '1', 'Name' => 'greedyFunction', 'ParameterCount' => '8', - 'RequiredParameterCount' => '6', + 'RequiredParameterCount' => '4', 'IsVariadic' => '0', 'ReturnsReference' => '0', 'HasReturnType' => '0', @@ -432,7 +442,7 @@ public function testFunctionParameterChanges() 'Position' => '0', 'TypeClass' => 'stdClass', 'HasType' => '1', - 'TypeName' => '\\stdClass', + 'TypeName' => $type_name, 'AllowsNull' => '0', 'IsArray' => '0', 'IsCallable' => '0', @@ -508,7 +518,7 @@ public function testFunctionParameterChanges() 'AllowsNull' => '1', 'IsArray' => '0', 'IsCallable' => '0', - 'IsOptional' => '0', + 'IsOptional' => '1', 'IsVariadic' => '0', 'CanBePassedByValue' => '1', 'IsPassedByReference' => '0', @@ -526,12 +536,12 @@ public function testFunctionParameterChanges() 'AllowsNull' => '1', 'IsArray' => '0', 'IsCallable' => '0', - 'IsOptional' => '0', + 'IsOptional' => '1', 'IsVariadic' => '0', 'CanBePassedByValue' => '0', 'IsPassedByReference' => '1', - 'HasDefaultValue' => '0', - 'DefaultValue' => null, + 'HasDefaultValue' => '1', + 'DefaultValue' => 'true', 'DefaultConstant' => null, ), array( diff --git a/tests/CodeInsight/KnowledgeBase/DataCollector/fixtures/ClassDataCollector/MethodParametersAfter.php b/tests/CodeInsight/KnowledgeBase/DataCollector/fixtures/ClassDataCollector/MethodParametersAfter.php index 710d426..93a9d26 100644 --- a/tests/CodeInsight/KnowledgeBase/DataCollector/fixtures/ClassDataCollector/MethodParametersAfter.php +++ b/tests/CodeInsight/KnowledgeBase/DataCollector/fixtures/ClassDataCollector/MethodParametersAfter.php @@ -9,7 +9,7 @@ function greedyMethod( callable $param_three, string $param_four, $param_five = 'def', - &$param_six, + &$param_six = true, $param_seven = null, $param_eight = PHP_EOL ) { diff --git a/tests/CodeInsight/KnowledgeBase/DataCollector/fixtures/FunctionDataCollector/FunctionParametersAfter.php b/tests/CodeInsight/KnowledgeBase/DataCollector/fixtures/FunctionDataCollector/FunctionParametersAfter.php index 21ba9b3..bbcc904 100644 --- a/tests/CodeInsight/KnowledgeBase/DataCollector/fixtures/FunctionDataCollector/FunctionParametersAfter.php +++ b/tests/CodeInsight/KnowledgeBase/DataCollector/fixtures/FunctionDataCollector/FunctionParametersAfter.php @@ -6,7 +6,7 @@ function greedyFunction( callable $param_three, string $param_four, $param_five = 'def', - &$param_six, + &$param_six = true, $param_seven = null, $param_eight = PHP_EOL ) {