From 894d9525c27dff647fc7e1ea2327bebdbec64089 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Mon, 11 Mar 2024 09:00:56 +0530 Subject: [PATCH] Fix `tests:check-direct-dependency-use` command not working with plugins via Github action (#22012) --- plugins/TestRunner/Commands/CheckDirectDependencyUse.php | 8 ++++---- .../tests/System/CheckDirectDependencyUseCommandTest.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/TestRunner/Commands/CheckDirectDependencyUse.php b/plugins/TestRunner/Commands/CheckDirectDependencyUse.php index f35482d679d..bf310ee7190 100644 --- a/plugins/TestRunner/Commands/CheckDirectDependencyUse.php +++ b/plugins/TestRunner/Commands/CheckDirectDependencyUse.php @@ -83,7 +83,7 @@ private function grepForUses($prefix, $psrType, $plugin, $isGrepVendorFolder) $rgOutput = []; if ($plugin) { - $plugin = '/' . $plugin; + $plugin = '/plugins/' . $plugin; } $vendorScan = '--glob=\\!vendor'; @@ -98,7 +98,7 @@ private function grepForUses($prefix, $psrType, $plugin, $isGrepVendorFolder) $regex = '\\b' . preg_quote($prefix) . '_'; } - $command = 'rg \'' . $regex . '\' --glob=*.php ' . $vendorScan . ' --json --sort path ' . PIWIK_INCLUDE_PATH . '/plugins' . $plugin; + $command = 'rg \'' . $regex . '\' --glob=*.php ' . $vendorScan . ' --json --sort path ' . PIWIK_INCLUDE_PATH . $plugin; exec($command, $rgOutput, $returnCode); if (isset($returnCode) && $returnCode == 127) { @@ -119,7 +119,7 @@ private function grepForUses($prefix, $psrType, $plugin, $isGrepVendorFolder) array_shift($parts); $pluginName = array_shift($parts); - if (file_exists(PIWIK_INCLUDE_PATH . '/plugins/' . $pluginName . '/.git')) { + if ($pluginName) { $remainingPath = implode('/', $parts); $uses[$pluginName][] = $remainingPath; } @@ -138,7 +138,7 @@ private function reportDirectUses($prefix, $directUses, $type) $output->writeln("Found '$prefix' ($type) usage in:"); foreach ($directUses as $plugin => $files) { foreach ($files as $file) { - $this->usesFoundList[$plugin][$prefix][] = $plugin . '/' . $file; + $this->usesFoundList[rtrim($plugin, '\\')][rtrim($prefix, '\\')][] = $plugin . '/' . $file; } $output->writeln(" - $plugin, " . count($files) . " files"); } diff --git a/plugins/TestRunner/tests/System/CheckDirectDependencyUseCommandTest.php b/plugins/TestRunner/tests/System/CheckDirectDependencyUseCommandTest.php index 03ce2cd5503..7b99692e1fa 100644 --- a/plugins/TestRunner/tests/System/CheckDirectDependencyUseCommandTest.php +++ b/plugins/TestRunner/tests/System/CheckDirectDependencyUseCommandTest.php @@ -42,8 +42,8 @@ public function testCommand($pluginName, $expectedResult) public function getTestDataForDependencyCheck() { return [ - ['TestRunner', []], - ['Provider', ['Matomo\Network\\' => ['Provider/Columns/Provider.php']]], + ['TestRunner', ['Symfony\Component\Console' => ['TestRunner/tests/System/CheckDirectDependencyUseCommandTest.php']]], + ['Provider', ['Matomo\Network' => ['Provider/Columns/Provider.php']]], ]; } }