49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace AppTest\Action\Article;
|
|
|
|
use App\Action\Article\DeleteAction;
|
|
use App\Service\Article\ArticleService;
|
|
use App\Service\EntityServiceInterface;
|
|
use Zend\Diactoros\Response;
|
|
use Zend\Diactoros\ServerRequest;
|
|
|
|
class DeleteActionTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
|
|
/** @var EntityServiceInterface */
|
|
protected $entityService;
|
|
|
|
protected function setUp()
|
|
{
|
|
$this->entityService = $this->prophesize(ArticleService::class);
|
|
$this->entityService->willImplement(EntityServiceInterface::class);
|
|
$this->entityService->delete(1)->willReturn(true);
|
|
$this->entityService->delete(10)->willReturn(false);
|
|
}
|
|
|
|
public function testCanDelete()
|
|
{
|
|
$page = new DeleteAction($this->entityService->reveal());
|
|
$request = new ServerRequest();
|
|
$response = $page($request->withAttribute('id', 1), new Response(), function () {
|
|
|
|
});
|
|
|
|
$this->assertTrue($response instanceof Response);
|
|
$this->assertEquals('true', $response->getBody()->getContents());
|
|
}
|
|
|
|
public function testCantDelete()
|
|
{
|
|
$page = new DeleteAction($this->entityService->reveal());
|
|
$request = new ServerRequest();
|
|
$response = $page($request->withAttribute('id', 10), new Response(), function () {
|
|
|
|
});
|
|
|
|
$this->assertTrue($response instanceof Response);
|
|
$this->assertEquals('false', $response->getBody()->getContents());
|
|
}
|
|
}
|