Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to laminas-cli commands #9

Merged
merged 5 commits into from
Mar 29, 2021

Conversation

weierophinney
Copy link
Member

This patch is a complete rewrite, while retaining the same functionality for end users of the command (albeit with different invocation).

First, it extracts a class, Composer, for operations around reading and parsing the composer.json file, adding and removing autoloading rules, writing changes to the file, and dumping autoload rules. The class uses several collaborators to do its work:

  • FileReaderInterface performs the operation of reading the composer.json file.
  • FileWriterInterface performs the operation of writing changes bacck to the composer.json file.
  • AutoloadDumpInterface performs the operation of calling composer dump-autoload.

Each has exactly one implementation:

  • FileReaderViaFileGetContents
  • FileWriterViaFilePutContents
  • AutoloadDumpViaSystemProcess

This approach makes testing the functionality far easier, as no actual filesystem operations need to be performed while testing.

The Command\Enable and Command\Disable classes were rewritten to Command\EnableCommand and Command\DisableCommand, respectively, and now inherit from a common symfony/console Command class extension, AbstractCommand. The AbstractCommand includes setup of common input options, input validation, and the logic for autodiscovery of the autoloader type to use.

The EnableCommand has an additional collaborator, MoveModuleClassFileInterface, which has the responsibility of moving Module.php files in the root of a module directory into its source subdirectory. This interface, like the others, has exactly one implementation, MoveModMoveModuleClassFileViaFileOperations.

A ConfigProvider and Module class allow exposing the commands via laminas-cli to MVC and Mezzio applications.

Fixes #4

This patch is a complete rewrite, while retaining the same functionality for end users of the command (albeit with different invocation).

First, it extracts a class, `Composer`, for operations around reading and parsing the `composer.json` file, adding and removing autoloading rules, writing changes to the file, and dumping autoload rules.
The class uses several collaborators to do its work:

- `FileReaderInterface` performs the operation of reading the `composer.json` file.
- `FileWriterInterface` performs the operation of writing changes bacck to the `composer.json` file.
- `AutoloadDumpInterface` performs the operation of calling `composer dump-autoload`.

Each has exactly one implementation:

- `FileReaderViaFileGetContents`
- `FileWriterViaFilePutContents`
- `AutoloadDumpViaSystemProcess`

This approach makes testing the functionality far easier, as no actual filesystem operations need to be performed while testing.

The `Command\Enable` and `Command\Disable` classes were rewritten to `Command\EnableCommand` and `Command\DisableCommand`, respectively, and now inherit from a common symfony/console `Command` class extension, `AbstractCommand`.
The `AbstractCommand` includes setup of common input options, input validation, and the logic for autodiscovery of the autoloader type to use.

The `EnableCommand` has an additional collaborator, `MoveModuleClassFileInterface`, which has the responsibility of moving `Module.php` files in the root of a module directory into its source subdirectory.
This interface, like the others, has exactly one implementation, `MoveModMoveModuleClassFileViaFileOperations`.

A `ConfigProvider` and `Module` class allow exposing the commands via laminas-cli to MVC and Mezzio applications.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
@weierophinney weierophinney added this to the 3.0.0 milestone Mar 23, 2021
@weierophinney weierophinney linked an issue Mar 23, 2021 that may be closed by this pull request
Tests all paths through the implementation, using vfsStream for file operations.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Tests all paths through implementation, using vfsStream for file operations.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Tests all paths, including separate tests for if the directory is not writable vs the file not writable.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
Adds an internal public property representing the system command, allowing the test case to slipstream in another callable to act as a spy.

Signed-off-by: Matthew Weier O'Phinney <matthew@weierophinney.net>
@weierophinney weierophinney merged commit 4cc2a1a into laminas:3.0.x Mar 29, 2021
@weierophinney weierophinney deleted the feature/laminas-cli branch March 29, 2021 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate this to become a laminas-cli command
1 participant