| Conditions | 1 |
| Paths | 1 |
| Total Lines | 79 |
| 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 |
||
| 18 | public function testInvoke() |
||
| 19 | { |
||
| 20 | $request = new Request(); |
||
| 21 | $entity = new TestSimpleEntity(); |
||
| 22 | |||
| 23 | $actionConfiguration = $this->getMockWithoutConstructor(ActionConfiguration::class); |
||
| 24 | $actionConfiguration |
||
| 25 | ->method('getParameter') |
||
| 26 | ->willReturnMap([ |
||
| 27 | ['form', 'MyForm'], |
||
| 28 | ['form_options', [ |
||
| 29 | 'required' => false, |
||
| 30 | ]], |
||
| 31 | ]) |
||
| 32 | ; |
||
| 33 | |||
| 34 | $admin = $this->getMockWithoutConstructor(AdminInterface::class); |
||
| 35 | $admin |
||
| 36 | ->expects($this->once()) |
||
| 37 | ->method('handleRequest') |
||
| 38 | ->with($request) |
||
| 39 | ; |
||
| 40 | $admin |
||
| 41 | ->expects($this->once()) |
||
| 42 | ->method('getEntities') |
||
| 43 | ->willReturn([ |
||
| 44 | $entity, |
||
| 45 | ]) |
||
| 46 | ; |
||
| 47 | |||
| 48 | $form = $this->getMockWithoutConstructor(FormInterface::class); |
||
| 49 | $form |
||
| 50 | ->expects($this->once()) |
||
| 51 | ->method('handleRequest') |
||
| 52 | ->with($request) |
||
| 53 | ; |
||
| 54 | |||
| 55 | $filterForm = $this->getMockWithoutConstructor(FormInterface::class); |
||
| 56 | $filterForm |
||
| 57 | ->expects($this->once()) |
||
| 58 | ->method('handleRequest') |
||
| 59 | ; |
||
| 60 | |||
| 61 | $formFactory = $this->getMockWithoutConstructor(FormFactoryInterface::class); |
||
| 62 | $formFactory |
||
| 63 | ->expects($this->once()) |
||
| 64 | ->method('create') |
||
| 65 | ->with('MyForm', [ |
||
| 66 | $entity, |
||
| 67 | ], [ |
||
| 68 | 'required' => false, |
||
| 69 | ]) |
||
| 70 | ->willReturn($form) |
||
| 71 | ; |
||
| 72 | |||
| 73 | $responder = $this->getMockWithoutConstructor(ListResponder::class); |
||
| 74 | $responder |
||
| 75 | ->method('respond') |
||
| 76 | ->with($actionConfiguration, $admin, $form, $filterForm) |
||
| 77 | ; |
||
| 78 | |||
| 79 | $builder = $this->getMockWithoutConstructor(FilterFormBuilder::class); |
||
| 80 | $builder |
||
| 81 | ->method('build') |
||
| 82 | ->with($actionConfiguration) |
||
| 83 | ->willReturn($filterForm) |
||
| 84 | ; |
||
| 85 | |||
| 86 | $action = new ListAction( |
||
| 87 | 'list', |
||
| 88 | $formFactory, |
||
| 89 | $responder, |
||
| 90 | $builder |
||
| 91 | ); |
||
| 92 | $action->setConfiguration($actionConfiguration); |
||
| 93 | $action->setAdmin($admin); |
||
| 94 | |||
| 95 | $action->__invoke($request); |
||
| 96 | } |
||
| 97 | } |
||
| 98 |