mirror of
https://github.com/shlinkio/shlink.git
synced 2025-01-11 00:22:04 -06:00
Created CreateTagsActiontest
This commit is contained in:
parent
563e654b99
commit
575509c45b
58
module/Rest/test/Action/Tag/CreateTagsActionTest.php
Normal file
58
module/Rest/test/Action/Tag/CreateTagsActionTest.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace ShlinkioTest\Shlink\Rest\Action\Tag;
|
||||||
|
|
||||||
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
|
use Interop\Http\ServerMiddleware\DelegateInterface;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
use Prophecy\Prophecy\MethodProphecy;
|
||||||
|
use Prophecy\Prophecy\ObjectProphecy;
|
||||||
|
use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
|
||||||
|
use Shlinkio\Shlink\Rest\Action\Tag\CreateTagsAction;
|
||||||
|
use Zend\Diactoros\ServerRequestFactory;
|
||||||
|
|
||||||
|
class CreateTagsActionTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var CreateTagsAction
|
||||||
|
*/
|
||||||
|
private $action;
|
||||||
|
/**
|
||||||
|
* @var ObjectProphecy
|
||||||
|
*/
|
||||||
|
private $tagService;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->tagService = $this->prophesize(TagServiceInterface::class);
|
||||||
|
$this->action = new CreateTagsAction($this->tagService->reveal());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @dataProvider provideTags
|
||||||
|
* @param array|null $tags
|
||||||
|
*/
|
||||||
|
public function processDelegatesIntoService($tags)
|
||||||
|
{
|
||||||
|
$request = ServerRequestFactory::fromGlobals()->withParsedBody(['tags' => $tags]);
|
||||||
|
/** @var MethodProphecy $deleteTags */
|
||||||
|
$deleteTags = $this->tagService->createTags($tags ?: [])->willReturn(new ArrayCollection());
|
||||||
|
|
||||||
|
$response = $this->action->process($request, $this->prophesize(DelegateInterface::class)->reveal());
|
||||||
|
|
||||||
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
$deleteTags->shouldHaveBeenCalled();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideTags()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[['foo', 'bar', 'baz']],
|
||||||
|
[['some', 'thing']],
|
||||||
|
[null],
|
||||||
|
[[]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user