stable

Clone or download

Read-only

Move away from Guzzle 3 in REST tests

Tests located outside of plugins have been manually converted, the others have been converted with custom Rector [0] rules and some manual fixes. rector.php: ``` <?php declare(strict_types=1); use Rector\Renaming\Rector\Name\RenameClassRector; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Rector\Core\ValueObject\PhpVersion; use Rector\Core\Configuration\Option; use Tuleap\ReplaceGuzzleClientCall; require_once __DIR__ . '/rules.php'; return static function (ContainerConfigurator $containerConfigurator): void { $parameters = $containerConfigurator->parameters(); $parameters->set(Option::BOOTSTRAP_FILES, [ __DIR__ . '/tests/rest/lib/bootstrap.php', ]); $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_74); $services = $containerConfigurator->services(); $services->set(Tuleap\ReplaceGuzzleResponse::class); $services->set(RenameClassRector::class) ->call( 'configure', [ [ RenameClassRector::OLD_TO_NEW_CLASSES => [ 'Guzzle\Http\Message\Response' => 'Psr\Http\Message\ResponseInterface', ], ] ] ); $services->set(ReplaceGuzzleClientCall::class); }; ``` rules.php: ``` <?php declare(strict_types=1); namespace Tuleap; use PhpParser\Node\Arg; use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Name; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\String_; use PHPStan\Type\ObjectType; use Rector\NodeTypeResolver\Node\AttributeKey; final class ReplaceGuzzleResponse extends \Rector\Core\Rector\AbstractRector { private \Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer $fluent_chain_method_call_node_analyzer; public function __construct(\Rector\Defluent\NodeAnalyzer\FluentChainMethodCallNodeAnalyzer $fluent_chain_method_call_node_analyzer) { $this->fluent_chain_method_call_node_analyzer = $fluent_chain_method_call_node_analyzer; } public function getRuleDefinition(): \Symplify\RuleDocGenerator\ValueObject\RuleDefinition { throw new Exception("Not needed"); } public function getNodeTypes(): array { return [MethodCall::class]; } /** * @param MethodCall $node */ public function refactor(\PhpParser\Node $node) { if ($node->args === [] && $this->isName($node->name, 'json')) { return new FuncCall( new Name('json_decode'), [ new Arg(new MethodCall(new MethodCall($node->var, 'getBody'), 'getContents')), new Arg($this->nodeFactory->createTrue()), new Arg(new LNumber(512)), new ConstFetch(new Name('JSON_THROW_ON_ERROR')) ] ); } if ($this->isName($node->name, 'getBody') && isset($node->args[0]) && $node->args[0]->value instanceof ConstFetch && $node->args[0]->value->name->getFirst() === "true") { return new MethodCall(new MethodCall($node->var, 'getBody'), 'getContents'); } if ($this->isName($node->name, 'getHeader') && isset($node->args[0]) && $node->args[0]->value instanceof String_) { if ($node->args[0]->value->value === "Allow") { return $this->nodeFactory->createFuncCall( 'explode', [ ', ', $this->nodeFactory->createMethodCall( $node->var, 'getHeaderLine', ['Allow'] ) ] ); } return $this->nodeFactory->createMethodCall( $node->var, 'getHeader', $node->args ); } if ($this->isNames($node->name, ['normalize', 'toArray'])) { $chain_method_calls = $this->fluent_chain_method_call_node_analyzer->collectAllMethodCallsInChain($node); foreach ($chain_method_calls as $chainMethodCall) { if ($this->isNames($chainMethodCall->name, ['normalize', 'toArray'])) { continue; } $node = $this->refactor(new \PhpParser\Node\Expr\MethodCall($chainMethodCall->var, $chainMethodCall->name, $chainMethodCall->args)); } return $node; } return null; } } final class ReplaceGuzzleClientCall extends \Rector\Core\Rector\AbstractRector { public function getRuleDefinition(): \Symplify\RuleDocGenerator\ValueObject\RuleDefinition { throw new Exception("Not needed"); } public function getNodeTypes(): array { return [MethodCall::class]; } /** * @param MethodCall $node */ public function refactor(\PhpParser\Node $node) { if ($node->args === []) { return; } if (! $node->var instanceof PropertyFetch || $node->var->name->name !== 'client') { return; } if ($this->isName($node->name, 'get')) { return $this->getBaseRequest($node, 'GET'); } if ($this->isName($node->name, 'post')) { return $this->getRequestWithPossibleBody($node, 'POST'); } if ($this->isName($node->name, 'put')) { return $this->getRequestWithPossibleBody($node, 'PUT'); } if ($this->isName($node->name, 'patch')) { return $this->getRequestWithPossibleBody($node, 'PATCH'); } if ($this->isName($node->name, 'delete')) { return $this->getBaseRequest($node, 'DELETE'); } if ($this->isName($node->name, 'options')) { return $this->getBaseRequest($node, 'OPTIONS'); } return null; } private function getBaseRequest(MethodCall $current_node, string $method): MethodCall { return $this->nodeFactory->createMethodCall( $this->nodeFactory->createPropertyFetch('this', 'request_factory'), 'createRequest', [$method, $current_node->args[0]] ); } private function getRequestWithPossibleBody(MethodCall $current_node, string $method): MethodCall { $init_request = $this->getBaseRequest($current_node, $method); if (! isset($current_node->args[2])) { return $init_request; } $request_body = $this->nodeFactory->createMethodCall( $this->nodeFactory->createPropertyFetch('this', 'stream_factory'), 'createStream', [$current_node->args[2]] ); return $this->nodeFactory->createMethodCall($init_request, 'withBody', [$request_body]); } } ``` Part of request #21863: Run REST tests under PHP 8.0 [0] https://github.com/rectorphp/rector Change-Id: Icb9bce85d27a079cce2ef70447d058dcebafe3d4

Modified Files

Name
M plugins/agiledashboard/tests/rest/ArtifactsTest.php +2 −2 Go to diff View file
M plugins/agiledashboard/tests/rest/ExplicitBacklog/ExplicitBacklogTest.php +12 −28 Go to diff View file
M plugins/agiledashboard/tests/rest/ExplicitBacklog/MilestonesTest.php +4 −4 Go to diff View file
M plugins/agiledashboard/tests/rest/ExplicitBacklog/WorkflowPostActionTest.php +6 −18 Go to diff View file
M plugins/agiledashboard/tests/rest/KanbanColumns/KanbanColumnsTest.php +16 −24 Go to diff View file
M plugins/agiledashboard/tests/rest/KanbanTest.php +200 −305 Go to diff View file
M plugins/agiledashboard/tests/rest/TestBase.php +2 −2 Go to diff View file
M plugins/create_test_env/tests/rest/CreateTestEnvResourceTest.php +28 −38 Go to diff View file
M plugins/crosstracker/tests/rest/CrossTracker/CrossTrackerTest.php +15 −15 Go to diff View file
M plugins/crosstracker/tests/rest/CrossTracker/CrossTrackerTestExpertQueryTest.php +18 −18 Go to diff View file
M plugins/crosstracker/tests/rest/CrossTracker/CrossTrackerTestNonRegressionTrackerTest.php +10 −10 Go to diff View file
M plugins/docman/tests/rest/Docman/DocmanEmbeddedTest.php +79 −99 Go to diff View file
M plugins/docman/tests/rest/Docman/DocmanEmptyTest.php +93 −143 Go to diff View file
M plugins/docman/tests/rest/Docman/DocmanFilesTest.php +154 −240 Go to diff View file
M plugins/docman/tests/rest/Docman/DocmanFoldersTest.php +138 −260 Go to diff View file
M plugins/docman/tests/rest/Docman/DocmanItemsTest.php +24 −24 Go to diff View file
M plugins/docman/tests/rest/Docman/DocmanLinksTest.php +77 −106 Go to diff View file
M plugins/docman/tests/rest/Docman/DocmanProjectServiceTest.php +6 −6 Go to diff View file
M plugins/docman/tests/rest/Docman/DocmanWikiTest.php +72 −91 Go to diff View file
M plugins/docman/tests/rest/Helper/DocmanHardcodedMetadataExecutionHelper.php +12 −12 Go to diff View file
M plugins/docman/tests/rest/Helper/DocmanTestExecutionHelper.php +16 −16 Go to diff View file
M plugins/docman/tests/rest/Metadata/CustomMetadataTest.php +58 −66 Go to diff View file
M plugins/docman/tests/rest/Metadata/HardcodedMetadataTest.php +47 −56 Go to diff View file
M plugins/dynamic_credentials/tests/rest/DynamicCredentialsTest.php +19 −31 Go to diff View file
M plugins/frs/tests/rest/FRS/FileTest.php +40 −55 Go to diff View file
M plugins/frs/tests/rest/FRS/PackagesTest.php +21 −22 Go to diff View file
M plugins/frs/tests/rest/FRS/ReleaseTest.php +24 −25 Go to diff View file
M plugins/frs/tests/rest/FRS/ServiceTest.php +10 −10 Go to diff View file
M plugins/git/tests/rest/Git/GerritTest.php +13 −14 Go to diff View file
M plugins/git/tests/rest/Git/ProjectTest.php +9 −18 Go to diff View file
M plugins/git/tests/rest/Git/RepositoryTest.php +59 −82 Go to diff View file
M plugins/gitlab/tests/rest/Gitlab/ProjectTest.php +7 −12 Go to diff View file
M plugins/gitlab/tests/rest/Gitlab/RepositoryTest.php +16 −35 Go to diff View file
M plugins/hudson_git/tests/rest/JenkinsServersTest.php +2 −2 Go to diff View file
M plugins/program_management/tests/rest/v1/ProjectResourceTest.php +38 −60 Go to diff View file
M plugins/project_ownership/tests/rest/ProjectOwnershipTest.php +21 −35 Go to diff View file
M plugins/project_ownership/tests/rest/ProjectUserGroupTest.php +13 −22 Go to diff View file
M plugins/pullrequest/tests/rest/PullRequest/PullRequestsCommentsTest.php +17 −22 Go to diff View file
M plugins/pullrequest/tests/rest/PullRequest/PullRequestsLabelsTest.php +31 −40 Go to diff View file
M plugins/pullrequest/tests/rest/PullRequest/PullRequestsReviewersTest.php +17 −29 Go to diff View file
M plugins/pullrequest/tests/rest/PullRequest/PullRequestsTest.php +6 −10 Go to diff View file
M plugins/roadmap/tests/rest/v1/RoadmapResourceTest.php +6 −6 Go to diff View file
M plugins/svn/tests/rest/SVN/ProjectTest.php +12 −19 Go to diff View file
M plugins/svn/tests/rest/SVN/RepositoryTest.php +27 −32 Go to diff View file
M plugins/svn/tests/rest/SVN/RepositoryTestNonRegressionTest.php +21 −21 Go to diff View file
M plugins/taskboard/tests/rest/TaskboardCardTest.php +16 −16 Go to diff View file
M plugins/taskboard/tests/rest/TaskboardCellTest.php +15 −27 Go to diff View file
M plugins/taskboard/tests/rest/TaskboardTest.php +12 −12 Go to diff View file
M plugins/testmanagement/tests/rest/TestManagement/ArtifactsTest.php +6 −6 Go to diff View file
M plugins/testmanagement/tests/rest/TestManagement/BaseTest.php +5 −7 Go to diff View file
M plugins/testmanagement/tests/rest/TestManagement/CampaignsTest.php +65 −109 Go to diff View file
M plugins/testmanagement/tests/rest/TestManagement/DefinitionsTest.php +8 −8 Go to diff View file
M plugins/testmanagement/tests/rest/TestManagement/ExecutionsTest.php +38 −50 Go to diff View file
M plugins/testmanagement/tests/rest/TestManagement/ProjectTest.php +8 −9 Go to diff View file
M plugins/testplan/tests/rest/v1/BacklogItemTest.php +6 −6 Go to diff View file
M plugins/timetracking/tests/rest/Timetracking/TimetrackingReportTest.php +14 −14 Go to diff View file
M plugins/timetracking/tests/rest/Timetracking/TimetrackingTest.php +34 −34 Go to diff View file
M plugins/tracker/tests/rest/Artifacts/ArtifactsTest.php +13 −14 Go to diff View file
M plugins/tracker/tests/rest/Artifacts/LinkedArtifactsTest.php +7 −8 Go to diff View file
M plugins/tracker/tests/rest/Artifacts/UsersArtifactsTest.php +9 −9 Go to diff View file
M plugins/tracker/tests/rest/ArtifactsActions/ArtifactsActionsTest.php +19 −20 Go to diff View file
M plugins/tracker/tests/rest/ComputedFieldsDefaultValue/ComputedFieldsDefaultValueTest.php +4 −4 Go to diff View file
M plugins/tracker/tests/rest/PrivateComment/PrivateCommentArtifactTest.php +18 −18 Go to diff View file
M plugins/tracker/tests/rest/PrivateComment/PrivateCommentReportQueryTest.php +4 −4 Go to diff View file
M plugins/tracker/tests/rest/TQL/TQLTest.php +7 −7 Go to diff View file
M plugins/tracker/tests/rest/TrackerAdministrator/ProjectTest.php +5 −5 Go to diff View file
M plugins/tracker/tests/rest/TrackerAdministrator/ProjectTrackerTest.php +5 −5 Go to diff View file
M plugins/tracker/tests/rest/TrackerArtifacts/TrackerArtifactsTest.php +8 −8 Go to diff View file
M plugins/tracker/tests/rest/TrackerFields/TrackerFieldsTest.php +38 −53 Go to diff View file
M plugins/tracker/tests/rest/Workflows/SimpleModeTest.php +24 −44 Go to diff View file
M plugins/tracker/tests/rest/Workflows/SwitchTest.php +4 −4 Go to diff View file
M plugins/tracker/tests/rest/Workflows/TrackerWorkflowTransitionsTest.php +32 −106 Go to diff View file
M plugins/tracker/tests/rest/Workflows/TrackerWorkflowsTest.php +15 −27 Go to diff View file
M plugins/tracker/tests/rest/XML/ArtifactTest.php +28 −33 Go to diff View file
M plugins/tracker/tests/rest/XML/SemanticTimeframeImportTest.php +2 −2 Go to diff View file
M plugins/tracker/tests/rest/XMLImportAndFileURLs/XMLImportAndFileURLsTest.php +4 −4 Go to diff View file
M tests/rest/composer.json +3 −4 Go to diff View file
M tests/rest/composer.lock +449 −122 Go to diff View file
M tests/rest/lib/ArtifactsTestExecutionHelper.php +8 −8 Go to diff View file
M tests/rest/lib/RequestWrapper.php +17 −29 Go to diff View file
M tests/rest/lib/RestBase.php +37 −53 Go to diff View file
M tests/rest/lib/TrackerBase.php +2 −1 Go to diff View file
M tests/rest/lib/tracker/Tracker.php +35 −26 Go to diff View file
M tests/rest/lib/tracker/TrackerFactory.php +16 −9 Go to diff View file
M tests/rest/tests/AccessKeyTest.php +23 −31 Go to diff View file
M tests/rest/tests/ArtifactFilesTest.php +59 −47 Go to diff View file
M tests/rest/tests/ArtifactsChangesetsTest.php +13 −16 Go to diff View file
M tests/rest/tests/ArtifactsTest.php +117 −104 Go to diff View file
M tests/rest/tests/AuthenticationTest.php +7 −8 Go to diff View file
M tests/rest/tests/BacklogItemsTest.php +130 −99 Go to diff View file
M tests/rest/tests/CardsTest.php +56 −24 Go to diff View file
M tests/rest/tests/InvitationsTest.php +15 −6 Go to diff View file
M tests/rest/tests/JWTTest.php +6 −4 Go to diff View file
M tests/rest/tests/MilestonesBacklogPatchTest.php +153 −78 Go to diff View file
M tests/rest/tests/MilestonesBacklogTest.php +74 −51 Go to diff View file
M tests/rest/tests/MilestonesBurndownTest.php +8 −9 Go to diff View file
M tests/rest/tests/MilestonesCardwallTest.php +8 −9 Go to diff View file
M tests/rest/tests/MilestonesContentTest.php +64 −34 Go to diff View file
M tests/rest/tests/MilestonesMilestonesTest.php +37 −19 Go to diff View file
M tests/rest/tests/MilestonesTest.php +16 −16 Go to diff View file
M tests/rest/tests/PhpWikiTest.php +19 −20 Go to diff View file
M tests/rest/tests/PlanningTest.php +20 −20 Go to diff View file
M tests/rest/tests/PlatformBannerTest.php +12 −21 Go to diff View file
M tests/rest/tests/ProjectBacklogV2Test.php +10 −20 Go to diff View file
M tests/rest/tests/ProjectFieldsTest.php +2 −2 Go to diff View file
M tests/rest/tests/ProjectMilestonesPeriodTest.php +9 −6 Go to diff View file
M tests/rest/tests/ProjectServicesTest.php +18 −10 Go to diff View file
M tests/rest/tests/ProjectTest.php +373 −242 Go to diff View file
M tests/rest/tests/ReadOnlyAdministrator/ArtifactFilesTest.php +5 −5 Go to diff View file
M tests/rest/tests/ReadOnlyAdministrator/ArtifactsTest.php +11 −10 Go to diff View file
M tests/rest/tests/ReadOnlyAdministrator/ProjectTest.php +55 −41 Go to diff View file
M tests/rest/tests/SystemEventTest.php +9 −9 Go to diff View file
M tests/rest/tests/TokenTest.php +20 −14 Go to diff View file
M tests/rest/tests/TrackersTest.php +118 −74 Go to diff View file
M tests/rest/tests/UserGroupTest.php +170 −112 Go to diff View file
M tests/rest/tests/UserMembershipTest.php +9 −11 Go to diff View file
M tests/rest/tests/UsersTest.php +211 −116 Go to diff View file
M tests/rest/tests/regressions/ArtifactsCreationWithWrongWorkflowTest.php +3 −1 Go to diff View file
M tests/rest/tests/regressions/MilestonesContentOrderTest.php +12 −4 Go to diff View file
M tests/rest/tests/regressions/MilestonesContentTest.php +8 −3 Go to diff View file
M tests/rest/tests/regressions/PutSoloCardTest.php +6 −2 Go to diff View file