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