Conditions | 1 |
Paths | 1 |
Total Lines | 58 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 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 |
||
78 | public function testComposeTriggersEvents() |
||
79 | { |
||
80 | $renderer = $this->getMock('MtMail\Renderer\RendererInterface', ['render']); |
||
81 | $renderer->expects($this->once())->method('render')->with($this->isInstanceOf('Zend\View\Model\ModelInterface')) |
||
82 | ->will($this->returnValue('MAIL_BODY')); |
||
83 | |||
84 | $em = new EventManager(); |
||
85 | $listener = function ($event) { |
||
86 | $this->assertInstanceof( |
||
87 | ComposerEvent::class, |
||
88 | $event, |
||
89 | 'Failed asserting event instance of ' . get_class($event) . ' is of type ' . ComposerEvent::class |
||
90 | ); |
||
91 | $this->composeEventsTriggered[] = $event->getName(); |
||
92 | }; |
||
93 | |||
94 | $em->attach( |
||
95 | ComposerEvent::EVENT_COMPOSE_PRE, |
||
96 | $listener |
||
97 | ); |
||
98 | $em->attach( |
||
99 | ComposerEvent::EVENT_HEADERS_PRE, |
||
100 | $listener |
||
101 | ); |
||
102 | $em->attach( |
||
103 | ComposerEvent::EVENT_HEADERS_POST, |
||
104 | $listener |
||
105 | ); |
||
106 | $em->attach( |
||
107 | ComposerEvent::EVENT_HTML_BODY_PRE, |
||
108 | $listener |
||
109 | ); |
||
110 | $em->attach( |
||
111 | ComposerEvent::EVENT_HTML_BODY_POST, |
||
112 | $listener |
||
113 | ); |
||
114 | $em->attach( |
||
115 | ComposerEvent::EVENT_COMPOSE_POST, |
||
116 | $listener |
||
117 | ); |
||
118 | |||
119 | $service = new Composer($renderer); |
||
120 | $service->setEventManager($em); |
||
121 | $template = new HtmlTemplate(); |
||
122 | $service->compose([], $template, new ViewModel()); |
||
123 | |||
124 | $this->assertEquals( |
||
125 | [ |
||
126 | ComposerEvent::EVENT_COMPOSE_PRE, |
||
127 | ComposerEvent::EVENT_HEADERS_PRE, |
||
128 | ComposerEvent::EVENT_HEADERS_POST, |
||
129 | ComposerEvent::EVENT_HTML_BODY_PRE, |
||
130 | ComposerEvent::EVENT_HTML_BODY_POST, |
||
131 | ComposerEvent::EVENT_COMPOSE_POST, |
||
132 | ], |
||
133 | $this->composeEventsTriggered |
||
134 | ); |
||
135 | } |
||
136 | |||
171 |