From 3f443285f3c7124fbd4fd9fa5e8c18e0245f2641 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Thu, 29 Feb 2024 19:04:48 +0530 Subject: [PATCH 1/4] Added documentation for tests:check-direct-dependency-use comman, #PG-3272 --- docs/5.x/tests-system.md | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/docs/5.x/tests-system.md b/docs/5.x/tests-system.md index 61107384d..eaa42ae81 100644 --- a/docs/5.x/tests-system.md +++ b/docs/5.x/tests-system.md @@ -195,6 +195,51 @@ class ApiTest extends SystemTestCase } ``` +## How to write a test to scan for Matomo core dependencies being used directly in your plugins + +With release of Matomo v5.1.0, now you can check the usage of core dependencies in your plugin directly using the `tests:check-direct-dependency-use` command, you can also write a System test case to test the same by using below sample code. + +```php +markTestSkipped('tests:check-direct-dependency-use is not available in this version'); + } + $pluginName = '{YOUR_PLUGIN_NAME}'; + $console = new \Piwik\Console(self::$fixture->piwikEnvironment); + $checkDirectDependencyUse = new CheckDirectDependencyUse(); + $console->addCommands([$checkDirectDependencyUse]); + $command = $console->find('tests:check-direct-dependency-use'); + $arguments = array( + 'command' => 'tests:check-direct-dependency-use', + '--plugin' => $pluginName, + '--grep-vendor' + ); + $inputObject = new ArrayInput($arguments); + $command->run($inputObject, new NullOutput()); + + $this->assertEmpty($checkDirectDependencyUse->usesFoundList[$pluginName]); + } +} +``` + ## Writing tests for commands It is also possible to write system tests for console commands. These tests should extend `Piwik\Tests\Framework\TestCase\ConsoleCommandTestCase`. From ac5731315862ba54857d032df49978a1c142ef52 Mon Sep 17 00:00:00 2001 From: Altamash Shaikh Date: Thu, 29 Feb 2024 19:05:06 +0530 Subject: [PATCH 2/4] Added documentation for tests:check-direct-dependency-use comman, #PG-3272 --- docs/5.x/tests-system.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/docs/5.x/tests-system.md b/docs/5.x/tests-system.md index eaa42ae81..8364e2847 100644 --- a/docs/5.x/tests-system.md +++ b/docs/5.x/tests-system.md @@ -201,13 +201,6 @@ With release of Matomo v5.1.0, now you can check the usage of core dependencies ```php Date: Fri, 1 Mar 2024 11:17:10 +0530 Subject: [PATCH 3/4] PR suggestion --- docs/5.x/tests-system.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/5.x/tests-system.md b/docs/5.x/tests-system.md index 8364e2847..f2568b7ad 100644 --- a/docs/5.x/tests-system.md +++ b/docs/5.x/tests-system.md @@ -197,7 +197,7 @@ class ApiTest extends SystemTestCase ## How to write a test to scan for Matomo core dependencies being used directly in your plugins -With release of Matomo v5.1.0, now you can check the usage of core dependencies in your plugin directly using the `tests:check-direct-dependency-use` command, you can also write a System test case to test the same by using below sample code. +With the release of Matomo `v5.1.0`, you can now check the usage of core dependencies in your plugin directly using the `tests:check-direct-dependency-use` command. With the release of Matomo 5, plugins should not use core dependencies directly but instead [prefix](https://developer.matomo.org/guides/migrate-matomo-4-to-5#vendor-proxies) them. You can also write a system test case to test the same by using the sample code below ```php Date: Tue, 12 Mar 2024 01:46:42 +0530 Subject: [PATCH 4/4] Applied PR feedback --- docs/5.x/tests-system.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/docs/5.x/tests-system.md b/docs/5.x/tests-system.md index f2568b7ad..fdb3d126e 100644 --- a/docs/5.x/tests-system.md +++ b/docs/5.x/tests-system.md @@ -197,11 +197,9 @@ class ApiTest extends SystemTestCase ## How to write a test to scan for Matomo core dependencies being used directly in your plugins -With the release of Matomo `v5.1.0`, you can now check the usage of core dependencies in your plugin directly using the `tests:check-direct-dependency-use` command. With the release of Matomo 5, plugins should not use core dependencies directly but instead [prefix](https://developer.matomo.org/guides/migrate-matomo-4-to-5#vendor-proxies) them. You can also write a system test case to test the same by using the sample code below +With the release of Matomo `5.1.0`, you can now easily check if your plugin is using any core dependencies by running the `tests:check-direct-dependency-use` command. With the release of Matomo 5, plugins should not use core dependencies directly but instead use them via [proxies](https://developer.matomo.org/guides/migrate-matomo-4-to-5#vendor-proxies). To have a check for this in your test suite and run it automatically, you can also write a system test case by using the sample code below: ```php -markTestSkipped('tests:check-direct-dependency-use is not available in this version'); - } + } + $pluginName = '{YOUR_PLUGIN_NAME}'; - $console = new \Piwik\Console(self::$fixture->piwikEnvironment); + $checkDirectDependencyUse = new CheckDirectDependencyUse(); + $console = new \Piwik\Console(self::$fixture->piwikEnvironment); $console->addCommands([$checkDirectDependencyUse]); + $command = $console->find('tests:check-direct-dependency-use'); - $arguments = array( - 'command' => 'tests:check-direct-dependency-use', + $arguments = [ + 'command' => 'tests:check-direct-dependency-use', '--plugin' => $pluginName, - '--grep-vendor' - ); + '--grep-vendor', + ]; $inputObject = new ArrayInput($arguments); $command->run($inputObject, new NullOutput());