* refactored with entity service, so the code can be tested

This commit is contained in:
Danyi Dávid
2016-08-01 17:30:43 +02:00
parent f3939bbd13
commit 2de0bf8add
35 changed files with 359 additions and 215 deletions

View 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);
}
}

View 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);
}
}

View File

@@ -5,22 +5,21 @@ namespace AppTest\Action;
use App\Action\HomePageAction;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequest;
use Zend\Expressive\Router\RouterInterface;
use Doctrine\ORM\EntityManager;
class HomePageActionTest extends \PHPUnit_Framework_TestCase
{
/** @var RouterInterface */
protected $router;
protected function setUp()
{
$this->router = $this->prophesize(RouterInterface::class);
}
public function testResponse()
{
$homePage = new HomePageAction($this->router->reveal(), null);
$homePage = new HomePageAction();
$response = $homePage(new ServerRequest(['/']), new Response(), function () {
});
$this->assertTrue($response instanceof Response);

View File

@@ -5,7 +5,7 @@ namespace AppTest\Action;
use App\Action\HomePageAction;
use App\Action\HomePageFactory;
use Interop\Container\ContainerInterface;
use Zend\Expressive\Router\RouterInterface;
use Doctrine\ORM\EntityManager;
use Zend\Expressive\Template\TemplateRendererInterface;
class HomePageFactoryTest extends \PHPUnit_Framework_TestCase
@@ -16,9 +16,9 @@ class HomePageFactoryTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$this->container = $this->prophesize(ContainerInterface::class);
$router = $this->prophesize(RouterInterface::class);
$em = $this->prophesize(EntityManager::class);
$this->container->get(RouterInterface::class)->willReturn($router);
$this->container->get('doctrine.entity_manager.orm_default')->willReturn($em);
}
public function testFactoryWithoutTemplate()