Skip to content

Commit

Permalink
[#178] Add ToggleAPIPassTest
Browse files Browse the repository at this point in the history
  • Loading branch information
pheaturebot committed May 23, 2021
1 parent e5e1d13 commit c19ecc0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Expand Up @@ -6,7 +6,7 @@
</include>
</coverage>
<testsuites>
<testsuite name="Antidot\\Tests">
<testsuite name="Pheature\\Test\\Crud\\Psr11">
<directory>./test</directory>
</testsuite>
</testsuites>
Expand Down
12 changes: 6 additions & 6 deletions src/ToggleConfig.php
Expand Up @@ -9,7 +9,7 @@
final class ToggleConfig
{
private string $driver;
private string $prefix;
private string $apiPrefix;
/** @var array<string, mixed> */
private array $toggles = [];

Expand All @@ -18,11 +18,11 @@ final class ToggleConfig
*/
public function __construct(array $config)
{
Assert::keyExists($config, 'prefix');
Assert::keyExists($config, 'api_prefix');
Assert::keyExists($config, 'driver');
Assert::string($config['prefix']);
Assert::string($config['api_prefix']);
Assert::string($config['driver']);
$this->prefix = $config['prefix'];
$this->apiPrefix = $config['api_prefix'];
$this->driver = $config['driver'];
if (array_key_exists('toggles', $config)) {
Assert::isArray($config['toggles']);
Expand All @@ -32,9 +32,9 @@ public function __construct(array $config)
}
}

public function prefix(): string
public function apiPrefix(): string
{
return $this->prefix;
return $this->apiPrefix;
}

public function driver(): string
Expand Down
10 changes: 5 additions & 5 deletions test/FeatureFinderFactoryTest.php
Expand Up @@ -25,7 +25,7 @@ public function testItShouldThrowAnExceptionWhenItCantCreateAFeatureFinder(): vo
$this->createMock(SegmentFactory::class),
$this->createMock(ToggleStrategyFactory::class),
);
$toggleConfig = new ToggleConfig(['prefix' => '', 'driver' => 'some_other']);
$toggleConfig = new ToggleConfig(['api_prefix' => '', 'driver' => 'some_other']);

$container->expects(self::exactly(3))
->method('get')
Expand All @@ -41,7 +41,7 @@ public function testItShouldThrowAnExceptionWhenItCantCreateAFeatureFinder(): vo
public function testItShouldCreateADBalFeatureFinderFromInvokable(): void
{
$container = $this->createMock(ContainerInterface::class);
$toggleConfig = new ToggleConfig(['prefix' => '', 'driver' => 'dbal']);
$toggleConfig = new ToggleConfig(['api_prefix' => '', 'driver' => 'dbal']);
$chainStrategyFactory = new ChainToggleStrategyFactory(
$this->createMock(SegmentFactory::class),
$this->createMock(ToggleStrategyFactory::class),
Expand All @@ -62,7 +62,7 @@ public function testItShouldCreateADBalFeatureFinderFromInvokable(): void
public function testItShouldCreateAnInMemoryFeatureFinderFromInvokable(): void
{
$container = $this->createMock(ContainerInterface::class);
$toggleConfig = new ToggleConfig(['prefix' => '', 'driver' => 'inmemory']);
$toggleConfig = new ToggleConfig(['api_prefix' => '', 'driver' => 'inmemory']);
$chainStrategyFactory = new ChainToggleStrategyFactory(
$this->createMock(SegmentFactory::class),
$this->createMock(ToggleStrategyFactory::class),
Expand All @@ -81,7 +81,7 @@ public function testItShouldCreateAnInMemoryFeatureFinderFromInvokable(): void

public function testItShouldCreateADBalFeatureFinderFromCreate(): void
{
$toggleConfig = new ToggleConfig(['prefix' => '', 'driver' => 'dbal']);
$toggleConfig = new ToggleConfig(['api_prefix' => '', 'driver' => 'dbal']);
$chainStrategyFactory = new ChainToggleStrategyFactory(
$this->createMock(SegmentFactory::class),
$this->createMock(ToggleStrategyFactory::class),
Expand All @@ -93,7 +93,7 @@ public function testItShouldCreateADBalFeatureFinderFromCreate(): void

public function testItShouldCreateInMemoryFeatureFinderFromCreate(): void
{
$toggleConfig = new ToggleConfig(['prefix' => '', 'driver' => 'inmemory']);
$toggleConfig = new ToggleConfig(['api_prefix' => '', 'driver' => 'inmemory']);
$chainStrategyFactory = new ChainToggleStrategyFactory(
$this->createMock(SegmentFactory::class),
$this->createMock(ToggleStrategyFactory::class),
Expand Down
10 changes: 5 additions & 5 deletions test/FeatureRepositoryFactoryTest.php
Expand Up @@ -21,7 +21,7 @@ public function testItShouldThrowAnExceptionWhenItCantCreateAFeatureRepository()
{
$this->expectException(InvalidArgumentException::class);
$container = $this->createMock(ContainerInterface::class);
$toggleConfig = new ToggleConfig(['prefix' => '', 'driver' => 'some_other']);
$toggleConfig = new ToggleConfig(['api_prefix' => '', 'driver' => 'some_other']);

$container->expects(self::exactly(2))
->method('get')
Expand All @@ -36,7 +36,7 @@ public function testItShouldThrowAnExceptionWhenItCantCreateAFeatureRepository()
public function testItShouldCreateADBalFeatureRepositoryFromInvokable(): void
{
$container = $this->createMock(ContainerInterface::class);
$toggleConfig = new ToggleConfig(['prefix' => '', 'driver' => 'dbal']);
$toggleConfig = new ToggleConfig(['api_prefix' => '', 'driver' => 'dbal']);
$connection = $this->createMock(Connection::class);

$container->expects(static::exactly(2))
Expand All @@ -53,7 +53,7 @@ public function testItShouldCreateADBalFeatureRepositoryFromInvokable(): void
public function testItShouldCreateAnInMemoryFeatureRepositoryFromInvokable(): void
{
$container = $this->createMock(ContainerInterface::class);
$toggleConfig = new ToggleConfig(['prefix' => '', 'driver' => 'inmemory']);
$toggleConfig = new ToggleConfig(['api_prefix' => '', 'driver' => 'inmemory']);

$container->expects(static::exactly(2))
->method('get')
Expand All @@ -68,15 +68,15 @@ public function testItShouldCreateAnInMemoryFeatureRepositoryFromInvokable(): vo

public function testItShouldCreateADBalFeatureRepositoryFromCreate(): void
{
$toggleConfig = new ToggleConfig(['prefix' => '', 'driver' => 'dbal']);
$toggleConfig = new ToggleConfig(['api_prefix' => '', 'driver' => 'dbal']);
$connection = $this->createMock(Connection::class);
$featureRepository = FeatureRepositoryFactory::create($toggleConfig, $connection);
self::assertInstanceOf(FeatureRepository::class, $featureRepository);
}

public function testItShouldCreateInMemoryFeatureRepositoryFromCreate(): void
{
$toggleConfig = new ToggleConfig(['prefix' => '', 'driver' => 'inmemory']);
$toggleConfig = new ToggleConfig(['api_prefix' => '', 'driver' => 'inmemory']);
$connection = null;
$featureRepository = FeatureRepositoryFactory::create($toggleConfig, $connection);
self::assertInstanceOf(FeatureRepository::class, $featureRepository);
Expand Down

0 comments on commit c19ecc0

Please sign in to comment.