Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 51 |
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 |
||
21 | public function testHandlerRequest(): void |
||
22 | { |
||
23 | $listMapperMock = $this->createMock(ListMapper::class); |
||
24 | $filterMapperMock = $this->createMock(FilterMapper::class); |
||
25 | $formMock = $this->createMock(FormInterface::class); |
||
26 | $listFieldMock = $this->createMock(ListField::class); |
||
27 | $listFieldMock2 = $this->createMock(ListField::class); |
||
28 | $listFieldMock->expects($this->exactly(2)) |
||
29 | ->method('setOption') |
||
30 | ->withConsecutive( |
||
31 | ['sort_value', 'DESC'], |
||
32 | ['lazy', false] |
||
33 | ); |
||
34 | $listFieldMock->expects($this->once()) |
||
35 | ->method('getId') |
||
36 | ->willReturn('test_id'); |
||
37 | $listMapperMock->expects($this->once()) |
||
38 | ->method('getFields') |
||
39 | ->willReturn(new ArrayCollection([$listFieldMock2])); |
||
40 | $listFieldMock2->expects($this->once()) |
||
41 | ->method('getId') |
||
42 | ->willReturn('another_id'); |
||
43 | $listFieldMock2->expects($this->once()) |
||
44 | ->method('setOption') |
||
45 | ->with('sort_value', null); |
||
46 | $listMapperMock->expects($this->once()) |
||
47 | ->method('get') |
||
48 | ->willReturn($listFieldMock); |
||
49 | $formMock->expects($this->once()) |
||
50 | ->method('handleRequest'); |
||
51 | $formMock->expects($this->once()) |
||
52 | ->method('isSubmitted') |
||
53 | ->willReturn(true); |
||
54 | $formMock->expects($this->once()) |
||
55 | ->method('isValid') |
||
56 | ->willReturn(true); |
||
57 | $formMock->expects($this->once()) |
||
58 | ->method('getData') |
||
59 | ->willReturn(['field1' => 'val1', 'field2' => 'val2']); |
||
60 | $filterFieldMock1 = $this->createMock(FilterField::class); |
||
61 | $filterFieldMock2 = $this->createMock(FilterField::class); |
||
62 | $filterFieldMock1->expects($this->once()) |
||
63 | ->method('setValue') |
||
64 | ->with('val1'); |
||
65 | $filterFieldMock2->expects($this->once()) |
||
66 | ->method('setValue') |
||
67 | ->with('val2'); |
||
68 | $filterMapperMock->expects($this->exactly(2)) |
||
69 | ->method('get') |
||
70 | ->willReturnMap([ |
||
71 | ['field1', $filterFieldMock1], |
||
72 | ['field2', $filterFieldMock2] |
||
73 | ]); |
||
74 | |||
75 | $requestHandler = $this->getRequestHandler([['sort', null, ['field2' => 'invalid_sort', 'field1' => 'desc']]], [], [['sort', 'sort']]); |
||
76 | $requestHandler->handleRequest($listMapperMock, $filterMapperMock, $formMock); |
||
77 | } |
||
141 |