From 86230d9bf3833d7afe3463166944b9c77b73b1e0 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Thu, 8 Apr 2021 13:42:56 +0200 Subject: [PATCH] Removed duplicated code during CLI command tests --- .../test/Command/Api/DisableKeyCommandTest.php | 10 +++------- .../test/Command/Api/GenerateKeyCommandTest.php | 16 ++++++---------- .../CLI/test/Command/Api/ListKeysCommandTest.php | 10 +++------- .../Command/Db/CreateDatabaseCommandTest.php | 9 +++------ .../Command/Db/MigrateDatabaseCommandTest.php | 10 +++------- .../Command/Domain/ListDomainsCommandTest.php | 12 +++--------- .../ShortUrl/DeleteShortUrlCommandTest.php | 12 +++--------- .../ShortUrl/GenerateShortUrlCommandTest.php | 9 +++------ .../Command/ShortUrl/GetVisitsCommandTest.php | 10 +++------- .../ShortUrl/ListShortUrlsCommandTest.php | 9 +++------ .../Command/ShortUrl/ResolveUrlCommandTest.php | 11 +++-------- .../test/Command/Tag/CreateTagCommandTest.php | 12 +++--------- .../test/Command/Tag/DeleteTagsCommandTest.php | 12 +++--------- .../CLI/test/Command/Tag/ListTagsCommandTest.php | 12 +++--------- .../test/Command/Tag/RenameTagCommandTest.php | 12 +++--------- .../Command/Visit/LocateVisitsCommandTest.php | 6 +----- 16 files changed, 49 insertions(+), 123 deletions(-) diff --git a/module/CLI/test/Command/Api/DisableKeyCommandTest.php b/module/CLI/test/Command/Api/DisableKeyCommandTest.php index 49835f85..90942dc9 100644 --- a/module/CLI/test/Command/Api/DisableKeyCommandTest.php +++ b/module/CLI/test/Command/Api/DisableKeyCommandTest.php @@ -5,17 +5,16 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\Api; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand; use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; class DisableKeyCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $apiKeyService; @@ -23,10 +22,7 @@ class DisableKeyCommandTest extends TestCase public function setUp(): void { $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); - $command = new DisableKeyCommand($this->apiKeyService->reveal()); - $app = new Application(); - $app->add($command); - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand(new DisableKeyCommand($this->apiKeyService->reveal())); } /** @test */ diff --git a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php index 5c0c3c8a..e5c543d5 100644 --- a/module/CLI/test/Command/Api/GenerateKeyCommandTest.php +++ b/module/CLI/test/Command/Api/GenerateKeyCommandTest.php @@ -7,34 +7,30 @@ namespace ShlinkioTest\Shlink\CLI\Command\Api; use Cake\Chronos\Chronos; use PHPUnit\Framework\TestCase; use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\ApiKey\RoleResolverInterface; use Shlinkio\Shlink\CLI\Command\Api\GenerateKeyCommand; use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Tester\CommandTester; class GenerateKeyCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $apiKeyService; - private ObjectProphecy $roleResolver; public function setUp(): void { $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); - $this->roleResolver = $this->prophesize(RoleResolverInterface::class); - $this->roleResolver->determineRoles(Argument::type(InputInterface::class))->willReturn([]); + $roleResolver = $this->prophesize(RoleResolverInterface::class); + $roleResolver->determineRoles(Argument::type(InputInterface::class))->willReturn([]); - $command = new GenerateKeyCommand($this->apiKeyService->reveal(), $this->roleResolver->reveal()); - $app = new Application(); - $app->add($command); - $this->commandTester = new CommandTester($command); + $command = new GenerateKeyCommand($this->apiKeyService->reveal(), $roleResolver->reveal()); + $this->commandTester = $this->testerForCommand($command); } /** @test */ diff --git a/module/CLI/test/Command/Api/ListKeysCommandTest.php b/module/CLI/test/Command/Api/ListKeysCommandTest.php index fa6816d2..fc845ff7 100644 --- a/module/CLI/test/Command/Api/ListKeysCommandTest.php +++ b/module/CLI/test/Command/Api/ListKeysCommandTest.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\Api; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand; use Shlinkio\Shlink\Core\Entity\Domain; @@ -13,12 +12,12 @@ use Shlinkio\Shlink\Rest\ApiKey\Model\ApiKeyMeta; use Shlinkio\Shlink\Rest\ApiKey\Model\RoleDefinition; use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; class ListKeysCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $apiKeyService; @@ -26,10 +25,7 @@ class ListKeysCommandTest extends TestCase public function setUp(): void { $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); - $command = new ListKeysCommand($this->apiKeyService->reveal()); - $app = new Application(); - $app->add($command); - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand(new ListKeysCommand($this->apiKeyService->reveal())); } /** diff --git a/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php b/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php index db9dcf66..70d4d5eb 100644 --- a/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php +++ b/module/CLI/test/Command/Db/CreateDatabaseCommandTest.php @@ -9,11 +9,10 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; use PHPUnit\Framework\TestCase; use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Db\CreateDatabaseCommand; use Shlinkio\Shlink\CLI\Util\ProcessRunnerInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Lock\LockFactory; @@ -22,7 +21,7 @@ use Symfony\Component\Process\PhpExecutableFinder; class CreateDatabaseCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $processHelper; @@ -59,10 +58,8 @@ class CreateDatabaseCommandTest extends TestCase $this->regularConn->reveal(), $noDbNameConn->reveal(), ); - $app = new Application(); - $app->add($command); - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand($command); } /** @test */ diff --git a/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php b/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php index d25f44f2..d301f55e 100644 --- a/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php +++ b/module/CLI/test/Command/Db/MigrateDatabaseCommandTest.php @@ -6,11 +6,10 @@ namespace ShlinkioTest\Shlink\CLI\Command\Db; use PHPUnit\Framework\TestCase; use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Db\MigrateDatabaseCommand; use Shlinkio\Shlink\CLI\Util\ProcessRunnerInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Lock\LockFactory; @@ -19,7 +18,7 @@ use Symfony\Component\Process\PhpExecutableFinder; class MigrateDatabaseCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $processHelper; @@ -43,10 +42,7 @@ class MigrateDatabaseCommandTest extends TestCase $this->processHelper->reveal(), $phpExecutableFinder->reveal(), ); - $app = new Application(); - $app->add($command); - - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand($command); } /** @test */ diff --git a/module/CLI/test/Command/Domain/ListDomainsCommandTest.php b/module/CLI/test/Command/Domain/ListDomainsCommandTest.php index a0f79448..04f7eb5d 100644 --- a/module/CLI/test/Command/Domain/ListDomainsCommandTest.php +++ b/module/CLI/test/Command/Domain/ListDomainsCommandTest.php @@ -5,18 +5,17 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\Domain; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Domain\ListDomainsCommand; use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; use Shlinkio\Shlink\Core\Domain\Model\DomainItem; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; class ListDomainsCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $domainService; @@ -24,12 +23,7 @@ class ListDomainsCommandTest extends TestCase public function setUp(): void { $this->domainService = $this->prophesize(DomainServiceInterface::class); - - $command = new ListDomainsCommand($this->domainService->reveal()); - $app = new Application(); - $app->add($command); - - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand(new ListDomainsCommand($this->domainService->reveal())); } /** @test */ diff --git a/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php index 83fd792d..a6b6fc78 100644 --- a/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/DeleteShortUrlCommandTest.php @@ -6,13 +6,12 @@ namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl; use PHPUnit\Framework\TestCase; use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\ShortUrl\DeleteShortUrlCommand; use Shlinkio\Shlink\Core\Exception; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; use function array_pop; @@ -22,7 +21,7 @@ use const PHP_EOL; class DeleteShortUrlCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $service; @@ -30,12 +29,7 @@ class DeleteShortUrlCommandTest extends TestCase public function setUp(): void { $this->service = $this->prophesize(DeleteShortUrlServiceInterface::class); - - $command = new DeleteShortUrlCommand($this->service->reveal()); - $app = new Application(); - $app->add($command); - - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand(new DeleteShortUrlCommand($this->service->reveal())); } /** @test */ diff --git a/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php index 25953d38..19767dc7 100644 --- a/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GenerateShortUrlCommandTest.php @@ -7,7 +7,6 @@ namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl; use PHPUnit\Framework\Assert; use PHPUnit\Framework\TestCase; use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\ShortUrl\GenerateShortUrlCommand; use Shlinkio\Shlink\CLI\Util\ExitCodes; @@ -17,12 +16,12 @@ use Shlinkio\Shlink\Core\Exception\NonUniqueSlugException; use Shlinkio\Shlink\Core\Model\ShortUrlMeta; use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; class GenerateShortUrlCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $urlShortener; @@ -35,9 +34,7 @@ class GenerateShortUrlCommandTest extends TestCase $this->stringifier->stringify(Argument::type(ShortUrl::class))->willReturn(''); $command = new GenerateShortUrlCommand($this->urlShortener->reveal(), $this->stringifier->reveal(), 5); - $app = new Application(); - $app->add($command); - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand($command); } /** @test */ diff --git a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php index d25d5763..42f008be 100644 --- a/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/GetVisitsCommandTest.php @@ -8,7 +8,6 @@ use Cake\Chronos\Chronos; use Pagerfanta\Adapter\ArrayAdapter; use PHPUnit\Framework\TestCase; use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\ShortUrl\GetVisitsCommand; use Shlinkio\Shlink\Common\Paginator\Paginator; @@ -21,14 +20,13 @@ use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Model\VisitsParams; use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface; use Shlinkio\Shlink\IpGeolocation\Model\Location; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; - use function sprintf; class GetVisitsCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $visitsHelper; @@ -37,9 +35,7 @@ class GetVisitsCommandTest extends TestCase { $this->visitsHelper = $this->prophesize(VisitsStatsHelperInterface::class); $command = new GetVisitsCommand($this->visitsHelper->reveal()); - $app = new Application(); - $app->add($command); - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand($command); } /** @test */ diff --git a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php index 3f2b38b1..08519b62 100644 --- a/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ListShortUrlsCommandTest.php @@ -8,7 +8,6 @@ use Cake\Chronos\Chronos; use Pagerfanta\Adapter\ArrayAdapter; use PHPUnit\Framework\TestCase; use Prophecy\Argument; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\ShortUrl\ListShortUrlsCommand; use Shlinkio\Shlink\Common\Paginator\Paginator; @@ -17,14 +16,14 @@ use Shlinkio\Shlink\Core\Model\ShortUrlsParams; use Shlinkio\Shlink\Core\Service\ShortUrlServiceInterface; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier; use Shlinkio\Shlink\Core\ShortUrl\Transformer\ShortUrlDataTransformer; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; use function explode; class ListShortUrlsCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $shortUrlService; @@ -32,12 +31,10 @@ class ListShortUrlsCommandTest extends TestCase public function setUp(): void { $this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class); - $app = new Application(); $command = new ListShortUrlsCommand($this->shortUrlService->reveal(), new ShortUrlDataTransformer( new ShortUrlStringifier([]), )); - $app->add($command); - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand($command); } /** @test */ diff --git a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php index f0025b65..2a816207 100644 --- a/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php +++ b/module/CLI/test/Command/ShortUrl/ResolveUrlCommandTest.php @@ -5,14 +5,13 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\ShortUrl\ResolveUrlCommand; use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Service\ShortUrl\ShortUrlResolverInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; use function sprintf; @@ -21,7 +20,7 @@ use const PHP_EOL; class ResolveUrlCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $urlResolver; @@ -29,11 +28,7 @@ class ResolveUrlCommandTest extends TestCase public function setUp(): void { $this->urlResolver = $this->prophesize(ShortUrlResolverInterface::class); - $command = new ResolveUrlCommand($this->urlResolver->reveal()); - $app = new Application(); - $app->add($command); - - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand(new ResolveUrlCommand($this->urlResolver->reveal())); } /** @test */ diff --git a/module/CLI/test/Command/Tag/CreateTagCommandTest.php b/module/CLI/test/Command/Tag/CreateTagCommandTest.php index 2789c481..7062cb45 100644 --- a/module/CLI/test/Command/Tag/CreateTagCommandTest.php +++ b/module/CLI/test/Command/Tag/CreateTagCommandTest.php @@ -6,16 +6,15 @@ namespace ShlinkioTest\Shlink\CLI\Command\Tag; use Doctrine\Common\Collections\ArrayCollection; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Tag\CreateTagCommand; use Shlinkio\Shlink\Core\Tag\TagServiceInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; class CreateTagCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $tagService; @@ -23,12 +22,7 @@ class CreateTagCommandTest extends TestCase public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); - - $command = new CreateTagCommand($this->tagService->reveal()); - $app = new Application(); - $app->add($command); - - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand(new CreateTagCommand($this->tagService->reveal())); } /** @test */ diff --git a/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php index 6d3737c1..46f61814 100644 --- a/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php +++ b/module/CLI/test/Command/Tag/DeleteTagsCommandTest.php @@ -5,16 +5,15 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\Tag; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Tag\DeleteTagsCommand; use Shlinkio\Shlink\Core\Tag\TagServiceInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; class DeleteTagsCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $tagService; @@ -22,12 +21,7 @@ class DeleteTagsCommandTest extends TestCase public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); - - $command = new DeleteTagsCommand($this->tagService->reveal()); - $app = new Application(); - $app->add($command); - - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand(new DeleteTagsCommand($this->tagService->reveal())); } /** @test */ diff --git a/module/CLI/test/Command/Tag/ListTagsCommandTest.php b/module/CLI/test/Command/Tag/ListTagsCommandTest.php index 5b9e14e9..9ec42e54 100644 --- a/module/CLI/test/Command/Tag/ListTagsCommandTest.php +++ b/module/CLI/test/Command/Tag/ListTagsCommandTest.php @@ -5,18 +5,17 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\Tag; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Tag\ListTagsCommand; use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Tag\Model\TagInfo; use Shlinkio\Shlink\Core\Tag\TagServiceInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; class ListTagsCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $tagService; @@ -24,12 +23,7 @@ class ListTagsCommandTest extends TestCase public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); - - $command = new ListTagsCommand($this->tagService->reveal()); - $app = new Application(); - $app->add($command); - - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand(new ListTagsCommand($this->tagService->reveal())); } /** @test */ diff --git a/module/CLI/test/Command/Tag/RenameTagCommandTest.php b/module/CLI/test/Command/Tag/RenameTagCommandTest.php index d457c25d..3a52aba3 100644 --- a/module/CLI/test/Command/Tag/RenameTagCommandTest.php +++ b/module/CLI/test/Command/Tag/RenameTagCommandTest.php @@ -5,19 +5,18 @@ declare(strict_types=1); namespace ShlinkioTest\Shlink\CLI\Command\Tag; use PHPUnit\Framework\TestCase; -use Prophecy\PhpUnit\ProphecyTrait; use Prophecy\Prophecy\ObjectProphecy; use Shlinkio\Shlink\CLI\Command\Tag\RenameTagCommand; use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Exception\TagNotFoundException; use Shlinkio\Shlink\Core\Tag\Model\TagRenaming; use Shlinkio\Shlink\Core\Tag\TagServiceInterface; -use Symfony\Component\Console\Application; +use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use Symfony\Component\Console\Tester\CommandTester; class RenameTagCommandTest extends TestCase { - use ProphecyTrait; + use CliTestUtilsTrait; private CommandTester $commandTester; private ObjectProphecy $tagService; @@ -25,12 +24,7 @@ class RenameTagCommandTest extends TestCase public function setUp(): void { $this->tagService = $this->prophesize(TagServiceInterface::class); - - $command = new RenameTagCommand($this->tagService->reveal()); - $app = new Application(); - $app->add($command); - - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand(new RenameTagCommand($this->tagService->reveal())); } /** @test */ diff --git a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php index e7ccc9d2..6e4213f6 100644 --- a/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php +++ b/module/CLI/test/Command/Visit/LocateVisitsCommandTest.php @@ -21,7 +21,6 @@ use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException; use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; -use Symfony\Component\Console\Application; use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Tester\CommandTester; @@ -58,14 +57,11 @@ class LocateVisitsCommandTest extends TestCase $this->ipResolver->reveal(), $locker->reveal(), ); - $app = new Application(); - $app->add($command); $this->downloadDbCommand = $this->createCommandMock(DownloadGeoLiteDbCommand::NAME); $this->downloadDbCommand->run(Argument::cetera())->willReturn(ExitCodes::EXIT_SUCCESS); - $app->add($this->downloadDbCommand->reveal()); - $this->commandTester = new CommandTester($command); + $this->commandTester = $this->testerForCommand($command, $this->downloadDbCommand->reveal()); } /**