Conditions | 1 |
Paths | 1 |
Total Lines | 75 |
Code Lines | 51 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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 |
||
82 | public function testActionsBulk() |
||
83 | { |
||
84 | $content = '{"data":[ |
||
85 | {"type":"stock/type","attributes":{"stock.type.code":"slim","stock.type.label":"slim"}}, |
||
86 | {"type":"stock/type","attributes":{"stock.type.code":"slim2","stock.type.label":"slim"}} |
||
87 | ]}'; |
||
88 | $response = $this->call( 'POST', '/unittest/admin/jsonadm/stock/type', [], $content ); |
||
89 | |||
90 | $json = json_decode( (string) $response->getBody(), true ); |
||
91 | |||
92 | $this->assertNotNull( $json ); |
||
93 | $this->assertEquals( 201, $response->getStatusCode() ); |
||
94 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
95 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
||
96 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
||
97 | $this->assertEquals( 'slim', $json['data'][0]['attributes']['stock.type.label'] ); |
||
98 | $this->assertEquals( 'slim', $json['data'][1]['attributes']['stock.type.label'] ); |
||
99 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
100 | |||
101 | $ids = array( $json['data'][0]['attributes']['stock.type.id'], $json['data'][1]['attributes']['stock.type.id'] ); |
||
102 | |||
103 | |||
104 | $content = '{"data":[ |
||
105 | {"type":"stock/type","id":' . $ids[0] . ',"attributes":{"stock.type.label":"slim2"}}, |
||
106 | {"type":"stock/type","id":' . $ids[1] . ',"attributes":{"stock.type.label":"slim2"}} |
||
107 | ]}'; |
||
108 | $response = $this->call( 'PATCH', '/unittest/admin/jsonadm/stock/type', [], $content ); |
||
109 | |||
110 | $json = json_decode( (string) $response->getBody(), true ); |
||
111 | |||
112 | $this->assertNotNull( $json ); |
||
113 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
114 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
115 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][0]['attributes'] ); |
||
116 | $this->assertArrayHasKey( 'stock.type.id', $json['data'][1]['attributes'] ); |
||
117 | $this->assertEquals( 'slim2', $json['data'][0]['attributes']['stock.type.label'] ); |
||
118 | $this->assertEquals( 'slim2', $json['data'][1]['attributes']['stock.type.label'] ); |
||
119 | $this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
||
120 | $this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
||
121 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
122 | |||
123 | |||
124 | $getParams = ['filter' => ['&&' => [ |
||
125 | ['=~' => ['stock.type.code' => 'slim']], |
||
126 | ['==' => ['stock.type.label' => 'slim2']] |
||
127 | ]], |
||
128 | 'sort' => 'stock.type.code', 'page' => ['offset' => 0, 'limit' => 3] |
||
129 | ]; |
||
130 | $response = $this->call( 'GET', '/unittest/admin/jsonadm/stock/type', $getParams ); |
||
131 | |||
132 | $json = json_decode( (string) $response->getBody(), true ); |
||
133 | |||
134 | $this->assertNotNull( $json ); |
||
135 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
136 | $this->assertEquals( 2, count( $json['data'] ) ); |
||
137 | $this->assertEquals( 'slim', $json['data'][0]['attributes']['stock.type.code'] ); |
||
138 | $this->assertEquals( 'slim2', $json['data'][1]['attributes']['stock.type.code'] ); |
||
139 | $this->assertEquals( 'slim2', $json['data'][0]['attributes']['stock.type.label'] ); |
||
140 | $this->assertEquals( 'slim2', $json['data'][1]['attributes']['stock.type.label'] ); |
||
141 | $this->assertTrue( in_array( $json['data'][0]['attributes']['stock.type.id'], $ids ) ); |
||
142 | $this->assertTrue( in_array( $json['data'][1]['attributes']['stock.type.id'], $ids ) ); |
||
143 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
144 | |||
145 | |||
146 | $content = '{"data":[ |
||
147 | {"type":"stock/type","id":' . $ids[0] . '}, |
||
148 | {"type":"stock/type","id":' . $ids[1] . '} |
||
149 | ]}'; |
||
150 | $response = $this->call( 'DELETE', '/unittest/admin/jsonadm/stock/type', [], $content ); |
||
151 | |||
152 | $json = json_decode( (string) $response->getBody(), true ); |
||
153 | |||
154 | $this->assertNotNull( $json ); |
||
155 | $this->assertEquals( 200, $response->getStatusCode() ); |
||
156 | $this->assertEquals( 2, $json['meta']['total'] ); |
||
157 | } |
||
174 |