Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Added new tool - expressive-module (#8 and #9) #12

Merged
merged 29 commits into from
Mar 1, 2017
Merged

Added new tool - expressive-module (#8 and #9) #12

merged 29 commits into from
Mar 1, 2017

Conversation

michalbundyra
Copy link
Member

@michalbundyra michalbundyra commented Feb 17, 2017

New tool vendor/bin/expressive-module

Tool provide following commands:

  • create - create skeleton of the expressive module and register it
  • register - register module in configuration and composer autoloading
  • deregister - deregister module from configuration and composer autoloading

Tool accept following arguments:

  • --composer|-c path to composer binary
  • --modules-path|-p - path to modules directory

TODO:

Resolves #8 and #9

@weierophinney
Copy link
Member

Syntax is perfect - exactly what I'd expect! Looking forward to reviewing the final iterations!

@michalbundyra michalbundyra changed the title [WIP] Added new tool - expressive-module (#8 and #9) Added new tool - expressive-module (#8 and #9) Feb 22, 2017
@michalbundyra
Copy link
Member Author

@weierophinney It's ready for review, tests are failing but some of them are fixed in #10, so it should be merged first. Of course it needs also zend-component-install 0.7.0 release and update requirements in composer.json.
What is missing here - messages on success. Now we don't have any messages, so it's confusing if it was done successfully or not. Just response code is 0 on success. I need to think about it a bit more how to do it nicely, or maybe you have an idea?

@weierophinney
Copy link
Member

@webimpress I've tagged zend-component-installer 0.7.0 at this time, and merged #10.

As for messages, how about:

  • "Created module <module name> in <path>, and generated autoloading rules"
  • "Registered autoloading rules and added configuration entry for module <module>"
  • "Removed autoloading rules and configuration entries for module <module>"

Tool provide following commands:
- "create" - create skeleton of the expressive module and register it
- "register" - register module in configuration and composer autoloading
- "deregister" - deregister module from configuration and composer
  autoloading

Tool accept following arguments:
- "--composer|-c" path to composer binary
- "--modules-path|-p" - path to modules directory
Eliminated dependency of composer/composer package.
Now to inject/remove methods we don't need to pass
IOInterface.
Redirect stderr to stdout 2>&1
Works also on Windows.
Added catching RuntimeException from zf-composer-autoloading
and throwing module RuntimeException.
Now we have then consistent interface, and process method throws
only exception from the module.

Updated PHPDocs to reflect these changes.
Now commands from zfcampus/zf-composer-autoloading are invoked
via "process" method instead of "__invoke".
Also disabled moving module class for the module on enabling autoloading.
I've notice issue with constant and Mockery.
If we use Mockery to mock class, than we can't access to the constants.
This change uses constants from another class, so we have access
on mocking ConfigAggregatorInjector.
- zendframework/zend-component-installer ^0.7
- zf-composer-autoloading ^2.0
@michalbundyra
Copy link
Member Author

@weierophinney Rebased, used latest stable dependencies and added success messages as suggested. Ready for review.

Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fantastic, @webimpress ! There are a few minor changes I've suggested, and one larger one that, honestly, I can go either way on (whether or not to memorize $modulePath). Let me know how you want to proceed on that, and I can merge.

composer.json Outdated
@@ -40,7 +44,8 @@
"bin": [
"bin/expressive-migrate-original-messages",
"bin/expressive-pipeline-from-config",
"bin/expressive-scan-for-error-middleware"
"bin/expressive-scan-for-error-middleware",
"bin/expressive-module"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be alphabetized.

/**
* The configuration provider for the %1$s module
*
* @see https://docs.zendframework.com/zend-component-installer/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice touch! Linking to the documentation will definitely assist new developers.

*/
private function createDirectoryStructure($moduleName)
{
if (file_exists($this->modulePath)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that $modulePath is calculated by process(), perhaps it should be passed as an argument to each of this method and createConfigProvider(), instead of memoized as a property? That would be one less state for the instance to track.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed - property removed, now method has two parameters.

<info>Commands:</info>

<info>help</info> Display this help/usage message
<info>create</info> Create skeleton of the expressive module and register it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/skeleton of/source tree for/


<info>help</info> Display this help/usage message
<info>create</info> Create skeleton of the expressive module and register it
<info>register</info> Register module in configuration and composer autoloading
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Register module in application configuration, and enable autoloading of module via composer."

<info>help</info> Display this help/usage message
<info>create</info> Create skeleton of the expressive module and register it
<info>register</info> Register module in configuration and composer autoloading
<info>deregister</info> Deregister module from configuration and composer autoloading
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Deregister module from application configuration, and disable autoloading of module via composer."

{
$baseModulePath = sprintf('%s/my-modules/MyApp', $this->dir->url());

$mkdir = $this->getFunctionMock('Zend\Expressive\Tooling\Module\Command', 'mkdir');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was not aware of getFunctionMock()! Awesome!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please not this is not from PHPUnit but from php-mock library. Integration with PHPUnit is via php-mock/php-mock-phpunit.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, okay - did you add that dependency, or does PHPUnit depend on it itself? Either way, it's a nice library to know about.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I added:

"php-mock/php-mock-phpunit": "^2.0 || ^1.1.2",

There is also integration library with prophecy and mocker.
https://github.com/php-mock
I've chosen integration with PHPUnit as this is the main testing library. I know that many mocking we are doing recently using prophecy, so maybe better choice will be php-mock-prophecy?
Here is the library with the main functionality:
https://github.com/php-mock/php-mock

namespace ZendTest\Expressive\Tooling\Module\Command;

use Mockery;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what allows you to not need to specify @runInSeparateProcess for tests that overload classes via Mockery?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... this is recommended in Mockery documentation:
http://docs.mockery.io/en/latest/reference/phpunit_integration.html

I was trying to remove @runInSeparateProcess but some tests on some versions (php versions/dependencies) were failing. As you can note in some tests we still have this annotation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've somehow missed that documentation page previously, so, again, a nice thing to know about!

Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look perfect! Thanks, @webimpress !

@weierophinney weierophinney added this to the 0.3.0 milestone Mar 1, 2017
@weierophinney weierophinney self-assigned this Mar 1, 2017
@weierophinney weierophinney merged commit b3952af into zendframework:master Mar 1, 2017
weierophinney added a commit that referenced this pull request Mar 1, 2017
Added new tool - expressive-module (#8 and #9)
weierophinney added a commit that referenced this pull request Mar 1, 2017
weierophinney added a commit that referenced this pull request Mar 1, 2017
Close #12
Fixes #8
Fixes #9
@michalbundyra michalbundyra deleted the feature/module-tools branch March 1, 2017 16:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants