-
Notifications
You must be signed in to change notification settings - Fork 61
Refactor for new service and event manager #8
Refactor for new service and event manager #8
Conversation
@@ -21,7 +21,7 @@ | |||
* | |||
* @return bool | |||
*/ | |||
public function isValid(); | |||
public function __invoke(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be changed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what else can be done. These things end up in EventManager::triggerListeners()
, which does a $listener($event)
, not a $listener->isValid()
or a call_user_func($listener)
. Suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous format was correct. Implementators was using [new $validator($data), 'isValid']
which is callable too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I'll be. Right you are. Must've been something else in there breaking all the tests for validators then.
As far as I see we could decouple Could you refactor the test and mock the dependency in a different PR? |
|
||
$manager->start(); | ||
|
||
$this->assertEquals(1, $manager->getValidatorChain()->getListeners('session.validate')->count()); | ||
$chain = $manager->getValidatorChain(); | ||
$r = new \ReflectionMethod($chain, 'getListenersByEventName'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see an alternative to this using the public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Maks3w - for tests, I've been using a similar pattern in other components.
The getListeners and getEvents methods only really existed for testing
purposes, which is why they were removed during the refactor. The downside
is, of course, that testing now often needs to rely on reflection to
validate expectations. My point is: there isn't a way currently to verify
using the public API at this point other than triggering the event, which
often has side effects. Reflection should be fine here.
On Oct 25, 2015 2:09 PM, "Maks3w" notifications@github.com wrote:
In test/Service/SessionManagerFactoryTest.php
#8 (comment)
:$manager->start();
$this->assertEquals(1, $manager->getValidatorChain()->getListeners('session.validate')->count());
$chain = $manager->getValidatorChain();
$r = new \ReflectionMethod($chain, 'getListenersByEventName');
I would like to see an alternative to this using the public API.
—
Reply to this email directly or view it on GitHub
https://github.com/zendframework/zend-session/pull/8/files#r42948778.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And spy EventManagerInterface::attach was called?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Maks3w Correct. That's what the reflection calls are doing, essentially; verifying that the factory attached listeners for specific event names.
* @param callable $callback | ||
* @param int $priority | ||
* @return \Zend\Stdlib\CallbackHandler | ||
*/ | ||
public function attach($event, $callback = null, $priority = 1) | ||
public function attach($eventName, callable $callback, $priority = 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the callable typehint make impossible to be array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not true; arrays can be php callables. [$instance, $methodName]
validates
as callable when:
$instance
is an object where$methodName
is a publicly callable
method, OR$instance
is an object or class name and$methodName
is a publicly
callable static method.
On Oct 25, 2015 2:30 PM, "Maks3w" notifications@github.com wrote:
In src/ValidatorChain.php
#8 (comment)
:* @param callable $callback * @param int $priority * @return \Zend\Stdlib\CallbackHandler */
- public function attach($event, $callback = null, $priority = 1)
- public function attach($eventName, callable $callback, $priority = 1)
Note the callable typehint make impossible to be array
—
Reply to this email directly or view it on GitHub
https://github.com/zendframework/zend-session/pull/8/files#r42949108.
I've updated the initial description of this PR to reflect the changes made following @Maks3w review. Anything more need doing, or can I go out and play with expressive now ;) |
Heya, this has kind of slipped of my radar. But it's useful if you're using zend-session with dev versions of zend-eventmanager. I'm pretty sure the coverage decrease isn't down to me. Is there anything else you can see? |
@@ -9,8 +9,8 @@ | |||
|
|||
namespace Zend\Session\Service; | |||
|
|||
use Zend\ServiceManager\AbstractFactoryInterface; | |||
use Zend\ServiceManager\ServiceLocatorInterface; | |||
use Interop\Container\ContainerInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
container-interop should be added as a dev dependency. Yes, the SM depends on it as well, but you're explicitly referencing it in code here, which makes it another dependency.
@kynx Are you able/willing to address the feedback I've posted today? If not, let me know, and one of us will create a new PR that pulls in your changes and finishes them. If you are, make sure you look through the PRs merged to the SM and EM (mostly the SM) since you started this pull request, as we've made a number of changes that simplify the migration tremendously (e.g., it's no longer immutable; Thanks in advance! |
@weierophinney I'm pretty stacked out until the weekend, so please feel free to take this over if anyone has time before then. Cheers! |
@kynx I merged this PR including the feedbacks of @weierophinney and fixed some unit test. |
This PR contains changes to get zend-session working with the new zend-servicemanager and zend-eventmanager.
I've tried to keep changes to a minimum. The main points are: