From 0ece90c6cfe6a0225ca830d7c05cf104b44105e7 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 9 Feb 2020 12:11:20 +0000 Subject: [PATCH] Ensure that the directory doesn't already exist --- app.php | 14 ++++ composer.json | 19 ++++- composer.lock | 81 ++++++++++++++++++- phpunit.xml | 18 +++++ src/Command/GenerateDrupal7Command.php | 51 ++++++++++++ src/Exception/CannotCreateModuleException.php | 11 +++ .../GenerateDrupal7ModuleCommandTest.php | 27 +++++++ 7 files changed, 217 insertions(+), 4 deletions(-) create mode 100644 app.php create mode 100644 phpunit.xml create mode 100644 src/Command/GenerateDrupal7Command.php create mode 100644 src/Exception/CannotCreateModuleException.php create mode 100644 tests/Command/GenerateDrupal7ModuleCommandTest.php diff --git a/app.php b/app.php new file mode 100644 index 0000000..874f0f4 --- /dev/null +++ b/app.php @@ -0,0 +1,14 @@ +addCommands([ + new GenerateDrupal7Command(), +]); + +$app->run(); diff --git a/composer.json b/composer.json index 6c5a950..5674991 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,9 @@ "symfony/dependency-injection": "^5.0" }, "require-dev": { - "phpunit/phpunit": "^9.0" + "php": "5.6 || ^7.0", + "phpunit/phpunit": "^9.0", + "symfony/var-dumper": "^5.0" }, "license": "MIT", "authors": [ @@ -15,5 +17,18 @@ "name": "Oliver Davies", "email": "oliver@oliverdavies.uk" } - ] + ], + "autoload": { + "psr-4": { + "Opdavies\\DrupalModuleGenerator\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Opdavies\\Tests\\DrupalModuleGenerator\\": "tests/" + } + }, + "config": { + "sort-packages": true + } } diff --git a/composer.lock b/composer.lock index 973365b..f04f49c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c857126b9f1440b76b7f240733f85adb", + "content-hash": "21bd996a5a5331085c6854ddc3f384f2", "packages": [ { "name": "psr/container", @@ -1875,6 +1875,81 @@ ], "time": "2019-11-27T13:56:44+00:00" }, + { + "name": "symfony/var-dumper", + "version": "v5.0.4", + "source": { + "type": "git", + "url": "https://github.com/symfony/var-dumper.git", + "reference": "923591cfb78a935f0c98968fedfad05bfda9d01f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/923591cfb78a935f0c98968fedfad05bfda9d01f", + "reference": "923591cfb78a935f0c98968fedfad05bfda9d01f", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "phpunit/phpunit": "<5.4.3", + "symfony/console": "<4.4" + }, + "require-dev": { + "ext-iconv": "*", + "symfony/console": "^4.4|^5.0", + "symfony/process": "^4.4|^5.0", + "twig/twig": "^2.4|^3.0" + }, + "suggest": { + "ext-iconv": "To convert non-UTF-8 strings to UTF-8 (or symfony/polyfill-iconv in case ext-iconv cannot be used).", + "ext-intl": "To show region name in time zone dump", + "symfony/console": "To use the ServerDumpCommand and/or the bin/var-dump-server script" + }, + "bin": [ + "Resources/bin/var-dump-server" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "files": [ + "Resources/functions/dump.php" + ], + "psr-4": { + "Symfony\\Component\\VarDumper\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony mechanism for exploring and dumping PHP variables", + "homepage": "https://symfony.com", + "keywords": [ + "debug", + "dump" + ], + "time": "2020-01-25T15:56:29+00:00" + }, { "name": "theseer/tokenizer", "version": "1.1.3", @@ -1970,5 +2045,7 @@ "prefer-stable": false, "prefer-lowest": false, "platform": [], - "platform-dev": [] + "platform-dev": { + "php": "5.6 || ^7.0" + } } diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..901c1b6 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,18 @@ + + + + + + tests + + + + + + src/ + + + diff --git a/src/Command/GenerateDrupal7Command.php b/src/Command/GenerateDrupal7Command.php new file mode 100644 index 0000000..41f4e3f --- /dev/null +++ b/src/Command/GenerateDrupal7Command.php @@ -0,0 +1,51 @@ +setDescription('Generate a new Drupal 7 module.') + ->addArgument('module-name', InputArgument::REQUIRED, 'The name of the module to create'); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $this->moduleName = $input->getArgument('module-name'); + + $this->ensureDirectoryDoesNotExist(); + + return 0; + } + + /** + * Ensure that the directory name for the module doesn't already exist. + */ + private function ensureDirectoryDoesNotExist() + { + if (is_dir($this->moduleName)) { + throw CannotCreateModuleException::directoryAlreadyExists(); + } + } +} diff --git a/src/Exception/CannotCreateModuleException.php b/src/Exception/CannotCreateModuleException.php new file mode 100644 index 0000000..f79e879 --- /dev/null +++ b/src/Exception/CannotCreateModuleException.php @@ -0,0 +1,11 @@ +execute([ + 'module-name' => 'my-existing-drupal-module', + ]); + } catch (CannotCreateModuleException $e) { + $this->addToAssertionCount(1); + } + + rmdir('my-existing-drupal-module'); + } +}