-
Notifications
You must be signed in to change notification settings - Fork 181
/
Copy pathsfParameterResolverTest.php
58 lines (44 loc) · 1.58 KB
/
sfParameterResolverTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please component the LICENSE
* file that was distributed with this source code.
*/
require_once(__DIR__.'/../../bootstrap/unit.php');
require_once($_test_dir.'/unit/sfContextMock.class.php');
require_once($_test_dir.'/unit/sfNoRouting.class.php');
$t = new lime_test(3);
class MyService {
public function execute()
{
return "success";
}
}
class myComponent extends sfComponent
{
function execute($request, MyService $service = null) {
return $service->execute();
}
function executeNamed($request, MyService $service) {
return $service->execute();
}
function executeFoo($request, $options = "foo") {
return $options;
}
}
$context = sfContext::getInstance(array(
'routing' => 'sfNoRouting',
'request' => 'sfWebRequest',
));
$context->getServiceContainer()->setService("MyService", new MyService());
$component = new myComponent($context, 'module', 'action');
$resolver = new sfParameterResolver($context->getServiceContainer());
$resolver
->setRequest($context->getRequest())
->setComponent($component);
$t->diag('execute()');
$t->is($resolver->execute(), "success", 'without arguments executes default ->execute() method and resolves required dependencies');
$t->is($resolver->execute('executeNamed'), "success", 'can execute an arbitrary method and resolves required dependencies');
$t->is($resolver->execute('executeFoo'), "foo", 'uses default value if no type hint is present');