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

Avoid using Psr\Log\Test\TestLogger #32

Merged
merged 1 commit into from
Aug 1, 2021
Merged
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
29 changes: 18 additions & 11 deletions tests/ToggleRouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use Assert\InvalidArgumentException;
use Doctrine\DBAL\DriverManager;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\Test\TestLogger;
use Psr\Log\LoggerInterface;
use Trompette\FeatureToggles\DBAL\OnOffStrategyConfigurationRepository;
use Trompette\FeatureToggles\DBAL\PercentageStrategyConfigurationRepository;
use Trompette\FeatureToggles\DBAL\WhitelistStrategyConfigurationRepository;
Expand All @@ -24,11 +25,13 @@ class ToggleRouterTest extends TestCase

public function testTargetDoesNotHaveUnregisteredFeature()
{
$logger = $this->prophesize(LoggerInterface::class);
$logger->warning('Feature is unregistered', Argument::type('array'))->shouldBeCalled();

$router = $this->configureToggleRouter();
$router->setLogger($logger = new TestLogger());
$router->setLogger($logger->reveal());

static::assertFalse($router->hasFeature('target', 'feature'));
static::assertTrue($logger->hasWarning('Feature is unregistered'));
}

public function testTargetHasRegisteredFeatureWithValidStrategy()
Expand All @@ -47,11 +50,13 @@ public function testTargetDoesNotHaveRegisteredFeatureWithValidStrategy()

public function testTargetDoesNotHaveRegisteredFeatureWithInvalidStrategy()
{
$logger = $this->prophesize(LoggerInterface::class);
$logger->warning('Feature strategy is invalid', Argument::type('array'))->shouldBeCalled();

$router = $this->configureToggleRouter(new FeatureDefinition('feature', 'awesome feature', 'invalid'));
$router->setLogger($logger = new TestLogger());
$router->setLogger($logger->reveal());

static::assertFalse($router->hasFeature('target', 'feature'));
static::assertTrue($logger->hasWarning('Feature strategy is invalid'));
}

public function testFeatureConfigurationCanBeRetrievedByStrategy()
Expand All @@ -69,26 +74,28 @@ public function testUnregisteredFeatureCanBeConfiguredByStrategy()
$strategy = $this->prophesize(FakeStrategy::class);
$strategy->configure('value', 'feature')->shouldBeCalled();

$logger = $this->prophesize(LoggerInterface::class);
$logger->info('Feature has been configured', Argument::type('array'))->shouldBeCalled();

$router = $this->configureToggleRouter(null, ['fake' => $strategy->reveal()]);
$router->setLogger($logger = new TestLogger());
$router->setLogger($logger->reveal());
$router->configureFeature('feature', 'fake', 'configure', 'value');

static::assertTrue($logger->hasInfo('Feature has been configured'));
}

public function testRegisteredFeatureCanBeConfiguredByStrategy()
{
$strategy = $this->prophesize(FakeStrategy::class);
$strategy->configure('value', 'feature')->shouldBeCalled();

$logger = $this->prophesize(LoggerInterface::class);
$logger->info('Feature has been configured', Argument::type('array'))->shouldBeCalled();

$router = $this->configureToggleRouter(
new FeatureDefinition('feature', 'awesome feature', 'true'),
['fake' => $strategy->reveal()]
);
$router->setLogger($logger = new TestLogger());
$router->setLogger($logger->reveal());
$router->configureFeature('feature', 'fake', 'configure', 'value');

static::assertTrue($logger->hasInfo('Feature has been configured'));
}

public function testFeatureCannotBeConfiguredWhenStrategyDoesNotExist()
Expand Down