Skip to content

Commit

Permalink
[#14] Test ChainToggleStrategyFactoryFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
kpicaza committed Nov 21, 2021
1 parent a17b463 commit 8e0f695
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
51 changes: 51 additions & 0 deletions test/ChainToggleStrategyFactoryFactoryTest.php
@@ -0,0 +1,51 @@
<?php

declare(strict_types=1);

namespace Pheature\Test\Crud\Psr11\Toggle;

use Pheature\Core\Toggle\Read\ChainToggleStrategyFactory;
use Pheature\Model\Toggle\SegmentFactory;
use Pheature\Crud\Psr11\Toggle\ChainToggleStrategyFactoryFactory;
use Pheature\Crud\Psr11\Toggle\ToggleConfig;
use Pheature\Model\Toggle\StrategyFactory;
use Pheature\Test\Crud\Psr11\Toggle\Fixtures\PheatureFlagsConfig;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;

class ChainToggleStrategyFactoryFactoryTest extends TestCase
{
public function testItShouldCreateInstancesOfChainToggleStrategyFactory(): void
{
$segmentFactory = new SegmentFactory();
$strategyFactory = new StrategyFactory();
$container = $this->createMock(ContainerInterface::class);
$container->expects(self::exactly(4))
->method('get')
->withConsecutive(
[SegmentFactory::class],
[ToggleConfig::class],
['enable_by_matching_segment'],
['enable_by_matching_identity_id']
)
->willReturnOnConsecutiveCalls(
$segmentFactory,
new ToggleConfig(PheatureFlagsConfig::createDefault()->build()),
$strategyFactory,
$strategyFactory,
);

$factory = new ChainToggleStrategyFactoryFactory();
$chainToggleStrategyFactory = $factory->__invoke($container);
self::assertInstanceOf(ChainToggleStrategyFactory::class, $chainToggleStrategyFactory);
}

public function testItShouldCreateInstancesOfChainToggleStrategyFactoryStatically(): void
{
$segmentFactory = new SegmentFactory();
$strategyFactory = new StrategyFactory();

$chainToggleStrategyFactory = ChainToggleStrategyFactoryFactory::create($segmentFactory, $strategyFactory, $strategyFactory);
self::assertInstanceOf(ChainToggleStrategyFactory::class, $chainToggleStrategyFactory);
}
}
3 changes: 1 addition & 2 deletions test/ToggleConfigTest.php
Expand Up @@ -103,8 +103,7 @@ public function testItIsCreatedWithValidDrivers(
array $config,
string $expectedDriver,
array $expectedDriverOptions
): void
{
): void {
$toggleConfig = new ToggleConfig($config);

$this->assertSame($expectedDriver, $toggleConfig->driver());
Expand Down

0 comments on commit 8e0f695

Please sign in to comment.