1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Tests\Routing; |
4
|
|
|
|
5
|
|
|
use Cmobi\RabbitmqBundle\Routing\Method; |
6
|
|
|
use Cmobi\RabbitmqBundle\Routing\MethodCollection; |
7
|
|
|
use Cmobi\RabbitmqBundle\Routing\MethodRouter; |
8
|
|
|
use Cmobi\RabbitmqBundle\Tests\BaseTestCase; |
9
|
|
|
|
10
|
|
|
class RpcRouterTest extends BaseTestCase |
11
|
|
|
{ |
12
|
|
View Code Duplication |
public function testRouterDump() |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$methodCollection = new MethodCollection(); |
15
|
|
|
$method = new Method(null, 'foo'); |
16
|
|
|
$methodCollection->add('foo', $method); |
17
|
|
|
$sc = $this->getServiceContainer($methodCollection); |
18
|
|
|
$sc->setParameter('parameter.foo', 'foo'); |
19
|
|
|
|
20
|
|
|
$router = new MethodRouter($sc, 'foo'); |
21
|
|
|
$parameters = $router->match('foo'); |
22
|
|
|
|
23
|
|
|
$this->assertEquals('foo', $parameters['_method']); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
View Code Duplication |
public function testRouterRpcService() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$methodCollection = new MethodCollection(); |
29
|
|
|
$method = new Method(null, 'foo'); |
30
|
|
|
$methodCollection->add('foo', $method); |
31
|
|
|
$sc = $this->getServiceContainer($methodCollection); |
32
|
|
|
$sc->setParameter('parameter.foo', 'foo'); |
33
|
|
|
|
34
|
|
|
$router = new MethodRouter($sc, 'foo'); |
35
|
|
|
|
36
|
|
|
$method = $router->getMethodCollection()->get('foo'); |
37
|
|
|
|
38
|
|
|
$this->assertEquals( |
39
|
|
|
'foo', |
40
|
|
|
$method->getName() |
41
|
|
|
); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param MethodCollection $methods |
46
|
|
|
* |
47
|
|
|
* @return \Symfony\Component\DependencyInjection\Container |
48
|
|
|
*/ |
49
|
|
|
private function getServiceContainer(MethodCollection $methods) |
50
|
|
|
{ |
51
|
|
|
$loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); |
52
|
|
|
|
53
|
|
|
$loader |
54
|
|
|
->expects($this->any()) |
55
|
|
|
->method('load') |
56
|
|
|
->will($this->returnValue($methods)) |
57
|
|
|
; |
58
|
|
|
|
59
|
|
|
$sc = $this->getMock('Symfony\\Component\\DependencyInjection\\Container', array('get')); |
60
|
|
|
|
61
|
|
|
$sc |
62
|
|
|
->expects($this->once()) |
63
|
|
|
->method('get') |
64
|
|
|
->will($this->returnValue($loader)) |
65
|
|
|
; |
66
|
|
|
|
67
|
|
|
return $sc; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.