Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
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 |
||
27 | public function testAddOrder() |
||
28 | { |
||
29 | $request = new Request(); |
||
30 | |||
31 | $requestStack = $this->getMockWithoutConstructor(RequestStack::class); |
||
32 | $requestStack |
||
33 | ->expects($this->atLeastOnce()) |
||
34 | ->method('getMasterRequest') |
||
35 | ->willReturn($request) |
||
36 | ; |
||
37 | $admin = $this->getMockWithoutConstructor(AdminInterface::class); |
||
38 | $action = $this->getMockWithoutConstructor(ActionInterface::class); |
||
39 | |||
40 | $configuration = $this->getMockWithoutConstructor(ActionConfiguration::class); |
||
41 | $configuration |
||
42 | ->expects($this->once()) |
||
43 | ->method('getParameter') |
||
44 | ->with('order') |
||
45 | ->willReturn([ |
||
46 | 'id' => 'desc', |
||
47 | ]) |
||
48 | ; |
||
49 | |||
50 | $queryBuilder = $this->getMockWithoutConstructor(QueryBuilder::class); |
||
51 | $queryBuilder |
||
52 | ->expects($this->once()) |
||
53 | ->method('getRootAliases') |
||
54 | ->willReturn([ |
||
55 | 'entity', |
||
56 | ]) |
||
57 | ; |
||
58 | $queryBuilder |
||
59 | ->expects($this->once()) |
||
60 | ->method('addOrderBy') |
||
61 | ->with('entity.id', 'desc') |
||
62 | ; |
||
63 | |||
64 | $event = $this->getMockWithoutConstructor(DoctrineOrmFilterEvent::class); |
||
65 | $event |
||
66 | ->expects($this->once()) |
||
67 | ->method('getQueryBuilder') |
||
68 | ->willReturn($queryBuilder) |
||
69 | ; |
||
70 | $event |
||
71 | ->expects($this->once()) |
||
72 | ->method('getAdmin') |
||
73 | ->willReturn($admin) |
||
74 | ; |
||
75 | $admin |
||
76 | ->expects($this->once()) |
||
77 | ->method('getAction') |
||
78 | ->willReturn($action) |
||
79 | ; |
||
80 | $action |
||
81 | ->expects($this->once()) |
||
82 | ->method('getConfiguration') |
||
83 | ->willReturn($configuration) |
||
84 | ; |
||
85 | |||
86 | $subscriber = new ORMSubscriber($requestStack); |
||
87 | $subscriber->addOrder($event); |
||
88 | } |
||
89 | |||
145 |