Skip to content

Commit

Permalink
[#133] Add static version to PostFeatureFactory
Browse files Browse the repository at this point in the history
  • Loading branch information
xserrat authored and kpicaza committed Apr 25, 2021
1 parent c9455bc commit 11fa3e1
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Expand Up @@ -18,6 +18,11 @@ public function __invoke(ContainerInterface $container): PostFeature
/** @var ResponseFactoryInterface $responseFactory */
$responseFactory = $container->get(ResponseFactoryInterface::class);

return self::create($createFeature, $responseFactory);
}

public static function create(CreateFeature $createFeature, ResponseFactoryInterface $responseFactory): PostFeature
{
return new PostFeature($createFeature, $responseFactory);
}
}
@@ -0,0 +1,45 @@
<?php

namespace Pheature\Test\Crud\Psr11\Toggle;

use Pheature\Core\Toggle\Write\FeatureRepository;
use Pheature\Crud\Psr11\Toggle\PostFeatureFactory;
use Pheature\Crud\Psr7\Toggle\PostFeature;
use Pheature\Crud\Toggle\Handler\CreateFeature;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;

final class PostFeatureFactoryTest extends TestCase
{
public function testItShouldCreateAPostFeatureFromInvokable(): void
{
$container = $this->createMock(ContainerInterface::class);
$createFeature = new CreateFeature($this->createMock(FeatureRepository::class));
$responseFactory = $this->createMock(ResponseFactoryInterface::class);

$container
->expects(self::exactly(2))
->method('get')
->withConsecutive([CreateFeature::class], [ResponseFactoryInterface::class])
->willReturnOnConsecutiveCalls($createFeature, $responseFactory);

$factory = new PostFeatureFactory();
$actual = $factory->__invoke($container);

self::assertInstanceOf(PostFeature::class, $actual);
}

public function testItShouldCreateAPostFeatureFromCreate(): void
{
$createFeature = new CreateFeature($this->createMock(FeatureRepository::class));
$responseFactory = $this->createMock(ResponseFactoryInterface::class);

$actual = PostFeatureFactory::create(
$createFeature,
$responseFactory
);

self::assertInstanceOf(PostFeature::class, $actual);
}
}

0 comments on commit 11fa3e1

Please sign in to comment.