ListTagsCommandTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. declare(strict_types=1);
  3. namespace ShlinkioTest\Shlink\CLI\Command\Tag;
  4. use PHPUnit\Framework\TestCase;
  5. use Prophecy\Prophecy\ObjectProphecy;
  6. use Shlinkio\Shlink\CLI\Command\Tag\ListTagsCommand;
  7. use Shlinkio\Shlink\Core\Entity\Tag;
  8. use Shlinkio\Shlink\Core\Service\Tag\TagServiceInterface;
  9. use Symfony\Component\Console\Application;
  10. use Symfony\Component\Console\Tester\CommandTester;
  11. class ListTagsCommandTest extends TestCase
  12. {
  13. /** @var ListTagsCommand */
  14. private $command;
  15. /** @var CommandTester */
  16. private $commandTester;
  17. /** @var ObjectProphecy */
  18. private $tagService;
  19. public function setUp(): void
  20. {
  21. $this->tagService = $this->prophesize(TagServiceInterface::class);
  22. $command = new ListTagsCommand($this->tagService->reveal());
  23. $app = new Application();
  24. $app->add($command);
  25. $this->commandTester = new CommandTester($command);
  26. }
  27. /** @test */
  28. public function noTagsPrintsEmptyMessage()
  29. {
  30. $listTags = $this->tagService->listTags()->willReturn([]);
  31. $this->commandTester->execute([]);
  32. $output = $this->commandTester->getDisplay();
  33. $this->assertStringContainsString('No tags yet', $output);
  34. $listTags->shouldHaveBeenCalled();
  35. }
  36. /** @test */
  37. public function listOfTagsIsPrinted()
  38. {
  39. $listTags = $this->tagService->listTags()->willReturn([
  40. new Tag('foo'),
  41. new Tag('bar'),
  42. ]);
  43. $this->commandTester->execute([]);
  44. $output = $this->commandTester->getDisplay();
  45. $this->assertStringContainsString('foo', $output);
  46. $this->assertStringContainsString('bar', $output);
  47. $listTags->shouldHaveBeenCalled();
  48. }
  49. }