Conditions | 2 |
Paths | 2 |
Total Lines | 64 |
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 |
||
121 | public function testDtoBasics() |
||
122 | { |
||
123 | // Initialize classes to test |
||
124 | $action = new FormAction(false); |
||
125 | $action2 = clone $action; |
||
126 | $emptyAction = clone $action; |
||
127 | $order = new Order(false); |
||
128 | $order2 = clone $order; |
||
129 | $emptyOrder = clone $order; |
||
130 | $complextDto = new ComplexDto(false); |
||
131 | $complextDto2 = clone $complextDto; |
||
132 | |||
133 | $this->assertEquals($action, $action2, 'Error cloning dtos'); |
||
134 | $this->assertEquals($order, $order2, 'Error cloning dtos'); |
||
135 | $this->assertEquals($complextDto, $complextDto2, 'Error cloning dtos'); |
||
136 | |||
137 | // Populate tests |
||
138 | $exampleData = $this->getExampleData(); |
||
139 | |||
140 | // Manual creation vs hydration |
||
141 | $action->fromArray($exampleData['actions'][0]); |
||
142 | $action2->label = 'test1'; |
||
143 | $action2->url = 'test1'; |
||
144 | $action2->method = 'test1'; |
||
145 | $this->assertEquals($action, $action2, 'Different values from hydration'); |
||
146 | $this->assertEquals($action->toArray(), $action2->toArray(), 'Different values on export'); |
||
147 | |||
148 | $order->fromArray($exampleData['order']); |
||
149 | foreach ($exampleData['order'] as $field => $ord) { |
||
150 | $order2->addOrder($field, $ord); |
||
151 | } |
||
152 | $this->assertEquals($order, $order2, 'Different values from hydration'); |
||
153 | $this->assertEquals($order->toArray(), $order2->toArray(), 'Different values on export'); |
||
154 | $order2->removeOrder('test'); |
||
155 | $this->assertNotEquals($order, $order2, 'Remove field order failed in object'); |
||
156 | $this->assertNotEquals($order->toArray(), $order2->toArray(), 'Remove field order failed as array'); |
||
157 | |||
158 | // Multiple creation for dtos from array to create complex dto |
||
159 | $action1 = clone $emptyAction; |
||
160 | $action1->fromArray($exampleData['actions'][0]); |
||
161 | $complextDto->actions[] = $action1; |
||
162 | $action2 = clone $emptyAction; |
||
163 | $action2->fromArray($exampleData['actions'][1]); |
||
164 | $complextDto->actions[] = $action2; |
||
165 | $action3 = clone $emptyAction; |
||
166 | $action3->fromArray($exampleData['actions'][2]); |
||
167 | $complextDto->actions[] = $action3; |
||
168 | $emptyOrder->setOrder('test', Order::ASC); |
||
169 | $this->assertCount(1, $emptyOrder->getOrders(), 'Distinct number or orders created'); |
||
170 | $emptyOrder->addOrder('test2', Order::DESC); |
||
171 | $this->assertCount(2, $emptyOrder->getOrders(), 'Distinct number or orders added'); |
||
172 | $emptyOrder->addOrder('test3', Order::DESC); |
||
173 | $this->assertCount(3, $emptyOrder->getOrders(), 'Distinct number or orders added'); |
||
174 | $emptyOrder->removeOrder('test3'); |
||
175 | $this->assertCount(2, $emptyOrder->getOrders(), 'Distinct number or orders removed'); |
||
176 | $complextDto->order = $emptyOrder; |
||
177 | $complextDto->boolean = $exampleData['boolean']; |
||
178 | $complextDto->number = $exampleData['number']; |
||
179 | $complextDto->decimal = $exampleData['decimal']; |
||
180 | // Creation from import |
||
181 | $complextDto2->fromArray($exampleData); |
||
182 | $this->assertEquals($complextDto->jsonSerialize(), $complextDto2->jsonSerialize(), 'Different values on export'); |
||
183 | $this->assertEquals($complextDto->order->jsonSerialize(), $complextDto2->order->jsonSerialize(), 'Different order values on export'); |
||
184 | $this->assertEquals($complextDto->__toString(), $complextDto2->__toString(), 'Different values fot toString'); |
||
185 | } |
||
205 |