From d3e983e74030104d7944df8d6f22b8f08e0f630f Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Thu, 12 Mar 2020 22:08:50 +0100 Subject: [PATCH 1/3] mark console commands as final classes --- composer.json | 2 +- composer.lock | 107 +++++++++--------- .../Tools/Console/Command/DiffCommand.php | 4 +- .../Tools/Console/Command/DoctrineCommand.php | 11 +- .../Console/Command/DumpSchemaCommand.php | 4 +- .../Tools/Console/Command/ExecuteCommand.php | 2 +- .../Tools/Console/Command/GenerateCommand.php | 4 +- .../Tools/Console/Command/LatestCommand.php | 2 +- .../Tools/Console/Command/MigrateCommand.php | 2 +- .../Tools/Console/Command/RollupCommand.php | 2 +- .../Tools/Console/Command/StatusCommand.php | 2 +- .../Console/Command/SyncMetadataCommand.php | 2 +- .../Tools/Console/Command/UpToDateCommand.php | 2 +- .../Tools/Console/Command/VersionCommand.php | 2 +- .../Tools/Console/Command/DiffCommandTest.php | 33 ++++-- .../Console/Command/DumpSchemaCommandTest.php | 79 ++++++------- .../Console/Command/ExecuteCommandTest.php | 27 +++-- .../Console/Command/GenerateCommandTest.php | 26 +++-- .../Console/Command/MigrateCommandTest.php | 68 ++++++----- 19 files changed, 212 insertions(+), 169 deletions(-) diff --git a/composer.json b/composer.json index 2cf5895920..dd65146fbd 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "ocramius/package-versions": "^1.3", "ocramius/proxy-manager": "^2.0.2", "symfony/console": "^3.4||^4.0||^5.0", + "symfony/process": "^3.4||^4.0||^5.0", "symfony/stopwatch": "^3.4||^4.0||^5.0" }, "require-dev": { @@ -30,7 +31,6 @@ "phpstan/phpstan-strict-rules": "^0.11", "phpstan/phpstan-symfony": "^0.11.6", "phpunit/phpunit": "^8.3", - "symfony/process": "^3.4||^4.0||^5.0", "symfony/yaml": "^3.4||^4.0||^5.0" }, "suggest": { diff --git a/composer.lock b/composer.lock index f0386da27c..bf17f92864 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "0a41fb82ffcaf0bb65df32323e85b7e8", + "content-hash": "af9ec42ee918b7087ef47ac23f580bef", "packages": [ { "name": "doctrine/cache", @@ -600,6 +600,55 @@ ], "time": "2019-08-06T08:03:45+00:00" }, + { + "name": "symfony/process", + "version": "v4.4.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "bf9166bac906c9e69fb7a11d94875e7ced97bcd7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/bf9166bac906c9e69fb7a11d94875e7ced97bcd7", + "reference": "bf9166bac906c9e69fb7a11d94875e7ced97bcd7", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "https://symfony.com", + "time": "2020-02-07T20:06:44+00:00" + }, { "name": "symfony/service-contracts", "version": "v1.1.7", @@ -759,6 +808,7 @@ "code", "zf" ], + "abandoned": "laminas/laminas-code", "time": "2019-10-05T23:18:22+00:00" }, { @@ -813,6 +863,7 @@ "events", "zf2" ], + "abandoned": "laminas/laminas-eventmanager", "time": "2018-04-25T15:33:34+00:00" } ], @@ -4215,55 +4266,6 @@ ], "time": "2019-11-27T13:56:44+00:00" }, - { - "name": "symfony/process", - "version": "v4.3.5", - "source": { - "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "50556892f3cc47d4200bfd1075314139c4c9ff4b" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/50556892f3cc47d4200bfd1075314139c4c9ff4b", - "reference": "50556892f3cc47d4200bfd1075314139c4c9ff4b", - "shasum": "" - }, - "require": { - "php": "^7.1.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.3-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Process\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Process Component", - "homepage": "https://symfony.com", - "time": "2019-09-26T21:17:10+00:00" - }, { "name": "symfony/yaml", "version": "v4.3.5", @@ -4422,5 +4424,8 @@ }, "platform-dev": { "ext-pdo_sqlite": "*" + }, + "platform-overrides": { + "php": "7.2.0" } } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php index 3d9de7f465..da5d48e918 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php @@ -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'; @@ -149,7 +149,7 @@ public function execute( if ($editorCommand !== null) { assert(is_string($editorCommand)); - $this->procOpen($editorCommand, $path); + $this->procOpen($output, $editorCommand, $path); } $output->writeln([ diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php index a17a5d9568..58f93deff1 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php @@ -15,9 +15,8 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; -use function escapeshellarg; +use Symfony\Component\Process\Process; use function is_string; -use function proc_open; /** * The DoctrineCommand class provides base functionality for the other migrations commands to extend from. @@ -105,8 +104,12 @@ protected function canExecute( return ! $input->isInteractive() || $this->askConfirmation($question, $input, $output); } - protected function procOpen(string $editorCommand, string $path) : void + protected function procOpen(OutputInterface $output, string $editorCommand, string $path) : void { - proc_open($editorCommand . ' ' . escapeshellarg($path), [], $pipes); + $process = new Process([$editorCommand, $path]); + $process->setTty(true); + $this->getHelper('process')->mustRun($output, $process, null, static function ($type, $buffer) : void { + echo $buffer; + }); } } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php index de4e3a31ab..2e33acc2d4 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php @@ -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'; @@ -121,7 +121,7 @@ public function execute( if ($editorCommand !== null) { assert(is_string($editorCommand)); - $this->procOpen($editorCommand, $path); + $this->procOpen($output, $editorCommand, $path); } $output->writeln([ diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php index 07d060b21f..bfd8bc85aa 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/ExecuteCommand.php @@ -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'; diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php index b2aaff53c6..ec2e738f3a 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php @@ -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'; @@ -77,7 +77,7 @@ protected function execute(InputInterface $input, OutputInterface $output) : ?in if ($editorCommand !== null) { assert(is_string($editorCommand)); - $this->procOpen($editorCommand, $path); + $this->procOpen($output, $editorCommand, $path); } $output->writeln([ diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/LatestCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/LatestCommand.php index c0d78a0411..18546017be 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/LatestCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/LatestCommand.php @@ -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'; diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php index 2459ebc5b5..49fa24e04c 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/MigrateCommand.php @@ -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'; diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/RollupCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/RollupCommand.php index 3f1318f767..562908f2e3 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/RollupCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/RollupCommand.php @@ -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'; diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php index 06152f98eb..0889f4f56d 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/StatusCommand.php @@ -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'; diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/SyncMetadataCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/SyncMetadataCommand.php index 136a10e865..e1ba193f74 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/SyncMetadataCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/SyncMetadataCommand.php @@ -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'; diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/UpToDateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/UpToDateCommand.php index bbd9975008..fbc649fcce 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/UpToDateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/UpToDateCommand.php @@ -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'; diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php index 1c83e81cc9..a8433f18d3 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/VersionCommand.php @@ -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'; diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php index 739fe6fb0d..8308e112cd 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php @@ -11,8 +11,12 @@ 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\ProcessHelper; +use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Process\Process; use function sys_get_temp_dir; final class DiffCommandTest extends TestCase @@ -23,12 +27,18 @@ 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; + + /** @var MockObject|ProcessHelper */ + private $process; + public function testExecute() : void { $input = $this->createMock(InputInterface::class); @@ -74,9 +84,12 @@ public function testExecute() : void ->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'); + $this->process->expects(self::once()) + ->method('mustRun') + ->willReturnCallback(static function ($output, Process $process, $err, $callback) : void { + self::assertSame("'mate' '/path/to/migration.php'", $process->getCommandLine()); + self::assertNotNull($callback); + }); $output->expects(self::once()) ->method('writeln') @@ -117,9 +130,11 @@ 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->process = $this->createMock(ProcessHelper::class); + $this->questions = $this->createMock(QuestionHelper::class); + + $this->diffCommand->setHelperSet(new HelperSet(['question' => $this->questions, 'process' => $this->process])); } } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php index 5d3dfbabd5..44417d37ff 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php @@ -17,9 +17,12 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RuntimeException; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Helper\ProcessHelper; +use Symfony\Component\Console\Tester\CommandTester; +use function explode; use function sys_get_temp_dir; +use function trim; final class DumpSchemaCommandTest extends TestCase { @@ -38,53 +41,28 @@ final class DumpSchemaCommandTest extends TestCase /** @var DumpSchemaCommand */ private $dumpSchemaCommand; + /** @var MockObject|ProcessHelper */ + private $process; + + /** @var CommandTester */ + private $dumpSchemaCommandTester; + public function testExecuteThrowsRuntimeException() : void { $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Delete any previous migrations in the namespace "FooNs" before dumping your schema.'); - $input = $this->createMock(InputInterface::class); - $output = $this->createMock(OutputInterface::class); - $migration = new AvailableMigration(new Version('FooNs\Abc'), $this->createMock(AbstractMigration::class)); $this->migrationRepository->expects(self::once()) ->method('getMigrations') ->willReturn(new AvailableMigrationsList([$migration])); - $this->dumpSchemaCommand->execute($input, $output); + $this->dumpSchemaCommandTester->execute([]); } public function testExecute() : void { - $input = $this->createMock(InputInterface::class); - $output = $this->createMock(OutputInterface::class); - - $input->expects(self::at(0)) - ->method('getOption') - ->with('formatted') - ->willReturn(true); - - $input->expects(self::at(1)) - ->method('getOption') - ->with('line-length') - ->willReturn(80); - - $input->expects(self::at(2)) - ->method('getOption') - ->with('namespace') - ->willReturn(null); - - $input->expects(self::at(3)) - ->method('getOption') - ->with('filter-tables') - ->willReturn(['/foo/']); - - $input->expects(self::at(4)) - ->method('getOption') - ->with('editor-cmd') - ->willReturn('test'); - $this->migrationRepository->expects(self::once()) ->method('getMigrations') ->willReturn(new AvailableMigrationsList([])); @@ -93,19 +71,27 @@ public function testExecute() : void ->method('dump') ->with('FooNs\\Version1234', ['/foo/'], true, 80); - $output->expects(self::once()) - ->method('writeln') - ->with([ - 'Dumped your schema to a new migration class at ""', + $this->dumpSchemaCommandTester->execute([ + '--editor-cmd' => 'test', + '--filter-tables' => ['/foo/'], + '--line-length' => 80, + '--formatted' => true, + ]); + + $output = $this->dumpSchemaCommandTester->getDisplay(true); + + self::assertSame( + [ + 'Dumped your schema to a new migration class at ""', '', - 'To run just this migration for testing purposes, you can use migrations:execute --up \'FooNs\\\\Version1234\'', + 'To run just this migration for testing purposes, you can use migrations:execute --up \'FooNs\\\\Version1234\'', '', - 'To revert the migration you can use migrations:execute --down \'FooNs\\\\Version1234\'', + 'To revert the migration you can use migrations:execute --down \'FooNs\\\\Version1234\'', '', - 'To use this as a rollup migration you can use the migrations:rollup command.', - ]); - - $this->dumpSchemaCommand->execute($input, $output); + 'To use this as a rollup migration you can use the migrations:rollup command.', + ], + explode("\n", trim($output)) + ); } protected function setUp() : void @@ -140,5 +126,10 @@ protected function setUp() : void ->willReturn($this->migrationRepository); $this->dumpSchemaCommand = new DumpSchemaCommand($this->dependencyFactory); + + $this->process = $this->createMock(ProcessHelper::class); + $this->dumpSchemaCommand->setHelperSet(new HelperSet(['process' => $this->process])); + + $this->dumpSchemaCommandTester = new CommandTester($this->dumpSchemaCommand); } } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php index fa166c622f..6fcdcd7ad4 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/ExecuteCommandTest.php @@ -19,13 +19,15 @@ use Doctrine\Migrations\Version\Version; 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\Tester\CommandTester; use function getcwd; use function sys_get_temp_dir; class ExecuteCommandTest extends TestCase { - /** @var ExecuteCommand|MockObject */ + /** @var ExecuteCommand */ private $executeCommand; /** @var MockObject|DependencyFactory */ @@ -43,6 +45,9 @@ class ExecuteCommandTest extends TestCase /** @var MigrationPlanCalculator|MockObject */ private $planCalculator; + /** @var MockObject|QuestionHelper */ + private $questions; + /** * @param mixed $arg * @@ -85,8 +90,8 @@ public function getWriteSqlValues() : array public function testExecute() : void { - $this->executeCommand->expects(self::once()) - ->method('canExecute') + $this->questions->expects(self::once()) + ->method('ask') ->willReturn(true); $this->migrator @@ -118,8 +123,8 @@ public function testExecuteMultiple() : void ->with([new Version('1'), new Version('2')]) ->willReturn($pl); - $this->executeCommand->expects(self::once()) - ->method('canExecute') + $this->questions->expects(self::once()) + ->method('ask') ->willReturn(true); $this->migrator @@ -141,8 +146,8 @@ public function testExecuteMultiple() : void public function testExecuteCancel() : void { - $this->executeCommand->expects(self::once()) - ->method('canExecute') + $this->questions->expects(self::once()) + ->method('ask') ->willReturn(false); $this->migrator @@ -204,10 +209,10 @@ protected function setUp() : void ->method('getQueryWriter') ->willReturn($this->queryWriter); - $this->executeCommand = $this->getMockBuilder(ExecuteCommand::class) - ->setConstructorArgs([$this->dependencyFactory]) - ->onlyMethods(['canExecute']) - ->getMock(); + $this->executeCommand = new ExecuteCommand($this->dependencyFactory); + + $this->questions = $this->createMock(QuestionHelper::class); + $this->executeCommand->setHelperSet(new HelperSet(['question' => $this->questions])); $this->executeCommandTester = new CommandTester($this->executeCommand); } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php index f7b657a09d..c296cb283e 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php @@ -11,7 +11,10 @@ use Doctrine\Migrations\Tools\Console\Command\GenerateCommand; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Helper\ProcessHelper; use Symfony\Component\Console\Tester\CommandTester; +use Symfony\Component\Process\Process; use function explode; use function sys_get_temp_dir; use function trim; @@ -27,12 +30,15 @@ final class GenerateCommandTest extends TestCase /** @var Generator|MockObject */ private $migrationGenerator; - /** @var GenerateCommand|MockObject */ + /** @var GenerateCommand */ private $generateCommand; /** @var CommandTester */ private $generateCommandTest; + /** @var MockObject|ProcessHelper */ + private $process; + public function testExecute() : void { $this->migrationGenerator->expects(self::once()) @@ -40,9 +46,12 @@ public function testExecute() : void ->with('FooNs\\Version1234') ->willReturn('/path/to/migration.php'); - $this->generateCommand->expects(self::once()) - ->method('procOpen') - ->with('mate', '/path/to/migration.php'); + $this->process->expects(self::once()) + ->method('mustRun') + ->willReturnCallback(static function ($output, Process $process, $err, $callback) : void { + self::assertSame("'mate' '/path/to/migration.php'", $process->getCommandLine()); + self::assertNotNull($callback); + }); $this->generateCommandTest->execute(['--editor-cmd' => 'mate']); $output = $this->generateCommandTest->getDisplay(true); @@ -82,10 +91,11 @@ protected function setUp() : void ->method('getMigrationGenerator') ->willReturn($this->migrationGenerator); - $this->generateCommand = $this->getMockBuilder(GenerateCommand::class) - ->setConstructorArgs([$this->dependencyFactory]) - ->onlyMethods(['procOpen']) - ->getMock(); + $this->generateCommand = new GenerateCommand($this->dependencyFactory); + + $this->process = $this->createMock(ProcessHelper::class); + $this->generateCommand->setHelperSet(new HelperSet(['process' => $this->process])); + $this->generateCommandTest = new CommandTester($this->generateCommand); } } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php index 45a7031d5c..05d4e909a6 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/MigrateCommandTest.php @@ -21,6 +21,9 @@ use Doctrine\Migrations\Version\ExecutionResult; use Doctrine\Migrations\Version\Version; use PHPUnit\Framework\MockObject\MockObject; +use Symfony\Component\Console\Helper\HelperSet; +use Symfony\Component\Console\Helper\QuestionHelper; +use Symfony\Component\Console\Question\ConfirmationQuestion; use Symfony\Component\Console\Tester\CommandTester; use function getcwd; use function strpos; @@ -34,7 +37,7 @@ class MigrateCommandTest extends MigrationTestCase /** @var Configuration */ private $configuration; - /** @var MigrateCommand|MockObject */ + /** @var MigrateCommand */ private $migrateCommand; /** @var CommandTester */ @@ -46,6 +49,9 @@ class MigrateCommandTest extends MigrationTestCase /** @var MockObject */ private $queryWriter; + /** @var MockObject|QuestionHelper */ + private $questions; + public function testExecuteEmptyMigrationPlanCausesException() : void { $result = new ExecutionResult(new Version('A')); @@ -127,10 +133,13 @@ public function testExecutedUnavailableMigrationsCancel() : void $migrator->expects(self::never()) ->method('migrate'); - $this->migrateCommand->expects(self::once()) - ->method('canExecute') - ->with('Are you sure you wish to continue? (y/n)') - ->willReturn(false); + $this->questions->expects(self::at(0)) + ->method('ask') + ->willReturnCallback(static function ($input, $output, $question) { + self::assertEquals(new ConfirmationQuestion('Are you sure you wish to continue? (y/n)'), $question); + + return false; + }); $this->migrateCommandTester->execute(['version' => 'prev']); @@ -181,8 +190,8 @@ public function testExecuteMigrate() : void $migrator = $this->createMock(DbalMigrator::class); $this->dependencyFactory->setService(Migrator::class, $migrator); - $this->migrateCommand->expects(self::once()) - ->method('canExecute') + $this->questions->expects(self::once()) + ->method('ask') ->willReturn(true); $migrator->expects(self::once()) @@ -213,10 +222,6 @@ public function testExecuteMigrateAllOrNothing() : void return ['A']; }); - $this->migrateCommand->expects(self::once()) - ->method('canExecute') - ->willReturn(true); - $this->migrateCommandTester->execute( ['--all-or-nothing' => true], ['interactive' => false] @@ -237,15 +242,21 @@ public function testExecuteMigrateCancelExecutedUnavailableMigrations() : void $migrator->expects(self::never()) ->method('migrate'); - $this->migrateCommand->expects(self::at(0)) - ->method('canExecute') - ->with('Are you sure you wish to continue? (y/n)') - ->willReturn(true); + $this->questions->expects(self::at(0)) + ->method('ask') + ->willReturnCallback(static function ($input, $output, $question) { + self::assertEquals(new ConfirmationQuestion('Are you sure you wish to continue? (y/n)'), $question); - $this->migrateCommand->expects(self::at(1)) - ->method('canExecute') - ->with('WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)') - ->willReturn(false); + return true; + }); + + $this->questions->expects(self::at(1)) + ->method('ask') + ->willReturnCallback(static function ($input, $output, $question) { + self::assertEquals(new ConfirmationQuestion('WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)'), $question); + + return false; + }); $this->migrateCommandTester->execute(['version' => 'latest']); @@ -260,10 +271,13 @@ public function testExecuteMigrateCancel() : void $migrator->expects(self::never()) ->method('migrate'); - $this->migrateCommand->expects(self::once()) - ->method('canExecute') - ->with('WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)') - ->willReturn(false); + $this->questions->expects(self::once()) + ->method('ask') + ->willReturnCallback(static function ($input, $output, $question) { + self::assertEquals(new ConfirmationQuestion('WARNING! You are about to execute a database migration that could result in schema changes and data loss. Are you sure you wish to continue? (y/n)'), $question); + + return false; + }); $this->migrateCommandTester->execute(['version' => 'latest']); @@ -287,10 +301,10 @@ protected function setUp() : void $migrationRepository = $this->dependencyFactory->getMigrationRepository(); Helper::registerMigrationInstance($migrationRepository, new Version('A'), $migration); - $this->migrateCommand = $this->getMockBuilder(MigrateCommand::class) - ->setConstructorArgs([$this->dependencyFactory]) - ->onlyMethods(['canExecute']) - ->getMock(); + $this->migrateCommand = new MigrateCommand($this->dependencyFactory); + + $this->questions = $this->createMock(QuestionHelper::class); + $this->migrateCommand->setHelperSet(new HelperSet(['question' => $this->questions])); $this->migrateCommandTester = new CommandTester($this->migrateCommand); From 33ea68afa2073f3cc7230f44172130f6919022be Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Fri, 20 Mar 2020 11:37:21 +0100 Subject: [PATCH 2/3] remove --editor-cmd option from migration generation commands --- composer.json | 2 +- composer.lock | 107 +++++++++--------- .../Tools/Console/Command/DiffCommand.php | 16 --- .../Tools/Console/Command/DoctrineCommand.php | 10 -- .../Console/Command/DumpSchemaCommand.php | 13 --- .../Tools/Console/Command/GenerateCommand.php | 16 --- .../Tools/Console/Command/DiffCommandTest.php | 20 +--- .../Console/Command/DumpSchemaCommandTest.php | 9 -- .../Console/Command/GenerateCommandTest.php | 18 +-- 9 files changed, 54 insertions(+), 157 deletions(-) diff --git a/composer.json b/composer.json index dd65146fbd..2cf5895920 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ "ocramius/package-versions": "^1.3", "ocramius/proxy-manager": "^2.0.2", "symfony/console": "^3.4||^4.0||^5.0", - "symfony/process": "^3.4||^4.0||^5.0", "symfony/stopwatch": "^3.4||^4.0||^5.0" }, "require-dev": { @@ -31,6 +30,7 @@ "phpstan/phpstan-strict-rules": "^0.11", "phpstan/phpstan-symfony": "^0.11.6", "phpunit/phpunit": "^8.3", + "symfony/process": "^3.4||^4.0||^5.0", "symfony/yaml": "^3.4||^4.0||^5.0" }, "suggest": { diff --git a/composer.lock b/composer.lock index bf17f92864..f0386da27c 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "af9ec42ee918b7087ef47ac23f580bef", + "content-hash": "0a41fb82ffcaf0bb65df32323e85b7e8", "packages": [ { "name": "doctrine/cache", @@ -600,55 +600,6 @@ ], "time": "2019-08-06T08:03:45+00:00" }, - { - "name": "symfony/process", - "version": "v4.4.5", - "source": { - "type": "git", - "url": "https://github.com/symfony/process.git", - "reference": "bf9166bac906c9e69fb7a11d94875e7ced97bcd7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/bf9166bac906c9e69fb7a11d94875e7ced97bcd7", - "reference": "bf9166bac906c9e69fb7a11d94875e7ced97bcd7", - "shasum": "" - }, - "require": { - "php": "^7.1.3" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "4.4-dev" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Component\\Process\\": "" - }, - "exclude-from-classmap": [ - "/Tests/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony Process Component", - "homepage": "https://symfony.com", - "time": "2020-02-07T20:06:44+00:00" - }, { "name": "symfony/service-contracts", "version": "v1.1.7", @@ -808,7 +759,6 @@ "code", "zf" ], - "abandoned": "laminas/laminas-code", "time": "2019-10-05T23:18:22+00:00" }, { @@ -863,7 +813,6 @@ "events", "zf2" ], - "abandoned": "laminas/laminas-eventmanager", "time": "2018-04-25T15:33:34+00:00" } ], @@ -4266,6 +4215,55 @@ ], "time": "2019-11-27T13:56:44+00:00" }, + { + "name": "symfony/process", + "version": "v4.3.5", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "50556892f3cc47d4200bfd1075314139c4c9ff4b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/50556892f3cc47d4200bfd1075314139c4c9ff4b", + "reference": "50556892f3cc47d4200bfd1075314139c4c9ff4b", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.3-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "https://symfony.com", + "time": "2019-09-26T21:17:10+00:00" + }, { "name": "symfony/yaml", "version": "v4.3.5", @@ -4424,8 +4422,5 @@ }, "platform-dev": { "ext-pdo_sqlite": "*" - }, - "platform-overrides": { - "php": "7.2.0" } } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php index da5d48e918..6e24ef60f2 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DiffCommand.php @@ -40,9 +40,6 @@ protected function configure() : void %command.full_name% -You can optionally specify a --editor-cmd option to open the generated file in your favorite editor: - - %command.full_name% --editor-cmd=mate EOT ) ->addOption( @@ -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, @@ -145,13 +136,6 @@ public function execute( throw $exception; } - $editorCommand = $input->getOption('editor-cmd'); - - if ($editorCommand !== null) { - assert(is_string($editorCommand)); - $this->procOpen($output, $editorCommand, $path); - } - $output->writeln([ sprintf('Generated new migration class to "%s"', $path), '', diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php index 58f93deff1..f27b9a20e8 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DoctrineCommand.php @@ -15,7 +15,6 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\ConfirmationQuestion; -use Symfony\Component\Process\Process; use function is_string; /** @@ -103,13 +102,4 @@ protected function canExecute( ) : bool { return ! $input->isInteractive() || $this->askConfirmation($question, $input, $output); } - - protected function procOpen(OutputInterface $output, string $editorCommand, string $path) : void - { - $process = new Process([$editorCommand, $path]); - $process->setTty(true); - $this->getHelper('process')->mustRun($output, $process, null, static function ($type, $buffer) : void { - echo $buffer; - }); - } } diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php index 2e33acc2d4..963a471aea 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/DumpSchemaCommand.php @@ -43,12 +43,6 @@ protected function configure() : void After dumping your schema to a migration, you can rollup your migrations using the migrations:rollup command. EOT ) - ->addOption( - 'editor-cmd', - null, - InputOption::VALUE_OPTIONAL, - 'Open file with this command upon creation.' - ) ->addOption( 'formatted', null, @@ -117,13 +111,6 @@ public function execute( $lineLength ); - $editorCommand = $input->getOption('editor-cmd'); - - if ($editorCommand !== null) { - assert(is_string($editorCommand)); - $this->procOpen($output, $editorCommand, $path); - } - $output->writeln([ sprintf('Dumped your schema to a new migration class at "%s"', $path), '', diff --git a/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php b/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php index ec2e738f3a..2e1132e42a 100644 --- a/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php +++ b/lib/Doctrine/Migrations/Tools/Console/Command/GenerateCommand.php @@ -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, @@ -43,9 +37,6 @@ protected function configure() : void %command.full_name% -You can optionally specify a --editor-cmd option to open the generated file in your favorite editor: - - %command.full_name% --editor-cmd=mate EOT ); @@ -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($output, $editorCommand, $path); - } - $output->writeln([ sprintf('Generated new migration class to "%s"', $path), '', diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php index 8308e112cd..4d58a7a29f 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DiffCommandTest.php @@ -12,11 +12,9 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Console\Helper\HelperSet; -use Symfony\Component\Console\Helper\ProcessHelper; use Symfony\Component\Console\Helper\QuestionHelper; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Process\Process; use function sys_get_temp_dir; final class DiffCommandTest extends TestCase @@ -36,9 +34,6 @@ final class DiffCommandTest extends TestCase /** @var MockObject|QuestionHelper */ private $questions; - /** @var MockObject|ProcessHelper */ - private $process; - public function testExecute() : void { $input = $this->createMock(InputInterface::class); @@ -74,23 +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->process->expects(self::once()) - ->method('mustRun') - ->willReturnCallback(static function ($output, Process $process, $err, $callback) : void { - self::assertSame("'mate' '/path/to/migration.php'", $process->getCommandLine()); - self::assertNotNull($callback); - }); - $output->expects(self::once()) ->method('writeln') ->with([ @@ -132,9 +115,8 @@ protected function setUp() : void $this->diffCommand = new DiffCommand($this->dependencyFactory); - $this->process = $this->createMock(ProcessHelper::class); $this->questions = $this->createMock(QuestionHelper::class); - $this->diffCommand->setHelperSet(new HelperSet(['question' => $this->questions, 'process' => $this->process])); + $this->diffCommand->setHelperSet(new HelperSet(['question' => $this->questions])); } } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php index 44417d37ff..d25ba44d79 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/DumpSchemaCommandTest.php @@ -17,8 +17,6 @@ use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use RuntimeException; -use Symfony\Component\Console\Helper\HelperSet; -use Symfony\Component\Console\Helper\ProcessHelper; use Symfony\Component\Console\Tester\CommandTester; use function explode; use function sys_get_temp_dir; @@ -41,9 +39,6 @@ final class DumpSchemaCommandTest extends TestCase /** @var DumpSchemaCommand */ private $dumpSchemaCommand; - /** @var MockObject|ProcessHelper */ - private $process; - /** @var CommandTester */ private $dumpSchemaCommandTester; @@ -72,7 +67,6 @@ public function testExecute() : void ->with('FooNs\\Version1234', ['/foo/'], true, 80); $this->dumpSchemaCommandTester->execute([ - '--editor-cmd' => 'test', '--filter-tables' => ['/foo/'], '--line-length' => 80, '--formatted' => true, @@ -127,9 +121,6 @@ protected function setUp() : void $this->dumpSchemaCommand = new DumpSchemaCommand($this->dependencyFactory); - $this->process = $this->createMock(ProcessHelper::class); - $this->dumpSchemaCommand->setHelperSet(new HelperSet(['process' => $this->process])); - $this->dumpSchemaCommandTester = new CommandTester($this->dumpSchemaCommand); } } diff --git a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php index c296cb283e..f821fca448 100644 --- a/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php +++ b/tests/Doctrine/Migrations/Tests/Tools/Console/Command/GenerateCommandTest.php @@ -11,10 +11,7 @@ use Doctrine\Migrations\Tools\Console\Command\GenerateCommand; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Symfony\Component\Console\Helper\HelperSet; -use Symfony\Component\Console\Helper\ProcessHelper; use Symfony\Component\Console\Tester\CommandTester; -use Symfony\Component\Process\Process; use function explode; use function sys_get_temp_dir; use function trim; @@ -36,9 +33,6 @@ final class GenerateCommandTest extends TestCase /** @var CommandTester */ private $generateCommandTest; - /** @var MockObject|ProcessHelper */ - private $process; - public function testExecute() : void { $this->migrationGenerator->expects(self::once()) @@ -46,14 +40,7 @@ public function testExecute() : void ->with('FooNs\\Version1234') ->willReturn('/path/to/migration.php'); - $this->process->expects(self::once()) - ->method('mustRun') - ->willReturnCallback(static function ($output, Process $process, $err, $callback) : void { - self::assertSame("'mate' '/path/to/migration.php'", $process->getCommandLine()); - self::assertNotNull($callback); - }); - - $this->generateCommandTest->execute(['--editor-cmd' => 'mate']); + $this->generateCommandTest->execute([]); $output = $this->generateCommandTest->getDisplay(true); self::assertSame([ @@ -93,9 +80,6 @@ protected function setUp() : void $this->generateCommand = new GenerateCommand($this->dependencyFactory); - $this->process = $this->createMock(ProcessHelper::class); - $this->generateCommand->setHelperSet(new HelperSet(['process' => $this->process])); - $this->generateCommandTest = new CommandTester($this->generateCommand); } } From 7235df37bce58695d4991324ff6740353009f056 Mon Sep 17 00:00:00 2001 From: Asmir Mustafic Date: Fri, 20 Mar 2020 12:06:48 +0100 Subject: [PATCH 3/3] configure scrurinizer to run php 7.2 --- .scrutinizer.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 9303508680..b2385aa71f 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -3,7 +3,7 @@ build: analysis: environment: php: - version: 7.1 + version: 7.2 cache: disabled: false directories: @@ -16,7 +16,7 @@ build: - phpcs-run dependencies: override: - - composer install --ignore-platform-reqs --no-interaction + - composer install --no-interaction tools: external_code_coverage: