* refactored with entity service, so the code can be tested
This commit is contained in:
38
test/AppTest/Action/Article/ListActionTest.php
Normal file
38
test/AppTest/Action/Article/ListActionTest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action\Article;
|
||||
|
||||
use App\Action\Article\ListAction;
|
||||
use App\Entity\User;
|
||||
use App\Service\Article\ArticleService;
|
||||
use App\Service\EntityServiceInterface;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\ServerRequest;
|
||||
|
||||
class ListActionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/** @var EntityServiceInterface */
|
||||
protected $entityService;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$user = new User();
|
||||
|
||||
$entityService = $this->prophesize(ArticleService::class);
|
||||
$entityService->willImplement(EntityServiceInterface::class);
|
||||
$entityService->getList()->willReturn([]);
|
||||
|
||||
$this->entityService = $entityService;
|
||||
}
|
||||
|
||||
public function testResponse()
|
||||
{
|
||||
$page = new ListAction($this->entityService->reveal());
|
||||
$response = $page(new ServerRequest(['/api/article']), new Response(), function () {
|
||||
|
||||
});
|
||||
|
||||
$this->assertTrue($response instanceof Response);
|
||||
}
|
||||
}
|
||||
51
test/AppTest/Action/Article/ListFactoryTest.php
Normal file
51
test/AppTest/Action/Article/ListFactoryTest.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action\Article;
|
||||
|
||||
use App\Action\Article\ListAction;
|
||||
use App\Action\Article\ListFactory;
|
||||
use App\Service\Article\ArticleService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
use Zend\Expressive\Template\TemplateRendererInterface;
|
||||
|
||||
class ListFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/** @var ContainerInterface */
|
||||
protected $container;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->container = $this->prophesize(ContainerInterface::class);
|
||||
$articleService = $this->prophesize(ArticleService::class);
|
||||
|
||||
$this->container->get(ArticleService::class)->willReturn($articleService);
|
||||
}
|
||||
|
||||
public function testFactoryWithoutTemplate()
|
||||
{
|
||||
$factory = new ListFactory();
|
||||
$this->container->has(TemplateRendererInterface::class)->willReturn(false);
|
||||
|
||||
$this->assertTrue($factory instanceof ListFactory);
|
||||
|
||||
$page = $factory($this->container->reveal());
|
||||
|
||||
$this->assertTrue($page instanceof ListAction);
|
||||
}
|
||||
|
||||
public function testFactoryWithTemplate()
|
||||
{
|
||||
$factory = new ListFactory();
|
||||
$this->container->has(TemplateRendererInterface::class)->willReturn(true);
|
||||
$this->container
|
||||
->get(TemplateRendererInterface::class)
|
||||
->willReturn($this->prophesize(TemplateRendererInterface::class));
|
||||
|
||||
$this->assertTrue($factory instanceof ListFactory);
|
||||
|
||||
$homePage = $factory($this->container->reveal());
|
||||
|
||||
$this->assertTrue($homePage instanceof ListAction);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user