Removed duplicated code during CLI command tests

This commit is contained in:
Alejandro Celaya
2021-04-08 13:42:56 +02:00
parent 1f8994ca8b
commit 86230d9bf3
16 changed files with 49 additions and 123 deletions

View File

@@ -5,17 +5,16 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Api; namespace ShlinkioTest\Shlink\CLI\Command\Api;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand; use Shlinkio\Shlink\CLI\Command\Api\DisableKeyCommand;
use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; use Shlinkio\Shlink\Common\Exception\InvalidArgumentException;
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class DisableKeyCommandTest extends TestCase class DisableKeyCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $apiKeyService; private ObjectProphecy $apiKeyService;
@@ -23,10 +22,7 @@ class DisableKeyCommandTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class);
$command = new DisableKeyCommand($this->apiKeyService->reveal()); $this->commandTester = $this->testerForCommand(new DisableKeyCommand($this->apiKeyService->reveal()));
$app = new Application();
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -7,34 +7,30 @@ namespace ShlinkioTest\Shlink\CLI\Command\Api;
use Cake\Chronos\Chronos; use Cake\Chronos\Chronos;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\ApiKey\RoleResolverInterface; use Shlinkio\Shlink\CLI\ApiKey\RoleResolverInterface;
use Shlinkio\Shlink\CLI\Command\Api\GenerateKeyCommand; use Shlinkio\Shlink\CLI\Command\Api\GenerateKeyCommand;
use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Entity\ApiKey;
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; 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\Input\InputInterface;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class GenerateKeyCommandTest extends TestCase class GenerateKeyCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $apiKeyService; private ObjectProphecy $apiKeyService;
private ObjectProphecy $roleResolver;
public function setUp(): void public function setUp(): void
{ {
$this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class);
$this->roleResolver = $this->prophesize(RoleResolverInterface::class); $roleResolver = $this->prophesize(RoleResolverInterface::class);
$this->roleResolver->determineRoles(Argument::type(InputInterface::class))->willReturn([]); $roleResolver->determineRoles(Argument::type(InputInterface::class))->willReturn([]);
$command = new GenerateKeyCommand($this->apiKeyService->reveal(), $this->roleResolver->reveal()); $command = new GenerateKeyCommand($this->apiKeyService->reveal(), $roleResolver->reveal());
$app = new Application(); $this->commandTester = $this->testerForCommand($command);
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -5,7 +5,6 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Api; namespace ShlinkioTest\Shlink\CLI\Command\Api;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand; use Shlinkio\Shlink\CLI\Command\Api\ListKeysCommand;
use Shlinkio\Shlink\Core\Entity\Domain; 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\ApiKey\Model\RoleDefinition;
use Shlinkio\Shlink\Rest\Entity\ApiKey; use Shlinkio\Shlink\Rest\Entity\ApiKey;
use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface; use Shlinkio\Shlink\Rest\Service\ApiKeyServiceInterface;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class ListKeysCommandTest extends TestCase class ListKeysCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $apiKeyService; private ObjectProphecy $apiKeyService;
@@ -26,10 +25,7 @@ class ListKeysCommandTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class); $this->apiKeyService = $this->prophesize(ApiKeyServiceInterface::class);
$command = new ListKeysCommand($this->apiKeyService->reveal()); $this->commandTester = $this->testerForCommand(new ListKeysCommand($this->apiKeyService->reveal()));
$app = new Application();
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** /**

View File

@@ -9,11 +9,10 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\AbstractSchemaManager;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Db\CreateDatabaseCommand; use Shlinkio\Shlink\CLI\Command\Db\CreateDatabaseCommand;
use Shlinkio\Shlink\CLI\Util\ProcessRunnerInterface; 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\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Lock\LockFactory; use Symfony\Component\Lock\LockFactory;
@@ -22,7 +21,7 @@ use Symfony\Component\Process\PhpExecutableFinder;
class CreateDatabaseCommandTest extends TestCase class CreateDatabaseCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $processHelper; private ObjectProphecy $processHelper;
@@ -59,10 +58,8 @@ class CreateDatabaseCommandTest extends TestCase
$this->regularConn->reveal(), $this->regularConn->reveal(),
$noDbNameConn->reveal(), $noDbNameConn->reveal(),
); );
$app = new Application();
$app->add($command);
$this->commandTester = new CommandTester($command); $this->commandTester = $this->testerForCommand($command);
} }
/** @test */ /** @test */

View File

@@ -6,11 +6,10 @@ namespace ShlinkioTest\Shlink\CLI\Command\Db;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Db\MigrateDatabaseCommand; use Shlinkio\Shlink\CLI\Command\Db\MigrateDatabaseCommand;
use Shlinkio\Shlink\CLI\Util\ProcessRunnerInterface; 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\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Lock\LockFactory; use Symfony\Component\Lock\LockFactory;
@@ -19,7 +18,7 @@ use Symfony\Component\Process\PhpExecutableFinder;
class MigrateDatabaseCommandTest extends TestCase class MigrateDatabaseCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $processHelper; private ObjectProphecy $processHelper;
@@ -43,10 +42,7 @@ class MigrateDatabaseCommandTest extends TestCase
$this->processHelper->reveal(), $this->processHelper->reveal(),
$phpExecutableFinder->reveal(), $phpExecutableFinder->reveal(),
); );
$app = new Application(); $this->commandTester = $this->testerForCommand($command);
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -5,18 +5,17 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Domain; namespace ShlinkioTest\Shlink\CLI\Command\Domain;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Domain\ListDomainsCommand; use Shlinkio\Shlink\CLI\Command\Domain\ListDomainsCommand;
use Shlinkio\Shlink\CLI\Util\ExitCodes; use Shlinkio\Shlink\CLI\Util\ExitCodes;
use Shlinkio\Shlink\Core\Domain\DomainServiceInterface; use Shlinkio\Shlink\Core\Domain\DomainServiceInterface;
use Shlinkio\Shlink\Core\Domain\Model\DomainItem; use Shlinkio\Shlink\Core\Domain\Model\DomainItem;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class ListDomainsCommandTest extends TestCase class ListDomainsCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $domainService; private ObjectProphecy $domainService;
@@ -24,12 +23,7 @@ class ListDomainsCommandTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->domainService = $this->prophesize(DomainServiceInterface::class); $this->domainService = $this->prophesize(DomainServiceInterface::class);
$this->commandTester = $this->testerForCommand(new ListDomainsCommand($this->domainService->reveal()));
$command = new ListDomainsCommand($this->domainService->reveal());
$app = new Application();
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -6,13 +6,12 @@ namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\ShortUrl\DeleteShortUrlCommand; use Shlinkio\Shlink\CLI\Command\ShortUrl\DeleteShortUrlCommand;
use Shlinkio\Shlink\Core\Exception; use Shlinkio\Shlink\Core\Exception;
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface; use Shlinkio\Shlink\Core\Service\ShortUrl\DeleteShortUrlServiceInterface;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use function array_pop; use function array_pop;
@@ -22,7 +21,7 @@ use const PHP_EOL;
class DeleteShortUrlCommandTest extends TestCase class DeleteShortUrlCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $service; private ObjectProphecy $service;
@@ -30,12 +29,7 @@ class DeleteShortUrlCommandTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->service = $this->prophesize(DeleteShortUrlServiceInterface::class); $this->service = $this->prophesize(DeleteShortUrlServiceInterface::class);
$this->commandTester = $this->testerForCommand(new DeleteShortUrlCommand($this->service->reveal()));
$command = new DeleteShortUrlCommand($this->service->reveal());
$app = new Application();
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -7,7 +7,6 @@ namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl;
use PHPUnit\Framework\Assert; use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\ShortUrl\GenerateShortUrlCommand; use Shlinkio\Shlink\CLI\Command\ShortUrl\GenerateShortUrlCommand;
use Shlinkio\Shlink\CLI\Util\ExitCodes; 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\Model\ShortUrlMeta;
use Shlinkio\Shlink\Core\Service\UrlShortener; use Shlinkio\Shlink\Core\Service\UrlShortener;
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifierInterface;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class GenerateShortUrlCommandTest extends TestCase class GenerateShortUrlCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $urlShortener; private ObjectProphecy $urlShortener;
@@ -35,9 +34,7 @@ class GenerateShortUrlCommandTest extends TestCase
$this->stringifier->stringify(Argument::type(ShortUrl::class))->willReturn(''); $this->stringifier->stringify(Argument::type(ShortUrl::class))->willReturn('');
$command = new GenerateShortUrlCommand($this->urlShortener->reveal(), $this->stringifier->reveal(), 5); $command = new GenerateShortUrlCommand($this->urlShortener->reveal(), $this->stringifier->reveal(), 5);
$app = new Application(); $this->commandTester = $this->testerForCommand($command);
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -8,7 +8,6 @@ use Cake\Chronos\Chronos;
use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Adapter\ArrayAdapter;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\ShortUrl\GetVisitsCommand; use Shlinkio\Shlink\CLI\Command\ShortUrl\GetVisitsCommand;
use Shlinkio\Shlink\Common\Paginator\Paginator; 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\Model\VisitsParams;
use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface; use Shlinkio\Shlink\Core\Visit\VisitsStatsHelperInterface;
use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use function sprintf; use function sprintf;
class GetVisitsCommandTest extends TestCase class GetVisitsCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $visitsHelper; private ObjectProphecy $visitsHelper;
@@ -37,9 +35,7 @@ class GetVisitsCommandTest extends TestCase
{ {
$this->visitsHelper = $this->prophesize(VisitsStatsHelperInterface::class); $this->visitsHelper = $this->prophesize(VisitsStatsHelperInterface::class);
$command = new GetVisitsCommand($this->visitsHelper->reveal()); $command = new GetVisitsCommand($this->visitsHelper->reveal());
$app = new Application(); $this->commandTester = $this->testerForCommand($command);
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -8,7 +8,6 @@ use Cake\Chronos\Chronos;
use Pagerfanta\Adapter\ArrayAdapter; use Pagerfanta\Adapter\ArrayAdapter;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\Argument; use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\ShortUrl\ListShortUrlsCommand; use Shlinkio\Shlink\CLI\Command\ShortUrl\ListShortUrlsCommand;
use Shlinkio\Shlink\Common\Paginator\Paginator; 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\Service\ShortUrlServiceInterface;
use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier; use Shlinkio\Shlink\Core\ShortUrl\Helper\ShortUrlStringifier;
use Shlinkio\Shlink\Core\ShortUrl\Transformer\ShortUrlDataTransformer; use Shlinkio\Shlink\Core\ShortUrl\Transformer\ShortUrlDataTransformer;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use function explode; use function explode;
class ListShortUrlsCommandTest extends TestCase class ListShortUrlsCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $shortUrlService; private ObjectProphecy $shortUrlService;
@@ -32,12 +31,10 @@ class ListShortUrlsCommandTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class); $this->shortUrlService = $this->prophesize(ShortUrlServiceInterface::class);
$app = new Application();
$command = new ListShortUrlsCommand($this->shortUrlService->reveal(), new ShortUrlDataTransformer( $command = new ListShortUrlsCommand($this->shortUrlService->reveal(), new ShortUrlDataTransformer(
new ShortUrlStringifier([]), new ShortUrlStringifier([]),
)); ));
$app->add($command); $this->commandTester = $this->testerForCommand($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -5,14 +5,13 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl; namespace ShlinkioTest\Shlink\CLI\Command\ShortUrl;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\ShortUrl\ResolveUrlCommand; use Shlinkio\Shlink\CLI\Command\ShortUrl\ResolveUrlCommand;
use Shlinkio\Shlink\Core\Entity\ShortUrl; use Shlinkio\Shlink\Core\Entity\ShortUrl;
use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException; use Shlinkio\Shlink\Core\Exception\ShortUrlNotFoundException;
use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier; use Shlinkio\Shlink\Core\Model\ShortUrlIdentifier;
use Shlinkio\Shlink\Core\Service\ShortUrl\ShortUrlResolverInterface; use Shlinkio\Shlink\Core\Service\ShortUrl\ShortUrlResolverInterface;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use function sprintf; use function sprintf;
@@ -21,7 +20,7 @@ use const PHP_EOL;
class ResolveUrlCommandTest extends TestCase class ResolveUrlCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $urlResolver; private ObjectProphecy $urlResolver;
@@ -29,11 +28,7 @@ class ResolveUrlCommandTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->urlResolver = $this->prophesize(ShortUrlResolverInterface::class); $this->urlResolver = $this->prophesize(ShortUrlResolverInterface::class);
$command = new ResolveUrlCommand($this->urlResolver->reveal()); $this->commandTester = $this->testerForCommand(new ResolveUrlCommand($this->urlResolver->reveal()));
$app = new Application();
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -6,16 +6,15 @@ namespace ShlinkioTest\Shlink\CLI\Command\Tag;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Tag\CreateTagCommand; use Shlinkio\Shlink\CLI\Command\Tag\CreateTagCommand;
use Shlinkio\Shlink\Core\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class CreateTagCommandTest extends TestCase class CreateTagCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $tagService; private ObjectProphecy $tagService;
@@ -23,12 +22,7 @@ class CreateTagCommandTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->tagService = $this->prophesize(TagServiceInterface::class); $this->tagService = $this->prophesize(TagServiceInterface::class);
$this->commandTester = $this->testerForCommand(new CreateTagCommand($this->tagService->reveal()));
$command = new CreateTagCommand($this->tagService->reveal());
$app = new Application();
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -5,16 +5,15 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Tag; namespace ShlinkioTest\Shlink\CLI\Command\Tag;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Tag\DeleteTagsCommand; use Shlinkio\Shlink\CLI\Command\Tag\DeleteTagsCommand;
use Shlinkio\Shlink\Core\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class DeleteTagsCommandTest extends TestCase class DeleteTagsCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $tagService; private ObjectProphecy $tagService;
@@ -22,12 +21,7 @@ class DeleteTagsCommandTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->tagService = $this->prophesize(TagServiceInterface::class); $this->tagService = $this->prophesize(TagServiceInterface::class);
$this->commandTester = $this->testerForCommand(new DeleteTagsCommand($this->tagService->reveal()));
$command = new DeleteTagsCommand($this->tagService->reveal());
$app = new Application();
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -5,18 +5,17 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Tag; namespace ShlinkioTest\Shlink\CLI\Command\Tag;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Tag\ListTagsCommand; use Shlinkio\Shlink\CLI\Command\Tag\ListTagsCommand;
use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Tag\Model\TagInfo; use Shlinkio\Shlink\Core\Tag\Model\TagInfo;
use Shlinkio\Shlink\Core\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class ListTagsCommandTest extends TestCase class ListTagsCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $tagService; private ObjectProphecy $tagService;
@@ -24,12 +23,7 @@ class ListTagsCommandTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->tagService = $this->prophesize(TagServiceInterface::class); $this->tagService = $this->prophesize(TagServiceInterface::class);
$this->commandTester = $this->testerForCommand(new ListTagsCommand($this->tagService->reveal()));
$command = new ListTagsCommand($this->tagService->reveal());
$app = new Application();
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -5,19 +5,18 @@ declare(strict_types=1);
namespace ShlinkioTest\Shlink\CLI\Command\Tag; namespace ShlinkioTest\Shlink\CLI\Command\Tag;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy; use Prophecy\Prophecy\ObjectProphecy;
use Shlinkio\Shlink\CLI\Command\Tag\RenameTagCommand; use Shlinkio\Shlink\CLI\Command\Tag\RenameTagCommand;
use Shlinkio\Shlink\Core\Entity\Tag; use Shlinkio\Shlink\Core\Entity\Tag;
use Shlinkio\Shlink\Core\Exception\TagNotFoundException; use Shlinkio\Shlink\Core\Exception\TagNotFoundException;
use Shlinkio\Shlink\Core\Tag\Model\TagRenaming; use Shlinkio\Shlink\Core\Tag\Model\TagRenaming;
use Shlinkio\Shlink\Core\Tag\TagServiceInterface; use Shlinkio\Shlink\Core\Tag\TagServiceInterface;
use Symfony\Component\Console\Application; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
class RenameTagCommandTest extends TestCase class RenameTagCommandTest extends TestCase
{ {
use ProphecyTrait; use CliTestUtilsTrait;
private CommandTester $commandTester; private CommandTester $commandTester;
private ObjectProphecy $tagService; private ObjectProphecy $tagService;
@@ -25,12 +24,7 @@ class RenameTagCommandTest extends TestCase
public function setUp(): void public function setUp(): void
{ {
$this->tagService = $this->prophesize(TagServiceInterface::class); $this->tagService = $this->prophesize(TagServiceInterface::class);
$this->commandTester = $this->testerForCommand(new RenameTagCommand($this->tagService->reveal()));
$command = new RenameTagCommand($this->tagService->reveal());
$app = new Application();
$app->add($command);
$this->commandTester = new CommandTester($command);
} }
/** @test */ /** @test */

View File

@@ -21,7 +21,6 @@ use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException;
use Shlinkio\Shlink\IpGeolocation\Model\Location; use Shlinkio\Shlink\IpGeolocation\Model\Location;
use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface; use Shlinkio\Shlink\IpGeolocation\Resolver\IpLocationResolverInterface;
use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait; use ShlinkioTest\Shlink\CLI\CliTestUtilsTrait;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Exception\RuntimeException; use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
@@ -58,14 +57,11 @@ class LocateVisitsCommandTest extends TestCase
$this->ipResolver->reveal(), $this->ipResolver->reveal(),
$locker->reveal(), $locker->reveal(),
); );
$app = new Application();
$app->add($command);
$this->downloadDbCommand = $this->createCommandMock(DownloadGeoLiteDbCommand::NAME); $this->downloadDbCommand = $this->createCommandMock(DownloadGeoLiteDbCommand::NAME);
$this->downloadDbCommand->run(Argument::cetera())->willReturn(ExitCodes::EXIT_SUCCESS); $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());
} }
/** /**