From f7b03f426391da4500ab16737703630ba337f046 Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Sat, 11 Feb 2017 22:19:19 +0100 Subject: [PATCH 1/9] Issue #57: Distinguish files depending on dev environment. --- README.md | 26 ++++++++++++++------- src/Handler.php | 60 ++++++++++++++++++++++++++++++++++++++----------- src/Plugin.php | 2 +- 3 files changed, 66 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 03e1493..823cd39 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ of your root `composer.json`. "includes": [ "sites/default/example.settings.my.php" ], + "dev": [ + "my_settings_file_for_development.php" + ], "initial": { "sites/default/default.services.yml": "sites/default/services.yml", "sites/default/default.settings.php": "sites/default/settings.php" @@ -58,25 +61,29 @@ default. Default includes are provided by the plugin: ``` -.csslintrc -.editorconfig -.eslintignore -.eslintrc (Drupal <= 8.2.x) -.eslintrc.json (Drupal >= 8.3.x) -.gitattributes -.ht.router.php (Drupal >= 8.5.x) .htaccess index.php robots.txt sites/default/default.settings.php sites/default/default.services.yml -sites/development.services.yml sites/example.settings.local.php sites/example.sites.php update.php web.config ``` +Default dev are provided by the plugin: +``` +.csslintrc +.editorconfig +.eslintignore +.eslintrc (Drupal <= 8.2.x) +.eslintrc.json (Drupal >= 8.3.x) +.gitattributes +.ht.router.php (Drupal >= 8.5.x) +sites/development.services.yml +``` + When setting `omit-defaults` to `true`, neither the default excludes nor the default includes will be provided; in this instance, only those files explicitly listed in the `excludes` and `includes` options will be considered. If @@ -87,6 +94,9 @@ The `initial` hash lists files that should be copied over only if they do not exist in the destination. The key specifies the path to the source file, and the value indicates the path to the destination file. +The `dev` hash lists files that should be copied over only if they do not +exist in the destination and if the dev packages are installed. + ## Limitation When using Composer to install or update the Drupal development branch, the diff --git a/src/Handler.php b/src/Handler.php index 1bdefe0..304980f 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -133,7 +133,7 @@ public function onPostCmdEvent(Event $event) { // Only install the scaffolding if drupal/core was installed, // AND there are no scaffolding files present. if (isset($this->drupalCorePackage)) { - $this->downloadScaffold(); + $this->downloadScaffold($event->isDevMode()); // Generate the autoload.php file after generating the scaffold files. $this->generateAutoload(); } @@ -141,14 +141,22 @@ public function onPostCmdEvent(Event $event) { /** * Downloads drupal scaffold files for the current process. + * + * @param bool $dev + * TRUE if dev packages are installed. FALSE otherwise. */ - public function downloadScaffold() { + public function downloadScaffold($dev = FALSE) { $drupalCorePackage = $this->getDrupalCorePackage(); $webroot = realpath($this->getWebRoot()); - // Collect options, excludes and settings files. + // Collect options, excludes, dev and settings files. $options = $this->getOptions(); - $files = array_diff($this->getIncludes(), $this->getExcludes()); + $includes = $this->getIncludes(); + // Check dev files if necessary. + if ($dev) { + $includes = array_merge($includes, $this->getDev()); + } + $files = array_diff($includes, $this->getExcludes()); // Call any pre-scaffold scripts that may be defined. $dispatcher = new EventDispatcher($this->composer, $this->io); @@ -304,6 +312,15 @@ protected function getIncludes() { return $this->getNamedOptionList('includes', 'getIncludesDefault'); } + /** + * Retrieve list of additional dev files from optional "extra" configuration. + * + * @return array + */ + protected function getDev() { + return $this->getNamedOptionList('dev', 'getDevDefault'); + } + /** * Retrieve list of initial files from optional "extra" configuration. * @@ -343,6 +360,7 @@ protected function getOptions() { 'excludes' => [], 'includes' => [], 'initial' => [], + 'dev' => [], 'source' => 'https://cgit.drupalcode.org/drupal/plain/{path}?h={version}', // Github: https://raw.githubusercontent.com/drupal/drupal/{version}/{path} ]; @@ -360,32 +378,48 @@ protected function getExcludesDefault() { * Holds default settings files list. */ protected function getIncludesDefault() { - $version = $this->getDrupalCoreVersion($this->getDrupalCorePackage()); - list($major, $minor) = explode('.', $version, 3); - $version = "$major.$minor"; - /** * Files from 8.3.x * * @see https://cgit.drupalcode.org/drupal/tree/?h=8.3.x */ $common = [ - '.csslintrc', - '.editorconfig', - '.eslintignore', - '.gitattributes', '.htaccess', 'index.php', 'robots.txt', 'sites/default/default.settings.php', 'sites/default/default.services.yml', - 'sites/development.services.yml', 'sites/example.settings.local.php', 'sites/example.sites.php', 'update.php', 'web.config', ]; + return $common; + } + + /** + * Holds default dev files list. + */ + protected function getDevDefault() { + $version = $this->getDrupalCoreVersion($this->getDrupalCorePackage()); + list($major, $minor) = explode('.', $version, 3); + $version = "$major.$minor"; + + /** + * Files from 8.3.x + * + * @see http://cgit.drupalcode.org/drupal/tree/?h=8.3.x + */ + $common = [ + '.csslintrc', + '.editorconfig', + '.eslintignore', + '.eslintrc.json', + '.gitattributes', + 'sites/development.services.yml', + ]; + // Version specific variations. if (Semver::satisfies($version, '<8.3')) { $common[] = '.eslintrc'; diff --git a/src/Plugin.php b/src/Plugin.php index 7833903..318c3ad 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -95,7 +95,7 @@ public function postCmd(Event $event) { public static function scaffold(Event $event) { @trigger_error('\DrupalComposer\DrupalScaffold\Plugin::scaffold is deprecated since version 2.5.0 and will be removed in 3.0. Use "composer drupal:scaffold" instead.', E_USER_DEPRECATED); $handler = new Handler($event->getComposer(), $event->getIO()); - $handler->downloadScaffold(); + $handler->downloadScaffold($event->isDevMode()); // Generate the autoload.php file after generating the scaffold files. $handler->generateAutoload(); } From ce3da1337e77ce30ffc4daf3fd2c71addb3763e1 Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Sun, 12 Feb 2017 20:00:14 +0100 Subject: [PATCH 2/9] Pull request #58: Use includes-dev instead of dev. --- README.md | 6 +++--- src/Handler.php | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 823cd39..e147396 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ of your root `composer.json`. "includes": [ "sites/default/example.settings.my.php" ], - "dev": [ + "includes-dev": [ "my_settings_file_for_development.php" ], "initial": { @@ -72,7 +72,7 @@ update.php web.config ``` -Default dev are provided by the plugin: +Default includes dev are provided by the plugin: ``` .csslintrc .editorconfig @@ -94,7 +94,7 @@ The `initial` hash lists files that should be copied over only if they do not exist in the destination. The key specifies the path to the source file, and the value indicates the path to the destination file. -The `dev` hash lists files that should be copied over only if they do not +The `includes-dev` hash lists files that should be copied over only if they do not exist in the destination and if the dev packages are installed. ## Limitation diff --git a/src/Handler.php b/src/Handler.php index 304980f..c397c31 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -154,7 +154,7 @@ public function downloadScaffold($dev = FALSE) { $includes = $this->getIncludes(); // Check dev files if necessary. if ($dev) { - $includes = array_merge($includes, $this->getDev()); + $includes = array_merge($includes, $this->getIncludesDev()); } $files = array_diff($includes, $this->getExcludes()); @@ -317,8 +317,8 @@ protected function getIncludes() { * * @return array */ - protected function getDev() { - return $this->getNamedOptionList('dev', 'getDevDefault'); + protected function getIncludesDev() { + return $this->getNamedOptionList('includes-dev', 'getIncludesDevDefault'); } /** @@ -359,8 +359,8 @@ protected function getOptions() { 'omit-defaults' => FALSE, 'excludes' => [], 'includes' => [], + 'includes-dev' => [], 'initial' => [], - 'dev' => [], 'source' => 'https://cgit.drupalcode.org/drupal/plain/{path}?h={version}', // Github: https://raw.githubusercontent.com/drupal/drupal/{version}/{path} ]; @@ -401,7 +401,7 @@ protected function getIncludesDefault() { /** * Holds default dev files list. */ - protected function getDevDefault() { + protected function getIncludesDevDefault() { $version = $this->getDrupalCoreVersion($this->getDrupalCorePackage()); list($major, $minor) = explode('.', $version, 3); $version = "$major.$minor"; From fefa3f4d4a3a3c5b887a3f1843d262a77021ad28 Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Sun, 26 Feb 2017 18:32:33 +0100 Subject: [PATCH 3/9] Add test for #57. --- tests/HandlerTest.php | 165 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 tests/HandlerTest.php diff --git a/tests/HandlerTest.php b/tests/HandlerTest.php new file mode 100644 index 0000000..0b8bbb0 --- /dev/null +++ b/tests/HandlerTest.php @@ -0,0 +1,165 @@ +rootDir = realpath(realpath(__DIR__ . '/..')); + + // Prepare temp directory. + $this->fs = new Filesystem(); + $this->tmpDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'drupal-scaffold'; + $this->ensureDirectoryExistsAndClear($this->tmpDir); + + $this->writeTestReleaseTag(); + $this->writeComposerJSON(); + + chdir($this->tmpDir); + } + + /** + * tearDown + * + * @return void + */ + public function tearDown() + { + $this->fs->removeDirectory($this->tmpDir); + $this->git(sprintf('tag -d "%s"', $this->tmpReleaseTag)); + } + + /** + * Tests that files for dev environments are downloaded only in dev mode. + */ + public function testDevFiles() { + $exampleScaffoldFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'index.php'; + $developmentScaffoldFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'sites' . DIRECTORY_SEPARATOR . 'development.services.yml'; + $this->assertFileNotExists($exampleScaffoldFile, 'Scaffold file should not exist.'); + $this->assertFileNotExists($developmentScaffoldFile, 'Development scaffold file should not exist.'); + $this->composer('install --no-dev'); + $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should exist.'); + $this->assertFileNotExists($developmentScaffoldFile, 'Development scaffold file should not exist.'); + $this->composer('drupal-scaffold'); + $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should exist.'); + $this->assertFileExists($developmentScaffoldFile, 'Development scaffold file should exist.'); + } + + /** + * Writes the default composer json to the temp direcoty. + */ + protected function writeComposerJSON() { + $json = json_encode($this->composerJSONDefaults(), JSON_PRETTY_PRINT); + // Write composer.json. + file_put_contents($this->tmpDir . '/composer.json', $json); + } + + /** + * Writes a tag for the current commit, so we can reference it directly in the + * composer.json. + */ + protected function writeTestReleaseTag() { + // Tag the current state. + $this->tmpReleaseTag = '999.0.' . time(); + $this->git(sprintf('tag -a "%s" -m "%s"', $this->tmpReleaseTag, 'Tag for testing this exact commit')); + } + + /** + * Provides the default composer.json data. + * + * @return array + */ + protected function composerJSONDefaults() { + return array( + 'repositories' => array( + array( + 'type' => 'vcs', + 'url' => $this->rootDir, + ) + ), + 'require' => array( + 'drupal-composer/drupal-scaffold' => $this->tmpReleaseTag, + 'composer/installers' => '^1.0.20', + 'drupal/core' => '8.0.0', + ), + 'scripts' => array( + 'drupal-scaffold' => 'DrupalComposer\\DrupalScaffold\\Plugin::scaffold' + ), + 'minimum-stability' => 'dev', + 'prefer-stable' => true, + ); + } + + /** + * Wrapper for the composer command. + * + * @param string $command + * Composer command name, arguments and/or options + */ + protected function composer($command) { + chdir($this->tmpDir); + passthru(escapeshellcmd($this->rootDir . '/vendor/bin/composer ' . $command), $exit_code); + if ($exit_code !== 0) { + throw new \Exception('Composer returned a non-zero exit code'); + } + } + + /** + * Wrapper for git command in the root directory. + * + * @param $command + * Git command name, arguments and/or options. + */ + protected function git($command) { + chdir($this->rootDir); + passthru(escapeshellcmd('git ' . $command), $exit_code); + if ($exit_code !== 0) { + throw new \Exception('Git returned a non-zero exit code'); + } + } + + /** + * Makes sure the given directory exists and has no content. + * + * @param string $directory + */ + protected function ensureDirectoryExistsAndClear($directory) { + if (is_dir($directory)) { + $this->fs->removeDirectory($directory); + } + mkdir($directory, 0777, true); + } +} From a1585720d1b5b78d8dcf259136a78aeefb932211 Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Sat, 7 Oct 2017 14:22:10 +0200 Subject: [PATCH 4/9] Refactor tests to have a base Class. --- tests/BaseTest.php | 140 ++++++++++++++++++++++++++++++++++++++++++ tests/HandlerTest.php | 135 ++-------------------------------------- tests/PluginTest.php | 133 +-------------------------------------- 3 files changed, 147 insertions(+), 261 deletions(-) create mode 100644 tests/BaseTest.php diff --git a/tests/BaseTest.php b/tests/BaseTest.php new file mode 100644 index 0000000..79e0746 --- /dev/null +++ b/tests/BaseTest.php @@ -0,0 +1,140 @@ +rootDir = realpath(realpath(__DIR__ . '/..')); + + // Prepare temp directory. + $this->fs = new Filesystem(); + $this->tmpDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'drupal-scaffold'; + $this->ensureDirectoryExistsAndClear($this->tmpDir); + + $this->writeTestReleaseTag(); + $this->writeComposerJSON(); + + chdir($this->tmpDir); + } + + /** + * tearDown + * + * @return void + */ + public function tearDown() { + $this->fs->removeDirectory($this->tmpDir); + $this->git(sprintf('tag -d "%s"', $this->tmpReleaseTag)); + } + + /** + * Writes the default composer json to the temp direcoty. + */ + protected function writeComposerJSON() { + $json = json_encode($this->composerJSONDefaults(), JSON_PRETTY_PRINT); + // Write composer.json. + file_put_contents($this->tmpDir . '/composer.json', $json); + } + + /** + * Writes a tag for the current commit, so we can reference it directly in the + * composer.json. + */ + protected function writeTestReleaseTag() { + // Tag the current state. + $this->tmpReleaseTag = '999.0.' . time(); + $this->git(sprintf('tag -a "%s" -m "%s"', $this->tmpReleaseTag, 'Tag for testing this exact commit')); + } + + /** + * Provides the default composer.json data. + * + * @return array + */ + protected function composerJSONDefaults() { + return array( + 'repositories' => array( + array( + 'type' => 'vcs', + 'url' => $this->rootDir, + ), + ), + 'require' => array( + 'drupal-composer/drupal-scaffold' => $this->tmpReleaseTag, + 'composer/installers' => '^1.0.20', + 'drupal/core' => '8.0.0', + ), + 'minimum-stability' => 'dev', + ); + } + + /** + * Wrapper for the composer command. + * + * @param string $command + * Composer command name, arguments and/or options + */ + protected function composer($command) { + chdir($this->tmpDir); + passthru(escapeshellcmd($this->rootDir . '/vendor/bin/composer ' . $command), $exit_code); + if ($exit_code !== 0) { + throw new \Exception('Composer returned a non-zero exit code'); + } + } + + /** + * Wrapper for git command in the root directory. + * + * @param $command + * Git command name, arguments and/or options. + */ + protected function git($command) { + chdir($this->rootDir); + passthru(escapeshellcmd('git ' . $command), $exit_code); + if ($exit_code !== 0) { + throw new \Exception('Git returned a non-zero exit code'); + } + } + + /** + * Makes sure the given directory exists and has no content. + * + * @param string $directory + */ + protected function ensureDirectoryExistsAndClear($directory) { + if (is_dir($directory)) { + $this->fs->removeDirectory($directory); + } + mkdir($directory, 0777, TRUE); + } + +} diff --git a/tests/HandlerTest.php b/tests/HandlerTest.php index 0b8bbb0..4b1d303 100644 --- a/tests/HandlerTest.php +++ b/tests/HandlerTest.php @@ -2,65 +2,15 @@ /** * @file - * Contains \DrupalComposer\DrupalScaffold\Tests\PluginTest. + * Contains \DrupalComposer\DrupalScaffold\Tests\HandlerTest. */ namespace DrupalComposer\DrupalScaffold\Tests; -use Composer\Util\Filesystem; - /** * Tests composer plugin functionality. */ -class HandlerTest extends \PHPUnit_Framework_TestCase { - - /** - * @var \Composer\Util\Filesystem - */ - protected $fs; - - /** - * @var string - */ - protected $tmpDir; - - /** - * @var string - */ - protected $rootDir; - - /** - * @var string - */ - protected $tmpReleaseTag; - - /** - * SetUp test - */ - public function setUp() { - $this->rootDir = realpath(realpath(__DIR__ . '/..')); - - // Prepare temp directory. - $this->fs = new Filesystem(); - $this->tmpDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'drupal-scaffold'; - $this->ensureDirectoryExistsAndClear($this->tmpDir); - - $this->writeTestReleaseTag(); - $this->writeComposerJSON(); - - chdir($this->tmpDir); - } - - /** - * tearDown - * - * @return void - */ - public function tearDown() - { - $this->fs->removeDirectory($this->tmpDir); - $this->git(sprintf('tag -d "%s"', $this->tmpReleaseTag)); - } +class HandlerTest extends BaseTest { /** * Tests that files for dev environments are downloaded only in dev mode. @@ -79,87 +29,14 @@ public function testDevFiles() { } /** - * Writes the default composer json to the temp direcoty. - */ - protected function writeComposerJSON() { - $json = json_encode($this->composerJSONDefaults(), JSON_PRETTY_PRINT); - // Write composer.json. - file_put_contents($this->tmpDir . '/composer.json', $json); - } - - /** - * Writes a tag for the current commit, so we can reference it directly in the - * composer.json. - */ - protected function writeTestReleaseTag() { - // Tag the current state. - $this->tmpReleaseTag = '999.0.' . time(); - $this->git(sprintf('tag -a "%s" -m "%s"', $this->tmpReleaseTag, 'Tag for testing this exact commit')); - } - - /** - * Provides the default composer.json data. + * Add prefer-stable true to speed up tests. * * @return array */ protected function composerJSONDefaults() { - return array( - 'repositories' => array( - array( - 'type' => 'vcs', - 'url' => $this->rootDir, - ) - ), - 'require' => array( - 'drupal-composer/drupal-scaffold' => $this->tmpReleaseTag, - 'composer/installers' => '^1.0.20', - 'drupal/core' => '8.0.0', - ), - 'scripts' => array( - 'drupal-scaffold' => 'DrupalComposer\\DrupalScaffold\\Plugin::scaffold' - ), - 'minimum-stability' => 'dev', - 'prefer-stable' => true, - ); + $composerJsonDefault = parent::composerJSONDefaults(); + $composerJsonDefault['prefer-stable'] = true; + return $composerJsonDefault; } - /** - * Wrapper for the composer command. - * - * @param string $command - * Composer command name, arguments and/or options - */ - protected function composer($command) { - chdir($this->tmpDir); - passthru(escapeshellcmd($this->rootDir . '/vendor/bin/composer ' . $command), $exit_code); - if ($exit_code !== 0) { - throw new \Exception('Composer returned a non-zero exit code'); - } - } - - /** - * Wrapper for git command in the root directory. - * - * @param $command - * Git command name, arguments and/or options. - */ - protected function git($command) { - chdir($this->rootDir); - passthru(escapeshellcmd('git ' . $command), $exit_code); - if ($exit_code !== 0) { - throw new \Exception('Git returned a non-zero exit code'); - } - } - - /** - * Makes sure the given directory exists and has no content. - * - * @param string $directory - */ - protected function ensureDirectoryExistsAndClear($directory) { - if (is_dir($directory)) { - $this->fs->removeDirectory($directory); - } - mkdir($directory, 0777, true); - } } diff --git a/tests/PluginTest.php b/tests/PluginTest.php index a392e06..17f9c55 100644 --- a/tests/PluginTest.php +++ b/tests/PluginTest.php @@ -2,60 +2,10 @@ namespace DrupalComposer\DrupalScaffold\Tests; -use Composer\Util\Filesystem; -use PHPUnit\Framework\TestCase; - /** * Tests composer plugin functionality. */ -class PluginTest extends TestCase { - - /** - * @var \Composer\Util\Filesystem - */ - protected $fs; - - /** - * @var string - */ - protected $tmpDir; - - /** - * @var string - */ - protected $rootDir; - - /** - * @var string - */ - protected $tmpReleaseTag; - - /** - * SetUp test. - */ - public function setUp() { - $this->rootDir = realpath(realpath(__DIR__ . '/..')); - - // Prepare temp directory. - $this->fs = new Filesystem(); - $this->tmpDir = realpath(sys_get_temp_dir()) . DIRECTORY_SEPARATOR . 'drupal-scaffold'; - $this->ensureDirectoryExistsAndClear($this->tmpDir); - - $this->writeTestReleaseTag(); - $this->writeComposerJSON(); - - chdir($this->tmpDir); - } - - /** - * TearDown. - * - * @return void - */ - public function tearDown() { - $this->fs->removeDirectory($this->tmpDir); - $this->git(sprintf('tag -d "%s"', $this->tmpReleaseTag)); - } +class PluginTest extends BaseTest { /** * Tests a simple composer install without core, but adding core later. @@ -111,85 +61,4 @@ public function testComposerInstallAndUpdate() { $this->assertNotEquals(file_get_contents($exampleScaffoldFile), 1, 'Scaffold file was modified by custom command.'); } - /** - * Writes the default composer json to the temp direcoty. - */ - protected function writeComposerJSON() { - $json = json_encode($this->composerJSONDefaults(), JSON_PRETTY_PRINT); - // Write composer.json. - file_put_contents($this->tmpDir . '/composer.json', $json); - } - - /** - * Writes a tag for the current commit, so we can reference it directly in the - * composer.json. - */ - protected function writeTestReleaseTag() { - // Tag the current state. - $this->tmpReleaseTag = '999.0.' . time(); - $this->git(sprintf('tag -a "%s" -m "%s"', $this->tmpReleaseTag, 'Tag for testing this exact commit')); - } - - /** - * Provides the default composer.json data. - * - * @return array - */ - protected function composerJSONDefaults() { - return array( - 'repositories' => array( - array( - 'type' => 'vcs', - 'url' => $this->rootDir, - ), - ), - 'require' => array( - 'drupal-composer/drupal-scaffold' => $this->tmpReleaseTag, - 'composer/installers' => '^1.0.20', - 'drupal/core' => '8.0.0', - ), - 'minimum-stability' => 'dev', - ); - } - - /** - * Wrapper for the composer command. - * - * @param string $command - * Composer command name, arguments and/or options. - */ - protected function composer($command) { - chdir($this->tmpDir); - passthru(escapeshellcmd($this->rootDir . '/vendor/bin/composer ' . $command), $exit_code); - if ($exit_code !== 0) { - throw new \Exception('Composer returned a non-zero exit code'); - } - } - - /** - * Wrapper for git command in the root directory. - * - * @param $command - * Git command name, arguments and/or options. - */ - protected function git($command) { - chdir($this->rootDir); - passthru(escapeshellcmd('git ' . $command), $exit_code); - if ($exit_code !== 0) { - throw new \Exception('Git returned a non-zero exit code'); - } - } - - /** - * Makes sure the given directory exists and has no content. - * - * @param string $directory - */ - protected function ensureDirectoryExistsAndClear($directory) { - if (is_dir($directory)) { - $this->fs->removeDirectory($directory); - } - mkdir($directory, 0777, TRUE); - } - } From f3601dded70effe37cd417fd3f3fc1c0b6f8c801 Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Sat, 7 Oct 2017 14:39:02 +0200 Subject: [PATCH 5/9] Pass the entire Composer event to the downloadScaffold method. --- src/Handler.php | 10 +++++----- src/Plugin.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Handler.php b/src/Handler.php index c397c31..4393066 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -133,7 +133,7 @@ public function onPostCmdEvent(Event $event) { // Only install the scaffolding if drupal/core was installed, // AND there are no scaffolding files present. if (isset($this->drupalCorePackage)) { - $this->downloadScaffold($event->isDevMode()); + $this->downloadScaffold($event); // Generate the autoload.php file after generating the scaffold files. $this->generateAutoload(); } @@ -142,10 +142,10 @@ public function onPostCmdEvent(Event $event) { /** * Downloads drupal scaffold files for the current process. * - * @param bool $dev - * TRUE if dev packages are installed. FALSE otherwise. + * @param \Composer\Script\Event $event + * The Composer event. */ - public function downloadScaffold($dev = FALSE) { + public function downloadScaffold($event) { $drupalCorePackage = $this->getDrupalCorePackage(); $webroot = realpath($this->getWebRoot()); @@ -153,7 +153,7 @@ public function downloadScaffold($dev = FALSE) { $options = $this->getOptions(); $includes = $this->getIncludes(); // Check dev files if necessary. - if ($dev) { + if ($event->isDevMode()) { $includes = array_merge($includes, $this->getIncludesDev()); } $files = array_diff($includes, $this->getExcludes()); diff --git a/src/Plugin.php b/src/Plugin.php index 318c3ad..7a801f1 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -95,7 +95,7 @@ public function postCmd(Event $event) { public static function scaffold(Event $event) { @trigger_error('\DrupalComposer\DrupalScaffold\Plugin::scaffold is deprecated since version 2.5.0 and will be removed in 3.0. Use "composer drupal:scaffold" instead.', E_USER_DEPRECATED); $handler = new Handler($event->getComposer(), $event->getIO()); - $handler->downloadScaffold($event->isDevMode()); + $handler->downloadScaffold($event); // Generate the autoload.php file after generating the scaffold files. $handler->generateAutoload(); } From 6eac9e3e5e2ada46785e78341e9e52410ce9a8a0 Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Sat, 9 Dec 2017 11:34:47 +0100 Subject: [PATCH 6/9] Run composer install and require command with the dev dependencies to have the checked files. --- tests/PluginTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/PluginTest.php b/tests/PluginTest.php index 17f9c55..6b2c6d5 100644 --- a/tests/PluginTest.php +++ b/tests/PluginTest.php @@ -13,7 +13,7 @@ class PluginTest extends BaseTest { public function testComposerInstallAndUpdate() { $exampleScaffoldFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'index.php'; $this->assertFileNotExists($exampleScaffoldFile, 'Scaffold file should not be exist.'); - $this->composer('install --no-dev --prefer-dist'); + $this->composer('install --prefer-dist'); $this->assertFileExists($this->tmpDir . DIRECTORY_SEPARATOR . 'core', 'Drupal core is installed.'); $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be automatically installed.'); $this->fs->remove($exampleScaffoldFile); @@ -27,7 +27,7 @@ public function testComposerInstallAndUpdate() { touch($exampleScaffoldFile); $mtime_touched = filemtime($exampleScaffoldFile); // Requiring a newer version triggers "composer update". - $this->composer('require --update-with-dependencies --prefer-dist --update-no-dev drupal/core:"' . $version . '"'); + $this->composer('require --update-with-dependencies --prefer-dist drupal/core:"' . $version . '"'); clearstatcache(); $mtime_after = filemtime($exampleScaffoldFile); $this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by composer update. (' . $version . ')'); From 2f1053e3ca581320f45db529b8b2cdd301909f7e Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Sat, 9 Dec 2017 12:38:06 +0100 Subject: [PATCH 7/9] File .eslintrc.json should be added depending of the core version. --- src/Handler.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Handler.php b/src/Handler.php index 4393066..21c04a3 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -415,7 +415,6 @@ protected function getIncludesDevDefault() { '.csslintrc', '.editorconfig', '.eslintignore', - '.eslintrc.json', '.gitattributes', 'sites/development.services.yml', ]; From 554467bb73d7d64e3d67f7559afadb8d6a2913bd Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Sat, 21 Apr 2018 16:17:30 +0200 Subject: [PATCH 8/9] Update code due to the new drupal:scaffold command. Follow logic of Composer to add require-dev by default. --- src/DrupalScaffoldCommand.php | 8 ++++++-- src/Handler.php | 10 +++++----- src/Plugin.php | 2 +- tests/HandlerTest.php | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/DrupalScaffoldCommand.php b/src/DrupalScaffoldCommand.php index 485a2f5..970f269 100644 --- a/src/DrupalScaffoldCommand.php +++ b/src/DrupalScaffoldCommand.php @@ -4,6 +4,7 @@ use Composer\Command\BaseCommand; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; /** @@ -20,7 +21,10 @@ protected function configure() { parent::configure(); $this ->setName('drupal:scaffold') - ->setDescription('Update the Drupal scaffold files.'); + ->setDescription('Update the Drupal scaffold files.') + ->setDefinition(array( + new InputOption('no-dev', NULL, InputOption::VALUE_NONE, 'Disables download of include-dev files.'), + )); } /** @@ -28,7 +32,7 @@ protected function configure() { */ protected function execute(InputInterface $input, OutputInterface $output) { $handler = new Handler($this->getComposer(), $this->getIO()); - $handler->downloadScaffold(); + $handler->downloadScaffold(!$input->getOption('no-dev')); // Generate the autoload.php file after generating the scaffold files. $handler->generateAutoload(); } diff --git a/src/Handler.php b/src/Handler.php index 21c04a3..db3ed4a 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -133,7 +133,7 @@ public function onPostCmdEvent(Event $event) { // Only install the scaffolding if drupal/core was installed, // AND there are no scaffolding files present. if (isset($this->drupalCorePackage)) { - $this->downloadScaffold($event); + $this->downloadScaffold($event->isDevMode()); // Generate the autoload.php file after generating the scaffold files. $this->generateAutoload(); } @@ -142,10 +142,10 @@ public function onPostCmdEvent(Event $event) { /** * Downloads drupal scaffold files for the current process. * - * @param \Composer\Script\Event $event - * The Composer event. + * @param bool $dev + * TRUE if dev packages are installed. FALSE otherwise. */ - public function downloadScaffold($event) { + public function downloadScaffold($dev = TRUE) { $drupalCorePackage = $this->getDrupalCorePackage(); $webroot = realpath($this->getWebRoot()); @@ -153,7 +153,7 @@ public function downloadScaffold($event) { $options = $this->getOptions(); $includes = $this->getIncludes(); // Check dev files if necessary. - if ($event->isDevMode()) { + if ($dev) { $includes = array_merge($includes, $this->getIncludesDev()); } $files = array_diff($includes, $this->getExcludes()); diff --git a/src/Plugin.php b/src/Plugin.php index 7a801f1..318c3ad 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -95,7 +95,7 @@ public function postCmd(Event $event) { public static function scaffold(Event $event) { @trigger_error('\DrupalComposer\DrupalScaffold\Plugin::scaffold is deprecated since version 2.5.0 and will be removed in 3.0. Use "composer drupal:scaffold" instead.', E_USER_DEPRECATED); $handler = new Handler($event->getComposer(), $event->getIO()); - $handler->downloadScaffold($event); + $handler->downloadScaffold($event->isDevMode()); // Generate the autoload.php file after generating the scaffold files. $handler->generateAutoload(); } diff --git a/tests/HandlerTest.php b/tests/HandlerTest.php index 4b1d303..b74938c 100644 --- a/tests/HandlerTest.php +++ b/tests/HandlerTest.php @@ -23,7 +23,7 @@ public function testDevFiles() { $this->composer('install --no-dev'); $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should exist.'); $this->assertFileNotExists($developmentScaffoldFile, 'Development scaffold file should not exist.'); - $this->composer('drupal-scaffold'); + $this->composer('drupal:scaffold'); $this->assertFileExists($exampleScaffoldFile, 'Scaffold file should exist.'); $this->assertFileExists($developmentScaffoldFile, 'Development scaffold file should exist.'); } @@ -35,7 +35,7 @@ public function testDevFiles() { */ protected function composerJSONDefaults() { $composerJsonDefault = parent::composerJSONDefaults(); - $composerJsonDefault['prefer-stable'] = true; + $composerJsonDefault['prefer-stable'] = TRUE; return $composerJsonDefault; } From 2fdc6d66cd2610486cdb48fd1f2c09cc932b690d Mon Sep 17 00:00:00 2001 From: Florent Torregrosa Date: Thu, 5 Jul 2018 08:49:17 +0100 Subject: [PATCH 9/9] Fix missing class use after rebasing. --- tests/BaseTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/BaseTest.php b/tests/BaseTest.php index 79e0746..492dc74 100644 --- a/tests/BaseTest.php +++ b/tests/BaseTest.php @@ -3,11 +3,12 @@ namespace DrupalComposer\DrupalScaffold\Tests; use Composer\Util\Filesystem; +use PHPUnit\Framework\TestCase; /** * Base test Class for drupal-scaffold features. */ -abstract class BaseTest extends \PHPUnit_Framework_TestCase { +abstract class BaseTest extends TestCase { /** * @var \Composer\Util\Filesystem