1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cmobi\RabbitmqBundle\Tests\Routing\Loader; |
4
|
|
|
|
5
|
|
|
use Cmobi\RabbitmqBundle\Routing\Loader\YamlRpcLoader; |
6
|
|
|
use Cmobi\RabbitmqBundle\Tests\BaseTestCase; |
7
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; |
8
|
|
|
|
9
|
|
|
class YamlRpcLoaderTest extends BaseTestCase |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
View Code Duplication |
public function testLoadRouteInstance() |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
$parser = $this->createParser(); |
15
|
|
|
$path = __DIR__ . '/../../app/config'; |
16
|
|
|
$loader = new YamlRpcLoader($this->getContainer(), $path, $parser); |
|
|
|
|
17
|
|
|
$methodCollection = $loader->load('rpc_routing.yml'); |
18
|
|
|
$method = $methodCollection->get('cmobi_rabbitmq'); |
19
|
|
|
|
20
|
|
|
$this->assertInstanceOf('Cmobi\RabbitmqBundle\Routing\Method', $method); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
View Code Duplication |
public function testLoadRouteName() |
|
|
|
|
24
|
|
|
{ |
25
|
|
|
$parser = $this->createParser(); |
26
|
|
|
$path = __DIR__ . '/../../app/config'; |
27
|
|
|
$loader = new YamlRpcLoader($this->getContainer(), $path, $parser); |
|
|
|
|
28
|
|
|
$methodCollection = $loader->load('rpc_routing.yml'); |
29
|
|
|
$method = $methodCollection->get('cmobi_rabbitmq'); |
30
|
|
|
|
31
|
|
|
$this->assertSame('default', $method->getName()); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
private function createParser() |
35
|
|
|
{ |
36
|
|
|
$bundles = array( |
37
|
|
|
'FooBundle' => array($this->getBundle('TestBundle\FooBundle', 'FooBundle')), |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface'); |
41
|
|
|
$kernel |
42
|
|
|
->expects($this->any()) |
43
|
|
|
->method('getBundle') |
44
|
|
|
->will($this->returnCallback(function ($bundle) use ($bundles) { |
45
|
|
|
if (!isset($bundles[$bundle])) { |
46
|
|
|
throw new \InvalidArgumentException(sprintf('Invalid bundle name "%s"', $bundle)); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
return $bundles[$bundle]; |
50
|
|
|
})) |
51
|
|
|
; |
52
|
|
|
$bundles = [ |
53
|
|
|
'FooBundle' => $this->getBundle('Cmobi\RabbitmqBUndle\FooBundle', 'CmobiRabbitmqBundle'), |
54
|
|
|
]; |
55
|
|
|
$kernel |
56
|
|
|
->expects($this->any()) |
57
|
|
|
->method('getBundles') |
58
|
|
|
->will($this->returnValue($bundles)) |
59
|
|
|
; |
60
|
|
|
|
61
|
|
|
return new ControllerNameParser($kernel); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
private function getBundle($namespace, $name) |
65
|
|
|
{ |
66
|
|
|
$bundle = $this->getMock('Symfony\Component\HttpKernel\Bundle\BundleInterface'); |
67
|
|
|
$bundle->expects($this->any())->method('getName')->will($this->returnValue($name)); |
68
|
|
|
$bundle->expects($this->any())->method('getNamespace')->will($this->returnValue($namespace)); |
69
|
|
|
|
70
|
|
|
return $bundle; |
71
|
|
|
} |
72
|
|
|
} |
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.