Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
18 | class SectionHandlerTest extends HandlerTest |
||
19 | { |
||
20 | /** |
||
21 | * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::assign |
||
22 | */ |
||
23 | View Code Duplication | public function testAssign() |
|
54 | |||
55 | /** |
||
56 | * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::assignmentsCount |
||
57 | */ |
||
58 | public function testAssignmentsCount() |
||
80 | |||
81 | /** |
||
82 | * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::policiesCount |
||
83 | */ |
||
84 | public function testPoliciesCount() |
||
106 | |||
107 | /** |
||
108 | * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::countRoleAssignmentsUsingSection |
||
109 | */ |
||
110 | public function testCountRoleAssignmentsUsingSection() |
||
132 | |||
133 | /** |
||
134 | * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::create |
||
135 | */ |
||
136 | View Code Duplication | public function testCreate() |
|
137 | { |
||
138 | $this->loggerMock->expects($this->once())->method('logCall'); |
||
139 | |||
140 | $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler'); |
||
141 | $this->persistenceHandlerMock |
||
142 | ->expects($this->once()) |
||
143 | ->method('sectionHandler') |
||
144 | ->will($this->returnValue($innerHandlerMock)); |
||
145 | |||
146 | $innerHandlerMock |
||
147 | ->expects($this->once()) |
||
148 | ->method('create') |
||
149 | ->with('Intranet', 'intranet') |
||
150 | ->will( |
||
151 | $this->returnValue( |
||
152 | new SPISection( |
||
153 | array('id' => 33, 'name' => 'Intranet', 'identifier' => 'intranet') |
||
154 | ) |
||
155 | ) |
||
156 | ); |
||
157 | |||
158 | $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
||
159 | $this->cacheMock |
||
160 | ->expects($this->once()) |
||
161 | ->method('getItem') |
||
162 | ->with('section', 33) |
||
163 | ->will($this->returnValue($cacheItemMock)); |
||
164 | |||
165 | $cacheItemMock |
||
166 | ->expects($this->once()) |
||
167 | ->method('set') |
||
168 | ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Section')) |
||
169 | ->will($this->returnValue($cacheItemMock)); |
||
170 | |||
171 | $cacheItemMock |
||
172 | ->expects($this->once()) |
||
173 | ->method('save') |
||
174 | ->with(); |
||
175 | |||
176 | $cacheItemMock |
||
177 | ->expects($this->never()) |
||
178 | ->method('get'); |
||
179 | |||
180 | $handler = $this->persistenceCacheHandler->sectionHandler(); |
||
181 | $handler->create('Intranet', 'intranet'); |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::delete |
||
186 | */ |
||
187 | public function testDelete() |
||
214 | |||
215 | /** |
||
216 | * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::load |
||
217 | */ |
||
218 | View Code Duplication | public function testLoadCacheIsMiss() |
|
219 | { |
||
220 | $this->loggerMock->expects($this->once())->method('logCall'); |
||
221 | $cacheItemMock = $this->getMock('Stash\Interfaces\ItemInterface'); |
||
222 | $this->cacheMock |
||
223 | ->expects($this->once()) |
||
224 | ->method('getItem') |
||
225 | ->with('section', 33) |
||
226 | ->will($this->returnValue($cacheItemMock)); |
||
227 | |||
228 | $cacheItemMock |
||
229 | ->expects($this->once()) |
||
230 | ->method('isMiss') |
||
231 | ->will($this->returnValue(true)); |
||
232 | |||
233 | $innerHandlerMock = $this->getMock('eZ\\Publish\\SPI\\Persistence\\Content\\Section\\Handler'); |
||
234 | $this->persistenceHandlerMock |
||
235 | ->expects($this->once()) |
||
236 | ->method('sectionHandler') |
||
237 | ->will($this->returnValue($innerHandlerMock)); |
||
238 | |||
239 | $innerHandlerMock |
||
240 | ->expects($this->once()) |
||
241 | ->method('load') |
||
242 | ->with(33) |
||
243 | ->will( |
||
244 | $this->returnValue( |
||
245 | new SPISection( |
||
246 | array('id' => 33, 'name' => 'Intranet', 'identifier' => 'intranet') |
||
247 | ) |
||
248 | ) |
||
249 | ); |
||
250 | |||
251 | $cacheItemMock |
||
252 | ->expects($this->once()) |
||
253 | ->method('set') |
||
254 | ->with($this->isInstanceOf('eZ\\Publish\\SPI\\Persistence\\Content\\Section')) |
||
255 | ->will($this->returnValue($cacheItemMock)); |
||
256 | |||
257 | $cacheItemMock |
||
258 | ->expects($this->once()) |
||
259 | ->method('save') |
||
260 | ->with(); |
||
261 | |||
262 | $cacheItemMock |
||
263 | ->expects($this->once()) |
||
264 | ->method('get') |
||
265 | ->will($this->returnValue(null)); |
||
266 | |||
267 | $handler = $this->persistenceCacheHandler->sectionHandler(); |
||
268 | $handler->load(33); |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::load |
||
273 | */ |
||
274 | View Code Duplication | public function testLoadHasCache() |
|
311 | |||
312 | /** |
||
313 | * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::loadAll |
||
314 | */ |
||
315 | public function testLoadAll() |
||
336 | |||
337 | /** |
||
338 | * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::loadByIdentifier |
||
339 | */ |
||
340 | public function testLoadByIdentifier() |
||
368 | |||
369 | /** |
||
370 | * @covers eZ\Publish\Core\Persistence\Cache\SectionHandler::update |
||
371 | */ |
||
372 | View Code Duplication | public function testUpdate() |
|
419 | } |
||
420 |