Skip to content
Open
Changes from 3 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
38 changes: 38 additions & 0 deletions docs/5.x/tests-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,44 @@ 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

```php
<?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.0.2', '<=') && !\Piwik\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}';
$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`.
Expand Down