قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-22 06:57:53 +00:00

* Add feature flags plugin w/ config implementation and example feature * Make sure FeatureFlags plugin always loaded * Don't use DI for test feature, create new migration / version for the plugin * Add license info to files * Update screenshot tests * Update screenshot tests * Show HTML tag in markup * Update plugins/FeatureFlags/config/config.php Co-authored-by: Michal Kleiner <michal@innocraft.com> * Change Feature class names to NameFeatureFlag * Increase version * Increase version * Fix migration file name * Don't use DI for test feature, create new migration / version for the plugin * remove not needed migration * Make interface easier to use so you don't have to pass objects but just class names. * Move flags to DI and write more tests * Add command + system tests * Fix cs problems * Fix problem with example flag in home controller * Fix CS issues * Tidy up command * Update plugins/FeatureFlags/config/config.php Co-authored-by: Michal Kleiner <michal@innocraft.com> * Remove dependency on DI for feature flag manager * Split command into 3 commands, and rely on plugin manager rather than DI * Use constants for storage implementation * Use correct implementation of manager * Update deletion to not depend on concrete class * Remove plugin from pluginToAlwaysActivate and add plugin.json file * Fix spacing * Remove orphaned test * Remove extra closing bracket * Fix desc of command * Remove plugins.json and plugin base class * Fix config DI * Add plugin to list of always activated plugins * ensure to automatically activate newly added plugins, that are enabled by default * Ensure to always load di config of always activated plugins * Update expected screenshots --------- Co-authored-by: Michal Kleiner <michal@innocraft.com> Co-authored-by: sgiehl <stefan@matomo.org> Co-authored-by: Marc Neudert <marc@innocraft.com>
130 خطوط
3.3 KiB
PHP
130 خطوط
3.3 KiB
PHP
<?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\Plugins\FeatureFlags\tests\Unit;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Piwik\Log\LoggerInterface;
|
|
use Piwik\Plugins\FeatureFlags\FeatureFlagInterface;
|
|
use Piwik\Plugins\FeatureFlags\FeatureFlagManager;
|
|
use Piwik\Plugins\FeatureFlags\FeatureFlagStorageInterface;
|
|
|
|
class FeatureFlagManagerTest extends TestCase
|
|
{
|
|
public function testIsFeatureActiveReturnsFalseIfUnknownFeaturePassed()
|
|
{
|
|
$logger = $this->createMock(LoggerInterface::class);
|
|
$sut = new FeatureFlagManager([], $logger);
|
|
|
|
$this->assertFalse($sut->isFeatureActive('UnknownFeature'));
|
|
}
|
|
|
|
public function testIsFeatureActiveLogsDebugMessageIfFeatureNotFound()
|
|
{
|
|
$logger = $this->createMock(LoggerInterface::class);
|
|
$logger->expects($this->once())
|
|
->method('debug')
|
|
->with('isFeatureActive failed due to class not implementing FeatureFlagInterface', [
|
|
'featureFlag' => 'UnknownFeature'
|
|
]);
|
|
|
|
$sut = new FeatureFlagManager([], $logger);
|
|
|
|
$sut->isFeatureActive('UnknownFeature');
|
|
}
|
|
|
|
/**
|
|
* @dataProvider listOfStorages
|
|
*/
|
|
public function testIsFeatureActiveOverridesBasedOnOrderOfStorage(array $storageResponses, bool $expectedOutcome): void
|
|
{
|
|
$storages = [];
|
|
$logger = $this->createMock(LoggerInterface::class);
|
|
|
|
foreach ($storageResponses as $storageResponse) {
|
|
$mock = $this->createMock(FeatureFlagStorageInterface::class);
|
|
$mock->method('isFeatureActive')->willReturn($storageResponse);
|
|
$storages[] = $mock;
|
|
}
|
|
|
|
$mockFeature = $this->createMock(FeatureFlagInterface::class);
|
|
|
|
$sut = new FeatureFlagManager(
|
|
$storages,
|
|
$logger
|
|
);
|
|
|
|
$this->assertEquals($expectedOutcome, $sut->isFeatureActive(get_class($mockFeature)));
|
|
}
|
|
|
|
public function listOfStorages(): \Generator
|
|
{
|
|
yield [
|
|
[
|
|
// The return values for isFeatureActive on the storage
|
|
true,
|
|
false,
|
|
true
|
|
],
|
|
// Expected outcome
|
|
true
|
|
];
|
|
|
|
yield [
|
|
[
|
|
// The return values for isFeatureActive on the storage
|
|
false,
|
|
null,
|
|
false
|
|
],
|
|
// Expected outcome
|
|
false
|
|
];
|
|
|
|
yield [
|
|
[
|
|
// The return values for isFeatureActive on the storage
|
|
null,
|
|
null,
|
|
true
|
|
],
|
|
// Expected outcome
|
|
true
|
|
];
|
|
|
|
yield [
|
|
[
|
|
// The return values for isFeatureActive on the storage
|
|
true,
|
|
true,
|
|
false
|
|
],
|
|
// Expected outcome
|
|
false
|
|
];
|
|
|
|
yield [
|
|
[
|
|
// The return values for isFeatureActive on the storage
|
|
true,
|
|
true,
|
|
null
|
|
],
|
|
// Expected outcome
|
|
true
|
|
];
|
|
|
|
yield [
|
|
[],
|
|
// Expected outcome
|
|
false
|
|
];
|
|
}
|
|
}
|