Skip to content

Commit

Permalink
[BCB] PHPStanTestCase - extensions can no longer be provided by overr…
Browse files Browse the repository at this point in the history
…iding methods from PHPStanTestCase. Use getAdditionalConfigFiles() instead.
  • Loading branch information
ondrejmirtes committed Sep 14, 2021
1 parent db2f7fb commit 65efd93
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 67 deletions.
42 changes: 4 additions & 38 deletions src/Testing/PHPStanTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,11 @@ public function createReflectionProvider(): ReflectionProvider
$setterReflectionProviderProvider->setReflectionProvider($reflectionProvider);

$dynamicReturnTypeExtensionRegistryProvider = new DirectDynamicReturnTypeExtensionRegistryProvider(
array_merge(self::getContainer()->getServicesByTag(BrokerFactory::DYNAMIC_METHOD_RETURN_TYPE_EXTENSION_TAG), $this->getDynamicMethodReturnTypeExtensions()),
array_merge(self::getContainer()->getServicesByTag(BrokerFactory::DYNAMIC_STATIC_METHOD_RETURN_TYPE_EXTENSION_TAG), $this->getDynamicStaticMethodReturnTypeExtensions()),
array_merge(self::getContainer()->getServicesByTag(BrokerFactory::DYNAMIC_FUNCTION_RETURN_TYPE_EXTENSION_TAG), $this->getDynamicFunctionReturnTypeExtensions())
);
$operatorTypeSpecifyingExtensionRegistryProvider = new DirectOperatorTypeSpecifyingExtensionRegistryProvider(
$this->getOperatorTypeSpecifyingExtensions()
self::getContainer()->getServicesByTag(BrokerFactory::DYNAMIC_METHOD_RETURN_TYPE_EXTENSION_TAG),
self::getContainer()->getServicesByTag(BrokerFactory::DYNAMIC_STATIC_METHOD_RETURN_TYPE_EXTENSION_TAG),
self::getContainer()->getServicesByTag(BrokerFactory::DYNAMIC_FUNCTION_RETURN_TYPE_EXTENSION_TAG)
);
$operatorTypeSpecifyingExtensionRegistryProvider = new DirectOperatorTypeSpecifyingExtensionRegistryProvider([]);

$broker = new Broker(
$reflectionProvider,
Expand Down Expand Up @@ -605,38 +603,6 @@ public function getCurrentWorkingDirectory(): string
return $this->getFileHelper()->normalizePath(__DIR__ . '/../..');
}

/**
* @return \PHPStan\Type\DynamicMethodReturnTypeExtension[]
*/
public function getDynamicMethodReturnTypeExtensions(): array
{
return [];
}

/**
* @return \PHPStan\Type\DynamicStaticMethodReturnTypeExtension[]
*/
public function getDynamicStaticMethodReturnTypeExtensions(): array
{
return [];
}

/**
* @return \PHPStan\Type\DynamicFunctionReturnTypeExtension[]
*/
public function getDynamicFunctionReturnTypeExtensions(): array
{
return [];
}

/**
* @return \PHPStan\Type\OperatorTypeSpecifyingExtension[]
*/
public function getOperatorTypeSpecifyingExtensions(): array
{
return [];
}

/**
* @param \PhpParser\PrettyPrinter\Standard $printer
* @param \PHPStan\Reflection\ReflectionProvider $reflectionProvider
Expand Down
29 changes: 0 additions & 29 deletions tests/PHPStan/Rules/Comparison/IfConstantConditionRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

namespace PHPStan\Rules\Comparison;

use PhpParser\Node\Expr\FuncCall;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\DynamicFunctionReturnTypeExtension;
use PHPStan\Type\Type;

/**
* @extends \PHPStan\Testing\RuleTestCase<IfConstantConditionRule>
*/
Expand Down Expand Up @@ -39,28 +32,6 @@ protected function shouldTreatPhpDocTypesAsCertain(): bool
return $this->treatPhpDocTypesAsCertain;
}

/**
* @return DynamicFunctionReturnTypeExtension[]
*/
public function getDynamicFunctionReturnTypeExtensions(): array
{
return [
new class implements DynamicFunctionReturnTypeExtension {

public function isFunctionSupported(FunctionReflection $functionReflection): bool
{
return $functionReflection->getName() === 'always_true';
}

public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
{
return new ConstantBooleanType(true);
}

},
];
}

public function testRule(): void
{
$this->treatPhpDocTypesAsCertain = true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

/** @return true */
function always_true()
{
return true;
Expand Down

0 comments on commit 65efd93

Please sign in to comment.