Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark console commands as final classes #944

Merged
merged 3 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ build:
analysis:
environment:
php:
version: 7.1
version: 7.2
cache:
disabled: false
directories:
Expand All @@ -16,7 +16,7 @@ build:
- phpcs-run
dependencies:
override:
- composer install --ignore-platform-reqs --no-interaction
- composer install --no-interaction

tools:
external_code_coverage:
Expand Down
18 changes: 1 addition & 17 deletions lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* The DiffCommand class is responsible for generating a migration by comparing your current database schema to
* your mapping information.
*/
class DiffCommand extends DoctrineCommand
final class DiffCommand extends DoctrineCommand
{
/** @var string */
protected static $defaultName = 'migrations:diff';
Expand All @@ -40,9 +40,6 @@ protected function configure() : void

<info>%command.full_name%</info>

You can optionally specify a <comment>--editor-cmd</comment> option to open the generated file in your favorite editor:

<info>%command.full_name% --editor-cmd=mate</info>
EOT
)
->addOption(
Expand All @@ -51,12 +48,6 @@ protected function configure() : void
InputOption::VALUE_REQUIRED,
'The namespace to use for the migration (must be in the list of configured namespaces)'
)
->addOption(
'editor-cmd',
null,
InputOption::VALUE_REQUIRED,
'Open file with this command upon creation.'
)
->addOption(
'filter-expression',
null,
Expand Down Expand Up @@ -145,13 +136,6 @@ public function execute(
throw $exception;
}

$editorCommand = $input->getOption('editor-cmd');

if ($editorCommand !== null) {
assert(is_string($editorCommand));
$this->procOpen($editorCommand, $path);
}

$output->writeln([
sprintf('Generated new migration class to "<info>%s</info>"', $path),
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use function escapeshellarg;
use function is_string;
use function proc_open;

/**
* The DoctrineCommand class provides base functionality for the other migrations commands to extend from.
Expand Down Expand Up @@ -104,9 +102,4 @@ protected function canExecute(
) : bool {
return ! $input->isInteractive() || $this->askConfirmation($question, $input, $output);
}

protected function procOpen(string $editorCommand, string $path) : void
{
proc_open($editorCommand . ' ' . escapeshellarg($path), [], $pipes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @see Doctrine\Migrations\Tools\Console\Command\RollupCommand
*/
class DumpSchemaCommand extends DoctrineCommand
final class DumpSchemaCommand extends DoctrineCommand
{
/** @var string */
protected static $defaultName = 'migrations:dump-schema';
Expand All @@ -43,12 +43,6 @@ protected function configure() : void
After dumping your schema to a migration, you can rollup your migrations using the <info>migrations:rollup</info> command.
EOT
)
->addOption(
'editor-cmd',
null,
InputOption::VALUE_OPTIONAL,
'Open file with this command upon creation.'
)
->addOption(
'formatted',
null,
Expand Down Expand Up @@ -117,13 +111,6 @@ public function execute(
$lineLength
);

$editorCommand = $input->getOption('editor-cmd');

if ($editorCommand !== null) {
assert(is_string($editorCommand));
$this->procOpen($editorCommand, $path);
}

$output->writeln([
sprintf('Dumped your schema to a new migration class at "<info>%s</info>"', $path),
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* The ExecuteCommand class is responsible for executing migration versions up or down manually.
*/
class ExecuteCommand extends DoctrineCommand
final class ExecuteCommand extends DoctrineCommand
{
/** @var string */
protected static $defaultName = 'migrations:execute';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* The GenerateCommand class is responsible for generating a blank migration class for you to modify to your needs.
*/
class GenerateCommand extends DoctrineCommand
final class GenerateCommand extends DoctrineCommand
{
/** @var string */
protected static $defaultName = 'migrations:generate';
Expand All @@ -26,12 +26,6 @@ protected function configure() : void
$this
->setAliases(['generate'])
->setDescription('Generate a blank migration class.')
->addOption(
'editor-cmd',
null,
InputOption::VALUE_OPTIONAL,
'Open file with this command upon creation.'
)
->addOption(
'namespace',
null,
Expand All @@ -43,9 +37,6 @@ protected function configure() : void

<info>%command.full_name%</info>

You can optionally specify a <comment>--editor-cmd</comment> option to open the generated file in your favorite editor:

<info>%command.full_name% --editor-cmd=mate</info>
EOT
);

Expand Down Expand Up @@ -73,13 +64,6 @@ protected function execute(InputInterface $input, OutputInterface $output) : ?in

$path = $migrationGenerator->generateMigration($fqcn);

$editorCommand = $input->getOption('editor-cmd');

if ($editorCommand !== null) {
assert(is_string($editorCommand));
$this->procOpen($editorCommand, $path);
}

$output->writeln([
sprintf('Generated new migration class to "<info>%s</info>"', $path),
'',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* The LatestCommand class is responsible for outputting what your latest version is.
*/
class LatestCommand extends DoctrineCommand
final class LatestCommand extends DoctrineCommand
{
/** @var string */
protected static $defaultName = 'migrations:latest';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* The MigrateCommand class is responsible for executing a migration from the current version to another
* version up or down. It will calculate all the migration versions that need to be executed and execute them.
*/
class MigrateCommand extends DoctrineCommand
final class MigrateCommand extends DoctrineCommand
{
/** @var string */
protected static $defaultName = 'migrations:migrate';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* The RollupCommand class is responsible for deleting all previously executed migrations from the versions table
* and marking the freshly dumped schema migration (that was created with DumpSchemaCommand) as migrated.
*/
class RollupCommand extends DoctrineCommand
final class RollupCommand extends DoctrineCommand
{
/** @var string */
protected static $defaultName = 'migrations:rollup';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* The StatusCommand class is responsible for outputting what the current state is of all your migrations. It shows
* what your current version is, how many new versions you have to execute, etc. and details about each of your migrations.
*/
class StatusCommand extends DoctrineCommand
final class StatusCommand extends DoctrineCommand
{
/** @var string */
protected static $defaultName = 'migrations:status';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class SyncMetadataCommand extends DoctrineCommand
final class SyncMetadataCommand extends DoctrineCommand
{
/** @var string */
protected static $defaultName = 'migrations:sync-metadata-storage';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* The UpToDateCommand class outputs if your database is up to date or if there are new migrations
* that need to be executed.
*/
class UpToDateCommand extends DoctrineCommand
final class UpToDateCommand extends DoctrineCommand
{
/** @var string */
protected static $defaultName = 'migrations:up-to-date';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* The VersionCommand class is responsible for manually adding and deleting migration versions from the tracking table.
*/
class VersionCommand extends DoctrineCommand
final class VersionCommand extends DoctrineCommand
{
/** @var string */
protected static $defaultName = 'migrations:version';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Doctrine\Migrations\Tools\Console\Command\DiffCommand;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Helper\HelperSet;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use function sys_get_temp_dir;
Expand All @@ -23,12 +25,15 @@ final class DiffCommandTest extends TestCase
/** @var Configuration */
private $configuration;

/** @var DiffCommand|MockObject */
/** @var DiffCommand */
private $diffCommand;

/** @var MockObject */
/** @var MockObject|DependencyFactory */
private $dependencyFactory;

/** @var MockObject|QuestionHelper */
private $questions;

public function testExecute() : void
{
$input = $this->createMock(InputInterface::class);
Expand Down Expand Up @@ -64,20 +69,11 @@ public function testExecute() : void
->with('namespace')
->willReturn('FooNs');

$input->expects(self::at(6))
->method('getOption')
->with('editor-cmd')
->willReturn('mate');

$this->migrationDiffGenerator->expects(self::once())
->method('generate')
->with('FooNs\\Version1234', 'filter expression', true, 80)
->willReturn('/path/to/migration.php');

$this->diffCommand->expects(self::once())
->method('procOpen')
->with('mate', '/path/to/migration.php');

$output->expects(self::once())
->method('writeln')
->with([
Expand Down Expand Up @@ -117,9 +113,10 @@ protected function setUp() : void
->method('getDiffGenerator')
->willReturn($this->migrationDiffGenerator);

$this->diffCommand = $this->getMockBuilder(DiffCommand::class)
->setConstructorArgs([$this->dependencyFactory])
->onlyMethods(['procOpen'])
->getMock();
$this->diffCommand = new DiffCommand($this->dependencyFactory);

$this->questions = $this->createMock(QuestionHelper::class);

$this->diffCommand->setHelperSet(new HelperSet(['question' => $this->questions]));
}
}
Loading