Skip to content

Commit

Permalink
[#261] install composer unused in toggle-model package
Browse files Browse the repository at this point in the history
  • Loading branch information
kpicaza committed Jun 25, 2021
1 parent d50c915 commit 38197b9
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 2 deletions.
2 changes: 2 additions & 0 deletions composer.json
Expand Up @@ -21,6 +21,7 @@
"psr/container": "^1.0.0|^2.0.0"
},
"require-dev": {
"icanhazstring/composer-unused": "^0.7.5",
"infection/infection": "^0.23.0",
"phpro/grumphp": "^1.0",
"phpstan/phpstan": "^0.12",
Expand All @@ -42,6 +43,7 @@
},
"scripts": {
"check-all": [
"composer unused",
"@cs-check",
"@test",
"@inspect",
Expand Down
23 changes: 23 additions & 0 deletions src/CommandRunnerFactory.php
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Pheature\Sdk;

use Pheature\Core\Toggle\Read\FeatureFinder;
use Pheature\Core\Toggle\Read\Toggle;
use Pheature\Sdk\CommandRunner;
use Psr\Container\ContainerInterface;

final class CommandRunnerFactory
{
public function __invoke(ContainerInterface $container): CommandRunner
{
/** @var FeatureFinder $featureFinder */
$featureFinder = $container->get(FeatureFinder::class);

return new CommandRunner(
new Toggle($featureFinder)
);
}
}
2 changes: 1 addition & 1 deletion src/Container/ConfigProvider.php
Expand Up @@ -4,8 +4,8 @@

namespace Pheature\Sdk\Container;

use Pheature\Crud\Psr11\Toggle\CommandRunnerFactory;
use Pheature\Sdk\CommandRunner;
use Pheature\Sdk\CommandRunnerFactory;

final class ConfigProvider
{
Expand Down
55 changes: 55 additions & 0 deletions test/CommandRunnerFactoryTest.php
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Pheature\Test\Sdk;

use Exception;
use Pheature\Core\Toggle\Read\FeatureFinder;
use Pheature\Sdk\CommandRunner;
use Pheature\Sdk\CommandRunnerFactory;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

final class CommandRunnerFactoryTest extends TestCase
{
public function testItShouldThrowAnExceptionWhenFeatureFinderNotFoundInContainer(): void
{
$this->expectException(NotFoundExceptionInterface::class);

$notFoundException = new class() extends Exception implements NotFoundExceptionInterface {
};

/** @var ContainerInterface|MockObject $emptyContainer */
$emptyContainer = $this->createMock(ContainerInterface::class);
$emptyContainer
->expects($this->once())
->method('get')
->with(FeatureFinder::class)
->willThrowException($notFoundException);

$commandRunnerFactory = new CommandRunnerFactory();
$commandRunnerFactory->__invoke($emptyContainer);
}

public function testItShouldCreateACommandRunner(): void
{
/** @var FeatureFinder|MockObject $featureFinder */
$featureFinder = $this->createMock(FeatureFinder::class);

/** @var ContainerInterface|MockObject $container */
$container = $this->createMock(ContainerInterface::class);
$container
->expects($this->once())
->method('get')
->with(FeatureFinder::class)
->willReturn($featureFinder);

$commandRunnerFactory = new CommandRunnerFactory();
$actual = $commandRunnerFactory->__invoke($container);

self::assertInstanceOf(CommandRunner::class, $actual);
}
}
2 changes: 1 addition & 1 deletion test/Container/ConfigProviderTest.php
Expand Up @@ -4,8 +4,8 @@

namespace Pheature\Test\Sdk\Container;

use Pheature\Crud\Psr11\Toggle\CommandRunnerFactory;
use Pheature\Sdk\CommandRunner;
use Pheature\Sdk\CommandRunnerFactory;
use Pheature\Sdk\Container\ConfigProvider;
use PHPUnit\Framework\TestCase;

Expand Down

0 comments on commit 38197b9

Please sign in to comment.