From 13dfecacd9f726f612b48d960c2d8bc95d4275f0 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 14:52:28 -0300 Subject: [PATCH 01/13] Add test --- tests/Unit/Commands/AddCommandTest.php | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/Unit/Commands/AddCommandTest.php diff --git a/tests/Unit/Commands/AddCommandTest.php b/tests/Unit/Commands/AddCommandTest.php new file mode 100644 index 0000000..faee30e --- /dev/null +++ b/tests/Unit/Commands/AddCommandTest.php @@ -0,0 +1,58 @@ + 'dex/test', + 'config' => [ + 'allow-plugins' => [ + 'dex/composer-plug-and-play' => true, + 'dex/fake' => true, + ], + ], + ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + + mkdir($this->directory); + file_put_contents($this->directory . '/composer.json', $composer); + } + + protected function tearDown(): void + { + exec('rm -r ' . $this->directory); + } + + public function test(): void + { + $application = new Application(); + $input = new StringInput("plug-and-play:add -d {$this->directory} dex/extra"); + $output = new BufferedOutput(); + + $application->doRun($input, $output); + + $expected = json_encode([ + 'name' => 'dex/test', + 'config' => [ + 'allow-plugins' => [ + 'dex/composer-plug-and-play' => true, + 'dex/fake' => true, + ], + ], + 'require' => [ + 'dex/extra' => '*', + ], + ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + + $this->assertJsonStringEqualsJsonFile($expected, $this->directory . '/packages/composer.json'); + } +} From a706e3abcb3177809f09ded649985b1af753104e Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:00:26 -0300 Subject: [PATCH 02/13] Add test when file not exists --- tests/Unit/Commands/AddCommandTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/Unit/Commands/AddCommandTest.php b/tests/Unit/Commands/AddCommandTest.php index faee30e..7fb16ae 100644 --- a/tests/Unit/Commands/AddCommandTest.php +++ b/tests/Unit/Commands/AddCommandTest.php @@ -55,4 +55,17 @@ public function test(): void $this->assertJsonStringEqualsJsonFile($expected, $this->directory . '/packages/composer.json'); } + + public function testFileNotExists(): void + { + $application = new Application(); + $input = new StringInput("plug-and-play:add -d {$this->directory} dex/extra"); + $output = new BufferedOutput(); + + $application->doRun($input, $output); + + $output = $output->fetch(); + + $this->assertStringContainsString('The [packages/composer.json] file not exists.', $output); + } } From d1909089895e38d205b1fa735bc6c1e5a8ace4ae Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:01:25 -0300 Subject: [PATCH 03/13] Command `plug-and-play:add` --- src/Commands/AddCommand.php | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/Commands/AddCommand.php diff --git a/src/Commands/AddCommand.php b/src/Commands/AddCommand.php new file mode 100644 index 0000000..b00854c --- /dev/null +++ b/src/Commands/AddCommand.php @@ -0,0 +1,39 @@ +naming('plug-and-play:add'); + $this->setDescription('Add a required package to install using plug and play plugin.'); + $this->addArgument('package', InputArgument::REQUIRED, 'Package to add in plug and play dependencies'); + } + + protected function execute(InputInterface $input, OutputInterface $output): int + { + $output->writeln('You are using Composer Plug and Play Plugin.'); + + if ($input->getOption('plug-and-play-pretend')) { + return 0; + } + + if (file_exists('packages/composer.json') === false) { + $output->writeln('The [packages/composer.json] file not exists.'); + + return 1; + } + + return 0; + } +} From b7a49c0a4ac71e3b475232fb238d1630a7c72e65 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:01:30 -0300 Subject: [PATCH 04/13] Register command --- src/PlugAndPlayPlugin.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PlugAndPlayPlugin.php b/src/PlugAndPlayPlugin.php index 4ee019a..189e668 100644 --- a/src/PlugAndPlayPlugin.php +++ b/src/PlugAndPlayPlugin.php @@ -7,6 +7,7 @@ use Composer\Plugin\Capability\CommandProvider; use Composer\Plugin\Capable; use Composer\Plugin\PluginInterface; +use Dex\Composer\PlugAndPlay\Commands\AddCommand; use Dex\Composer\PlugAndPlay\Commands\DumpAutoloadCommand; use Dex\Composer\PlugAndPlay\Commands\InitCommand; use Dex\Composer\PlugAndPlay\Commands\InstallCommand; @@ -44,6 +45,7 @@ public function getCommands(): array new InstallCommand(), new UpdateCommand(), new DumpAutoloadCommand(), + new AddCommand(), new InitCommand(), ]; } From efa8a26fbe2ceb1d4509640b0d1d91fb5aefe1b5 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:17:40 -0300 Subject: [PATCH 05/13] Add required package --- src/Commands/AddCommand.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Commands/AddCommand.php b/src/Commands/AddCommand.php index b00854c..7d0cb05 100644 --- a/src/Commands/AddCommand.php +++ b/src/Commands/AddCommand.php @@ -34,6 +34,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int return 1; } + $composer = file_get_contents('packages/composer.json'); + + $json = json_decode($composer, true); + + $json['require'][$input->getArgument('package')] = '*'; + + $json = json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + + file_put_contents('packages/composer.json', $json); + return 0; } } From 4b7b8f92850430315dafb4d382a0aeae63a5e0b6 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:17:50 -0300 Subject: [PATCH 06/13] Modify test --- tests/Unit/Commands/AddCommandTest.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/Unit/Commands/AddCommandTest.php b/tests/Unit/Commands/AddCommandTest.php index 7fb16ae..024fe15 100644 --- a/tests/Unit/Commands/AddCommandTest.php +++ b/tests/Unit/Commands/AddCommandTest.php @@ -24,6 +24,7 @@ protected function setUp(): void ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); mkdir($this->directory); + mkdir($this->directory . '/packages'); file_put_contents($this->directory . '/composer.json', $composer); } @@ -34,6 +35,12 @@ protected function tearDown(): void public function test(): void { + $base = json_encode([ + 'minimum-stability' => 'dev', + ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + + file_put_contents($this->directory . '/packages/composer.json', $base); + $application = new Application(); $input = new StringInput("plug-and-play:add -d {$this->directory} dex/extra"); $output = new BufferedOutput(); @@ -41,19 +48,14 @@ public function test(): void $application->doRun($input, $output); $expected = json_encode([ - 'name' => 'dex/test', - 'config' => [ - 'allow-plugins' => [ - 'dex/composer-plug-and-play' => true, - 'dex/fake' => true, - ], - ], + 'minimum-stability' => 'dev', 'require' => [ 'dex/extra' => '*', ], ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - $this->assertJsonStringEqualsJsonFile($expected, $this->directory . '/packages/composer.json'); + $this->assertFileExists($this->directory . '/packages/composer.json'); + $this->assertJsonStringEqualsJsonFile($this->directory . '/packages/composer.json', $expected); } public function testFileNotExists(): void From 4be02799d550a47ea80548cda85c6ee48fbe88a7 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:18:58 -0300 Subject: [PATCH 07/13] Remove `pretent` option --- src/Commands/AddCommand.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Commands/AddCommand.php b/src/Commands/AddCommand.php index 7d0cb05..5cd70bc 100644 --- a/src/Commands/AddCommand.php +++ b/src/Commands/AddCommand.php @@ -24,10 +24,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $output->writeln('You are using Composer Plug and Play Plugin.'); - if ($input->getOption('plug-and-play-pretend')) { - return 0; - } - if (file_exists('packages/composer.json') === false) { $output->writeln('The [packages/composer.json] file not exists.'); From 64ffa5722962129b263f728e2b47d1c5f83b30bb Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:26:53 -0300 Subject: [PATCH 08/13] Allow to set the package version --- src/Commands/AddCommand.php | 3 ++- tests/Unit/Commands/AddCommandTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/Commands/AddCommand.php b/src/Commands/AddCommand.php index 5cd70bc..9e08810 100644 --- a/src/Commands/AddCommand.php +++ b/src/Commands/AddCommand.php @@ -18,6 +18,7 @@ protected function configure(): void $this->naming('plug-and-play:add'); $this->setDescription('Add a required package to install using plug and play plugin.'); $this->addArgument('package', InputArgument::REQUIRED, 'Package to add in plug and play dependencies'); + $this->addArgument('version', InputArgument::OPTIONAL, 'Version of the package', '*'); } protected function execute(InputInterface $input, OutputInterface $output): int @@ -34,7 +35,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $json = json_decode($composer, true); - $json['require'][$input->getArgument('package')] = '*'; + $json['require'][$input->getArgument('package')] = $input->getArgument('version'); $json = json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/tests/Unit/Commands/AddCommandTest.php b/tests/Unit/Commands/AddCommandTest.php index 024fe15..23b505a 100644 --- a/tests/Unit/Commands/AddCommandTest.php +++ b/tests/Unit/Commands/AddCommandTest.php @@ -58,6 +58,31 @@ public function test(): void $this->assertJsonStringEqualsJsonFile($this->directory . '/packages/composer.json', $expected); } + public function testWithVersion(): void + { + $base = json_encode([ + 'minimum-stability' => 'dev', + ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + + file_put_contents($this->directory . '/packages/composer.json', $base); + + $application = new Application(); + $input = new StringInput("plug-and-play:add -d {$this->directory} dex/extra 1.0"); + $output = new BufferedOutput(); + + $application->doRun($input, $output); + + $expected = json_encode([ + 'minimum-stability' => 'dev', + 'require' => [ + 'dex/extra' => '1.0', + ], + ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + + $this->assertFileExists($this->directory . '/packages/composer.json'); + $this->assertJsonStringEqualsJsonFile($this->directory . '/packages/composer.json', $expected); + } + public function testFileNotExists(): void { $application = new Application(); From accbe40e8697424ee105e3a3a58e4e6db743bfb8 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:30:31 -0300 Subject: [PATCH 09/13] Use constant --- src/Commands/AddCommand.php | 9 +++++---- tests/Unit/Commands/AddCommandTest.php | 13 +++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Commands/AddCommand.php b/src/Commands/AddCommand.php index 9e08810..6c3e0fa 100644 --- a/src/Commands/AddCommand.php +++ b/src/Commands/AddCommand.php @@ -3,6 +3,7 @@ namespace Dex\Composer\PlugAndPlay\Commands; use Composer\Command\BaseCommand; +use Dex\Composer\PlugAndPlay\PlugAndPlayInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -25,13 +26,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int { $output->writeln('You are using Composer Plug and Play Plugin.'); - if (file_exists('packages/composer.json') === false) { - $output->writeln('The [packages/composer.json] file not exists.'); + if (file_exists(PlugAndPlayInterface::PACKAGES_FILE) === false) { + $output->writeln('The [' . PlugAndPlayInterface::PACKAGES_FILE . '] file not exists.'); return 1; } - $composer = file_get_contents('packages/composer.json'); + $composer = file_get_contents(PlugAndPlayInterface::PACKAGES_FILE); $json = json_decode($composer, true); @@ -39,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $json = json_encode($json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - file_put_contents('packages/composer.json', $json); + file_put_contents(PlugAndPlayInterface::PACKAGES_FILE, $json); return 0; } diff --git a/tests/Unit/Commands/AddCommandTest.php b/tests/Unit/Commands/AddCommandTest.php index 23b505a..8ad3f90 100644 --- a/tests/Unit/Commands/AddCommandTest.php +++ b/tests/Unit/Commands/AddCommandTest.php @@ -2,6 +2,7 @@ namespace Dex\Composer\PlugAndPlay\Tests\Unit\Commands; +use Dex\Composer\PlugAndPlay\PlugAndPlayInterface; use Dex\Composer\PlugAndPlay\Tests\Application; use Dex\Composer\PlugAndPlay\Tests\TestCase; use Symfony\Component\Console\Input\StringInput; @@ -39,7 +40,7 @@ public function test(): void 'minimum-stability' => 'dev', ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - file_put_contents($this->directory . '/packages/composer.json', $base); + file_put_contents($this->directory . PlugAndPlayInterface::PACKAGES_FILE, $base); $application = new Application(); $input = new StringInput("plug-and-play:add -d {$this->directory} dex/extra"); @@ -54,8 +55,8 @@ public function test(): void ], ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - $this->assertFileExists($this->directory . '/packages/composer.json'); - $this->assertJsonStringEqualsJsonFile($this->directory . '/packages/composer.json', $expected); + $this->assertFileExists($this->directory . PlugAndPlayInterface::PACKAGES_FILE); + $this->assertJsonStringEqualsJsonFile($this->directory . PlugAndPlayInterface::PACKAGES_FILE, $expected); } public function testWithVersion(): void @@ -64,7 +65,7 @@ public function testWithVersion(): void 'minimum-stability' => 'dev', ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - file_put_contents($this->directory . '/packages/composer.json', $base); + file_put_contents($this->directory . PlugAndPlayInterface::PACKAGES_FILE, $base); $application = new Application(); $input = new StringInput("plug-and-play:add -d {$this->directory} dex/extra 1.0"); @@ -79,8 +80,8 @@ public function testWithVersion(): void ], ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); - $this->assertFileExists($this->directory . '/packages/composer.json'); - $this->assertJsonStringEqualsJsonFile($this->directory . '/packages/composer.json', $expected); + $this->assertFileExists($this->directory . PlugAndPlayInterface::PACKAGES_FILE); + $this->assertJsonStringEqualsJsonFile($this->directory . PlugAndPlayInterface::PACKAGES_FILE, $expected); } public function testFileNotExists(): void From fd472d816d669faace7cd93e52362db1a8c67655 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:34:04 -0300 Subject: [PATCH 10/13] Fix constant use --- tests/Unit/Commands/AddCommandTest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/Unit/Commands/AddCommandTest.php b/tests/Unit/Commands/AddCommandTest.php index 8ad3f90..9752eeb 100644 --- a/tests/Unit/Commands/AddCommandTest.php +++ b/tests/Unit/Commands/AddCommandTest.php @@ -10,7 +10,7 @@ class AddCommandTest extends TestCase { - protected $directory = __DIR__ . '/../../tmp'; + protected $directory = __DIR__ . '/../../tmp/'; protected function setUp(): void { @@ -25,8 +25,8 @@ protected function setUp(): void ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); mkdir($this->directory); - mkdir($this->directory . '/packages'); - file_put_contents($this->directory . '/composer.json', $composer); + mkdir($this->directory . PlugAndPlayInterface::PACKAGES_PATH); + file_put_contents($this->directory . 'composer.json', $composer); } protected function tearDown(): void @@ -94,6 +94,6 @@ public function testFileNotExists(): void $output = $output->fetch(); - $this->assertStringContainsString('The [packages/composer.json] file not exists.', $output); + $this->assertStringContainsString('The [' . PlugAndPlayInterface::PACKAGES_FILE . '] file not exists.', $output); } } From 819e814ca0b37f5850811c62d7b7b0836ddd6759 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:39:32 -0300 Subject: [PATCH 11/13] Put message into variable --- tests/Unit/Commands/AddCommandTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/Unit/Commands/AddCommandTest.php b/tests/Unit/Commands/AddCommandTest.php index 9752eeb..ec56477 100644 --- a/tests/Unit/Commands/AddCommandTest.php +++ b/tests/Unit/Commands/AddCommandTest.php @@ -94,6 +94,8 @@ public function testFileNotExists(): void $output = $output->fetch(); - $this->assertStringContainsString('The [' . PlugAndPlayInterface::PACKAGES_FILE . '] file not exists.', $output); + $message = 'The [' . PlugAndPlayInterface::PACKAGES_FILE . '] file not exists.'; + + $this->assertStringContainsString($message, $output); } } From 24819a218b54d500d1b27a19e9da21cb3fd38278 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:53:26 -0300 Subject: [PATCH 12/13] Test case base for command testing --- tests/CommandTestCase.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/CommandTestCase.php diff --git a/tests/CommandTestCase.php b/tests/CommandTestCase.php new file mode 100644 index 0000000..ac22037 --- /dev/null +++ b/tests/CommandTestCase.php @@ -0,0 +1,36 @@ +directory"); + $output = new BufferedOutput(); + + $application->doRun($input, $output); + + return $output; + } + + protected function encodeContent(array $data): string + { + return json_encode( + $data, + JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE + ); + } + + protected function packagesFile(): string + { + return $this->directory . PlugAndPlayInterface::PACKAGES_FILE; + } +} From e91008ca243872180bce3088b7d2ab0f063c8d62 Mon Sep 17 00:00:00 2001 From: Eder Soares Date: Fri, 23 Sep 2022 15:53:33 -0300 Subject: [PATCH 13/13] Improves test --- tests/Unit/Commands/AddCommandTest.php | 68 ++++++++++---------------- 1 file changed, 25 insertions(+), 43 deletions(-) diff --git a/tests/Unit/Commands/AddCommandTest.php b/tests/Unit/Commands/AddCommandTest.php index ec56477..2ae6772 100644 --- a/tests/Unit/Commands/AddCommandTest.php +++ b/tests/Unit/Commands/AddCommandTest.php @@ -3,15 +3,10 @@ namespace Dex\Composer\PlugAndPlay\Tests\Unit\Commands; use Dex\Composer\PlugAndPlay\PlugAndPlayInterface; -use Dex\Composer\PlugAndPlay\Tests\Application; -use Dex\Composer\PlugAndPlay\Tests\TestCase; -use Symfony\Component\Console\Input\StringInput; -use Symfony\Component\Console\Output\BufferedOutput; +use Dex\Composer\PlugAndPlay\Tests\CommandTestCase; -class AddCommandTest extends TestCase +class AddCommandTest extends CommandTestCase { - protected $directory = __DIR__ . '/../../tmp/'; - protected function setUp(): void { $composer = json_encode([ @@ -29,6 +24,15 @@ protected function setUp(): void file_put_contents($this->directory . 'composer.json', $composer); } + protected function createPackagesComposerJson(): void + { + $base = json_encode([ + 'minimum-stability' => 'dev', + ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + + file_put_contents($this->packagesFile(), $base); + } + protected function tearDown(): void { exec('rm -r ' . $this->directory); @@ -36,66 +40,44 @@ protected function tearDown(): void public function test(): void { - $base = json_encode([ - 'minimum-stability' => 'dev', - ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + $this->createPackagesComposerJson(); - file_put_contents($this->directory . PlugAndPlayInterface::PACKAGES_FILE, $base); + $this->runCommand('plug-and-play:add dex/extra'); - $application = new Application(); - $input = new StringInput("plug-and-play:add -d {$this->directory} dex/extra"); - $output = new BufferedOutput(); - - $application->doRun($input, $output); - - $expected = json_encode([ + $expected = $this->encodeContent([ 'minimum-stability' => 'dev', 'require' => [ 'dex/extra' => '*', ], - ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + ]); - $this->assertFileExists($this->directory . PlugAndPlayInterface::PACKAGES_FILE); - $this->assertJsonStringEqualsJsonFile($this->directory . PlugAndPlayInterface::PACKAGES_FILE, $expected); + $this->assertFileExists($this->packagesFile()); + $this->assertJsonStringEqualsJsonFile($this->packagesFile(), $expected); } public function testWithVersion(): void { - $base = json_encode([ - 'minimum-stability' => 'dev', - ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + $this->createPackagesComposerJson(); - file_put_contents($this->directory . PlugAndPlayInterface::PACKAGES_FILE, $base); + $this->runCommand('plug-and-play:add dex/extra 1.0'); - $application = new Application(); - $input = new StringInput("plug-and-play:add -d {$this->directory} dex/extra 1.0"); - $output = new BufferedOutput(); - - $application->doRun($input, $output); - - $expected = json_encode([ + $expected = $this->encodeContent([ 'minimum-stability' => 'dev', 'require' => [ 'dex/extra' => '1.0', ], - ], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); + ]); - $this->assertFileExists($this->directory . PlugAndPlayInterface::PACKAGES_FILE); - $this->assertJsonStringEqualsJsonFile($this->directory . PlugAndPlayInterface::PACKAGES_FILE, $expected); + $this->assertFileExists($this->packagesFile()); + $this->assertJsonStringEqualsJsonFile($this->packagesFile(), $expected); } public function testFileNotExists(): void { - $application = new Application(); - $input = new StringInput("plug-and-play:add -d {$this->directory} dex/extra"); - $output = new BufferedOutput(); - - $application->doRun($input, $output); - - $output = $output->fetch(); + $output = $this->runCommand('plug-and-play:add dex/extra'); $message = 'The [' . PlugAndPlayInterface::PACKAGES_FILE . '] file not exists.'; - $this->assertStringContainsString($message, $output); + $this->assertStringContainsString($message, $output->fetch()); } }