diff options
author | Thomas Steur <tsteur@users.noreply.github.com> | 2020-10-27 14:11:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 14:11:51 +0300 |
commit | 8f703bbc9d914d013c124d1e1d0f2ecd47d88ec4 (patch) | |
tree | 6e19c7f0c5f025d15d49e3aba95e82760e612554 /tests/PHPUnit/Framework | |
parent | 76ab5fedff8bd0b6837f67a81ba0c2d9099ed86b (diff) |
Automatically add phpunit group name to a plugin php test (#16615)
* Automatically add plugin group to every test
* prevent possible error
* add test
Diffstat (limited to 'tests/PHPUnit/Framework')
-rw-r--r-- | tests/PHPUnit/Framework/TestCase/SystemTestCase.php | 13 | ||||
-rw-r--r-- | tests/PHPUnit/Framework/TestCase/UnitTestCase.php | 15 |
2 files changed, 27 insertions, 1 deletions
diff --git a/tests/PHPUnit/Framework/TestCase/SystemTestCase.php b/tests/PHPUnit/Framework/TestCase/SystemTestCase.php index 20ebb007bb..da1e1dfb23 100644 --- a/tests/PHPUnit/Framework/TestCase/SystemTestCase.php +++ b/tests/PHPUnit/Framework/TestCase/SystemTestCase.php @@ -58,6 +58,19 @@ abstract class SystemTestCase extends TestCase */ public static $fixture; + public function setGroups(array $groups): void + { + $pluginName = explode('\\', get_class($this)); + if (!empty($pluginName[2]) && !empty($pluginName[1]) && $pluginName[1] === 'Plugins') { + // we assume \Piwik\Plugins\PluginName nanmespace... + if (!in_array($pluginName[2], $groups, true)) { + $groups[] = $pluginName[2]; + } + } + + parent::setGroups($groups); + } + public static function setUpBeforeClass(): void { Log::debug("Setting up " . get_called_class()); diff --git a/tests/PHPUnit/Framework/TestCase/UnitTestCase.php b/tests/PHPUnit/Framework/TestCase/UnitTestCase.php index d81f000a3d..56428a92de 100644 --- a/tests/PHPUnit/Framework/TestCase/UnitTestCase.php +++ b/tests/PHPUnit/Framework/TestCase/UnitTestCase.php @@ -26,6 +26,19 @@ abstract class UnitTestCase extends \PHPUnit\Framework\TestCase */ protected $environment; + public function setGroups(array $groups): void + { + $pluginName = explode('\\', get_class($this)); + if (!empty($pluginName[2]) && !empty($pluginName[1]) && $pluginName[1] === 'Plugins') { + // we assume \Piwik\Plugins\PluginName nanmespace... + if (!in_array($pluginName[2], $groups, true)) { + $groups[] = $pluginName[2]; + } + } + + parent::setGroups($groups); + } + public function setUp(): void { parent::setUp(); @@ -41,7 +54,7 @@ abstract class UnitTestCase extends \PHPUnit\Framework\TestCase // make sure the global container exists for the next test case that is executed (since logging can be done // before a test sets up an environment) - $nextTestEnviornment = new Environment($environment = null, array(), $postBootstrappedEvent = false); + $nextTestEnviornment = new Environment($environment = null, array()); $nextTestEnviornment->init(); parent::tearDown(); |