Created EditTagsActiontest

This commit is contained in:
Alejandro Celaya 2016-08-21 18:06:34 +02:00
parent d7b18776f1
commit 3376725152

View File

@ -0,0 +1,76 @@
<?php
namespace ShlinkioTest\Shlink\Rest\Action;
use PHPUnit_Framework_TestCase as TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\InvalidShortCodeException;
use Shlinkio\Shlink\Core\Service\ShortUrlService;
use Shlinkio\Shlink\Rest\Action\EditTagsAction;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;
use Zend\I18n\Translator\Translator;
class EditTagsActionTest extends TestCase
{
/**
* @var EditTagsAction
*/
protected $action;
/**
* @var ObjectProphecy
*/
private $shortUrlService;
public function setUp()
{
$this->shortUrlService = $this->prophesize(ShortUrlService::class);
$this->action = new EditTagsAction($this->shortUrlService->reveal(), Translator::factory([]));
}
/**
* @test
*/
public function notProvidingTagsReturnsError()
{
$response = $this->action->__invoke(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123'),
new Response()
);
$this->assertEquals(400, $response->getStatusCode());
}
/**
* @test
*/
public function anInvalidShortCodeReturnsNotFound()
{
$shortCode = 'abc123';
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willThrow(InvalidShortCodeException::class)
->shouldBeCalledTimes(1);
$response = $this->action->__invoke(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')
->withParsedBody(['tags' => []]),
new Response()
);
$this->assertEquals(404, $response->getStatusCode());
}
/**
* @test
*/
public function tagsListIsReturnedIfCorrectShortCodeIsProvided()
{
$shortCode = 'abc123';
$this->shortUrlService->setTagsByShortCode($shortCode, [])->willReturn(new ShortUrl())
->shouldBeCalledTimes(1);
$response = $this->action->__invoke(
ServerRequestFactory::fromGlobals()->withAttribute('shortCode', 'abc123')
->withParsedBody(['tags' => []]),
new Response()
);
$this->assertEquals(200, $response->getStatusCode());
}
}