Created ListTagsActionTest

This commit is contained in:
Alejandro Celaya 2017-07-07 13:28:58 +02:00
parent 95ec7e0afa
commit 5c7962966d
4 changed files with 55 additions and 4 deletions

View File

@ -1,6 +1,4 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Factory;
use PHPUnit\Framework\TestCase;

View File

@ -20,6 +20,11 @@ class Tag extends AbstractEntity implements \JsonSerializable
*/
protected $name;
public function __construct($name = null)
{
$this->name = $name;
}
/**
* @return string
*/

View File

@ -1,6 +1,4 @@
<?php
declare(strict_types=1);
namespace ShlinkioTest\Shlink\Core\Service\Tag;
use Doctrine\ORM\EntityManagerInterface;

View File

@ -0,0 +1,50 @@
<?php
namespace ShlinkioTest\Shlink\Rest\Action;
use Interop\Http\ServerMiddleware\DelegateInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\MethodProphecy;
use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
use Shlinkio\Shlink\Rest\Action\ListTagsAction;
use Zend\Diactoros\ServerRequestFactory;
class ListTagsActionTest extends TestCase
{
/**
* @var ListTagsAction
*/
private $action;
/**
* @var ObjectProphecy
*/
private $tagService;
public function setUp()
{
$this->tagService = $this->prophesize(TagServiceInterface::class);
$this->action = new ListTagsAction($this->tagService->reveal());
}
/**
* @test
*/
public function returnsDataFromService()
{
/** @var MethodProphecy $listTags */
$listTags = $this->tagService->listTags()->willReturn([new Tag('foo'), new Tag('bar')]);
$resp = $this->action->process(
ServerRequestFactory::fromGlobals(),
$this->prophesize(DelegateInterface::class)->reveal()
);
$this->assertEquals([
'tags' => [
'data' => ['foo', 'bar'],
],
], \json_decode((string) $resp->getBody(), true));
$listTags->shouldHaveBeenCalled();
}
}