Skip to content

Commit

Permalink
[#132] PatchFeatureFactory Static & Test
Browse files Browse the repository at this point in the history
  • Loading branch information
pheaturebot committed Apr 25, 2021
1 parent 57bf95f commit 06014ac
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/PatchFeatureFactory.php
Expand Up @@ -27,6 +27,16 @@ public function __invoke(ContainerInterface $container): PatchFeature
/** @var ResponseFactoryInterface $responseFactory */
$responseFactory = $container->get(ResponseFactoryInterface::class);

return self::create($addStrategy, $removeStrategy, $enableFeature, $disableFeature, $responseFactory);
}

public static function create(
AddStrategy $addStrategy,
RemoveStrategy $removeStrategy,
EnableFeature $enableFeature,
DisableFeature $disableFeature,
ResponseFactoryInterface $responseFactory
): PatchFeature {
return new PatchFeature($addStrategy, $removeStrategy, $enableFeature, $disableFeature, $responseFactory);
}
}
53 changes: 53 additions & 0 deletions test/PatchFeatureFactoryTest.php
@@ -0,0 +1,53 @@
<?php

namespace Pheature\Test\Crud\Psr11\Toggle;

use Pheature\Core\Toggle\Write\FeatureRepository;
use Pheature\Crud\Psr11\Toggle\PatchFeatureFactory;
use Pheature\Crud\Psr7\Toggle\PatchFeature;
use Pheature\Crud\Toggle\Handler\AddStrategy;
use Pheature\Crud\Toggle\Handler\DisableFeature;
use Pheature\Crud\Toggle\Handler\EnableFeature;
use Pheature\Crud\Toggle\Handler\RemoveStrategy;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;

class PatchFeatureFactoryTest extends TestCase
{
public function testItShouldCreateInstanceOfPatchFeature(): void
{
$featureRepository = $this->createMock(FeatureRepository::class);
$addStrategy = new AddStrategy($featureRepository);
$removeStrategy = new RemoveStrategy($featureRepository);
$enableFeature = new EnableFeature($featureRepository);
$disableFeature = new DisableFeature($featureRepository);
$responseFactory = $this->createMock(ResponseFactoryInterface::class);
$container = $this->createMock(ContainerInterface::class);

$container->expects(static::exactly(5))
->method('get')
->withConsecutive([AddStrategy::class], [RemoveStrategy::class],
[EnableFeature::class], [DisableFeature::class], [ResponseFactoryInterface::class])
->willReturnOnConsecutiveCalls($addStrategy, $removeStrategy,
$enableFeature, $disableFeature, $responseFactory);

$patchFeatureFactory = new PatchFeatureFactory();

$patchFeatureFactory->__invoke($container);
}

public function testItShouldCreateInstanceOfPatchFeatureStatically(): void
{
$featureRepository = $this->createMock(FeatureRepository::class);
$addStrategy = new AddStrategy($featureRepository);
$removeStrategy = new RemoveStrategy($featureRepository);
$enableFeature = new EnableFeature($featureRepository);
$disableFeature = new DisableFeature($featureRepository);
$responseFactory = $this->createMock(ResponseFactoryInterface::class);

$patchFeature = PatchFeatureFactory::create($addStrategy, $removeStrategy, $enableFeature, $disableFeature, $responseFactory);

$this->assertInstanceOf(PatchFeature::class, $patchFeature);
}
}

0 comments on commit 06014ac

Please sign in to comment.