File size: 2,209 Bytes
bf8c0ce | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | <?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Tests\Framework\TestCase;
use Piwik\Application\Environment;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\Mock\File;
/**
* Base class for Unit tests. Use this if you need to use the DI container in tests. It will be created fresh
* before each test.
*
* @deprecated Unit tests don't need no environment.
*
* @since 2.10.0
*/
abstract class UnitTestCase extends \PHPUnit\Framework\TestCase
{
/**
* @var Environment
*/
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();
$this->initEnvironment();
Fixture::clearInMemoryCaches($resetTranslations = false);
File::reset();
}
public function tearDown(): void
{
File::reset();
Fixture::clearInMemoryCaches($resetTranslations = false);
// 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());
$nextTestEnviornment->init();
parent::tearDown();
}
/**
* Use this method to return custom container configuration that you want to apply for the tests.
*
* @return array
*/
protected function provideContainerConfig()
{
return array();
}
protected function initEnvironment()
{
$this->environment = new Environment($environment = null, $this->provideContainerConfig(), $postBootstrappedEvent = false);
$this->environment->init();
}
}
|