-
Notifications
You must be signed in to change notification settings - Fork 8
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
Implement Closure
dispatcher.
#24
base: master
Are you sure you want to change the base?
Conversation
return $return; | ||
} | ||
|
||
protected function populateVariables(&$variables, $rtv) |
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.
Add API documentation please.
This is a draft and I made a very very quick/high review. Please, tell me when a deeper review is required. |
For sure it is a draft, thanks for the review... I'll make it cleaner quickly with a better atoum integration. |
@Hywan just one question about function mock... I tried to use it but I don't understand how to... I tried to found some doc in atoum but there is only native function mocks... Here my code sample : $this->function->dispatchedMethod = function($test, $foo, $bar) {
$test
->string($foo)
->isEqualTo('foo')
->string($bar)
->isEqualTo('bar');
}; I tried to call the Is there any example of that kind of use ? |
Hello @Hywan I need more help about that test cases, I tried different things with As an example, I write this in a test case : $this
->given(
$this->function->dispatchedMethod = function($test, $foo, $bar) {
$test
->string($foo)
->isEqualTo('foo')
->string($bar)
->isEqualTo('bar');
},
$router = new Router\Cli(),
$router->get(
'a',
'(?<_call>dispatchedMethod) ' .
'(?<foo>foo) ' .
'(?<bar>bar)'
),
$this->route(
$router,
'dispatchedMethod foo bar'
),
$dispatcher = new LUT\Closure(),
$dispatcher->getParameters()->setParameters([
'synchronous.call' => '(:call:U:)',
'synchronous.able' => '(:able:)'
])
)
->when($dispatcher->dispatch($router)); I'm sure that this code define the function mock for It's more about atoum behaviour than my PR, but I'm sure that you know atoum better than me 😄 |
Sorry for the late reply. Please, can you explain what do you want to test and what your test case does? |
I am assigning @osaris since I have too much work. |
Hello @Hywan, Don't worry for the delay, I was just thinking about this PR yesterday and I've added a comment 😄 |
Here the requested details on my test case which is built to test the behaviour of the closure dispatcher :
I've took the logic from the My main problem here is that my registered
So I don't know how to use my mocked function to deal with my test needs... |
Hello, any news about this PR ? I'm sorry but I'm lost in the "atoum" features... |
ping @osaris :-) |
Hello @Jir4, do you know atoum function mock enough to help me here ? |
I'm not aware about atoum :/ I don't use it at all. |
@shulard |
@Hywan, so my code is right here... I'm already able to create the mock function but I can't use it through my dispatcher. In my test case, I try to |
Are you trying to mock a function or a method? If this is a method, then: $this->calling($object)->$method = function (…) { … } |
I try to mock a function to test the |
@shulard Show me what piece of code you are trying to test please :-). |
@Hywan: Of course 😄 class Closure extends Test\Unit\Suite
{
public function case_function_name_in_rule_pattern()
{
$this
->given(
$this->function->dispatchedMethod = function($test, $foo, $bar) {
$test
->string($foo)
->isEqualTo('foo')
->string($bar)
->isEqualTo('bar');
},
$router = new Router\Cli(),
$router->get(
'a',
'(?<_call>dispatchedMethod) ' .
'(?<foo>foo) ' .
'(?<bar>bar)'
),
$this->route(
$router,
'dispatchedMethod foo bar'
),
$dispatcher = new LUT\Closure(),
$dispatcher->getParameters()->setParameters([
'synchronous.call' => '(:call:U:)',
'synchronous.able' => '(:able:)'
])
)
->when($dispatcher->dispatch($router));
}
protected function route(Router $router, $uri, array $extraVariables = [])
{
$router->route($uri);
$theRule = &$router->getTheRule();
$theRule[$router::RULE_VARIABLES]['test'] = $this;
foreach ($extraVariables as $name => $value) {
$theRule[$router::RULE_VARIABLES][$name] = $value;
}
return $router;
}
} With that code I just get the atoum error: I mock the method and try to use it in the dispatcher. Before using the mocked function, I've created some namespaced functions in my test file... It works but was not really clean... An example here |
Can you show me the SUT (the method you are trying to test) please? I don't understand why you're mocking your own function. |
I'm trying to test the This method must be able to dispatch to a Closure or a function. With this test case I try to validate that the Am I missing the whole thing ? Maybe my testing strategy is not the good one ? |
So you don't need to mock any thing. You have a function that will be called by the dispatcher. |
Yes but I need to create that function somewhere... Maybe I can use a PHP function instead of creating a useless one. Then validate the result of the call. |
@shulard You can use your own function, of course. To call it, don't forget the namespace ( |
Super 👍 |
34963f3
to
894848c
Compare
Hello @Hywan, I've rebased my branch on master and update the test suite to avoid useless function creation. |
Is it ready for a review? |
Yes I think ! I think we'll need a little refactoring because there is duplication between |
Looks correct, but I am waiting on a first review from @osaris :-)! |
Hey guys, I'm here :) It looks good for me too ! Thanks for testing your feature. |
Related to #11 |
Will merge it as soon as possible. |
Hello @Hywan, Any news about that PR ? |
Also refactor some code duplication around `Kit
Adaptation of the `ClassMethod` test suite.
894848c
to
77170fd
Compare
Hello,
I've tried to work on the #15 issue. The code is moved from the
Basic
to a newClosure
dispatcher. I've also added a test suite based on theClassMethod
one.I'm not totally fine because there is a lot of code duplication between the
ClassMethod
, theClosure
and also in theClosure
... It's a draft which work, I think ready for review 😄