From 8a386cf3bd51477909991776b8fd90dd39497d5f Mon Sep 17 00:00:00 2001 From: Tomasz Darmetko Date: Mon, 16 Jul 2018 22:41:14 +0200 Subject: [PATCH] Make sure that composer file exists before running (#42) --- src/BinCommand.php | 6 ++++++ tests/Fixtures/MyTestCommand.php | 11 +++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/BinCommand.php b/src/BinCommand.php index 5a299b1..93acaf4 100644 --- a/src/BinCommand.php +++ b/src/BinCommand.php @@ -102,6 +102,12 @@ private function executeInNamespace(ComposerApplication $application, $namespace } $this->chdir($namespace); + + // some plugins require access to composer file e.g. Symfony Flex + if (!file_exists(Factory::getComposerFile())) { + file_put_contents(Factory::getComposerFile(), '{}'); + } + $input = new StringInput((string) $input . ' --working-dir=.'); $this->getIO()->writeError('Run with ' . $input->__toString() . '', true, IOInterface::VERBOSE); diff --git a/tests/Fixtures/MyTestCommand.php b/tests/Fixtures/MyTestCommand.php index ee8ffce..f2f6bc6 100644 --- a/tests/Fixtures/MyTestCommand.php +++ b/tests/Fixtures/MyTestCommand.php @@ -27,12 +27,11 @@ public function __construct(\PHPUnit_Framework_Assert $assert) public function execute(InputInterface $input, OutputInterface $output) { - // make sure the proxy command didn't instantiate Composer - $this->assert->assertNull($this->getComposer(false)); - $this->assert->assertNull($this->getApplication()->getComposer(false)); - - // put a dummy composer.json to be able to create Composer - file_put_contents(getcwd().'/composer.json', '{}'); + $this->assert->assertInstanceOf( + '\Composer\Composer', + $this->getComposer(), + "Some plugins may require access to composer file e.g. Symfony Flex" + ); $factory = Factory::create(new NullIO()); $config = $factory->getConfig();