Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added documentation for tests:check-direct-dependency-use command, #PG-3272 #778

Open
wants to merge 4 commits into
base: live
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions docs/5.x/tests-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,45 @@ 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 `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
use Piwik\Plugins\TestRunner\Commands\CheckDirectDependencyUse;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Version;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\NullOutput;

class CheckDirectDependencyUseCommandTest extends SystemTestCase
{
public function testCommand()
{
if (version_compare(Version::VERSION, '5.1.0', '<=') || !file_exists(PIWIK_INCLUDE_PATH . '/plugins/TestRunner/Commands/CheckDirectDependencyUse.php')) {
$this->markTestSkipped('tests:check-direct-dependency-use is not available in this version');
}

$pluginName = '{YOUR_PLUGIN_NAME}';

$checkDirectDependencyUse = new CheckDirectDependencyUse();
$console = new \Piwik\Console(self::$fixture->piwikEnvironment);
$console->addCommands([$checkDirectDependencyUse]);

$command = $console->find('tests:check-direct-dependency-use');
$arguments = [
'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`.
Expand Down