Conditions | 1 |
Paths | 1 |
Total Lines | 68 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
22 | public function testCreateService() |
||
23 | { |
||
24 | $configuration = [ |
||
25 | 'pami_module' => [ |
||
26 | 'connection' => [ |
||
27 | 'default' => [ |
||
28 | 'host' => 'local.host', |
||
29 | 'scheme' => 'tcp://', |
||
30 | 'port' => 123, |
||
31 | 'username' => 'admin', |
||
32 | 'secret' => 'foosecret', |
||
33 | 'connect_timeout' => 123, |
||
34 | 'read_timeout' => 123, |
||
35 | ], |
||
36 | 'other' => [ |
||
37 | 'host' => 'local2.host', |
||
38 | 'scheme' => 'tcp://', |
||
39 | 'port' => 123, |
||
40 | 'username' => 'admin', |
||
41 | 'secret' => 'foosecret', |
||
42 | 'connect_timeout' => 123, |
||
43 | 'read_timeout' => 123, |
||
44 | ], |
||
45 | ], |
||
46 | 'client' => [ |
||
47 | 'default' => [ |
||
48 | 'connection' => 'default', |
||
49 | 'params' => [ |
||
50 | 'foo' => 'bar', |
||
51 | ], |
||
52 | ], |
||
53 | ], |
||
54 | ], |
||
55 | ]; |
||
56 | |||
57 | $connectionMock = $this->getMockBuilder('PAMI\\Client\\Impl\\ClientImpl') |
||
58 | ->disableOriginalConstructor() |
||
59 | ->setMethods(['registerEventListener']) |
||
60 | ->getMock(); |
||
61 | |||
62 | $connectionMock->expects(static::once()) |
||
63 | ->method('registerEventListener') |
||
64 | ->with(static::isInstanceOf('PamiModule\\Event\\EventForwarder')); |
||
65 | |||
66 | $serviceManager = $this->moduleLoader->getServiceManager(); |
||
67 | $serviceManager->setAllowOverride(true); |
||
68 | |||
69 | $config = $serviceManager->get('config'); |
||
70 | $config = ArrayUtils::merge($config, $configuration); |
||
71 | $serviceManager->setService('config', $config); |
||
72 | $serviceManager->setService('pami.connection.default', $connectionMock); |
||
73 | |||
74 | $factory = new ClientFactory('default'); |
||
75 | $service = $factory->createService($serviceManager); |
||
76 | |||
77 | static::assertInstanceOf('PamiModule\\Service\\Client', $service); |
||
78 | static::assertEquals(['foo' => 'bar'], $service->getParams()); |
||
79 | static::assertInstanceOf('Zend\\EventManager\\EventManager', $service->getEventManager()); |
||
80 | |||
81 | // Test with client not in in configuration |
||
82 | |||
83 | $factory = new ClientFactory('other'); |
||
84 | $service = $factory->createService($serviceManager); |
||
85 | |||
86 | static::assertInstanceOf('PamiModule\\Service\\Client', $service); |
||
87 | static::assertEquals([], $service->getParams()); |
||
88 | static::assertInstanceOf('Zend\\EventManager\\EventManager', $service->getEventManager()); |
||
89 | } |
||
90 | } |
||
91 |