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 |
||
24 | class EntityManagerTest extends OrmTestCase |
||
25 | { |
||
26 | /** |
||
27 | * @var EntityManager |
||
28 | */ |
||
29 | private $_em; |
||
30 | |||
31 | function setUp() |
||
36 | |||
37 | /** |
||
38 | * @group DDC-899 |
||
39 | */ |
||
40 | public function testIsOpen() |
||
46 | |||
47 | public function testGetConnection() |
||
51 | |||
52 | public function testGetMetadataFactory() |
||
56 | |||
57 | public function testGetConfiguration() |
||
61 | |||
62 | public function testGetUnitOfWork() |
||
66 | |||
67 | public function testGetProxyFactory() |
||
71 | |||
72 | public function testGetEventManager() |
||
76 | |||
77 | public function testCreateNativeQuery() |
||
84 | |||
85 | /** |
||
86 | * @covers \Doctrine\ORM\EntityManager::createNamedNativeQuery |
||
87 | */ |
||
88 | public function testCreateNamedNativeQuery() |
||
97 | |||
98 | public function testCreateQueryBuilder() |
||
102 | |||
103 | public function testCreateQueryBuilderAliasValid() |
||
116 | |||
117 | public function testCreateQuery_DqlIsOptional() |
||
121 | |||
122 | public function testGetPartialReference() |
||
129 | |||
130 | public function testCreateQuery() |
||
136 | |||
137 | /** |
||
138 | * @covers Doctrine\ORM\EntityManager::createNamedQuery |
||
139 | */ |
||
140 | public function testCreateNamedQuery() |
||
148 | |||
149 | View Code Duplication | static public function dataMethodsAffectedByNoObjectArguments() |
|
150 | { |
||
151 | return [ |
||
152 | ['persist'], |
||
153 | ['remove'], |
||
154 | ['merge'], |
||
155 | ['refresh'], |
||
156 | ['detach'] |
||
157 | ]; |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * @dataProvider dataMethodsAffectedByNoObjectArguments |
||
162 | */ |
||
163 | public function testThrowsExceptionOnNonObjectValues($methodName) { |
||
169 | |||
170 | View Code Duplication | static public function dataAffectedByErrorIfClosedException() |
|
171 | { |
||
172 | return [ |
||
173 | ['flush'], |
||
174 | ['persist'], |
||
175 | ['remove'], |
||
176 | ['merge'], |
||
177 | ['refresh'], |
||
178 | ]; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @dataProvider dataAffectedByErrorIfClosedException |
||
183 | * @param string $methodName |
||
184 | */ |
||
185 | public function testAffectedByErrorIfClosedException($methodName) |
||
193 | |||
194 | /** |
||
195 | * @group DDC-1125 |
||
196 | */ |
||
197 | public function testTransactionalAcceptsReturn() |
||
205 | |||
206 | public function testTransactionalAcceptsVariousCallables() |
||
210 | |||
211 | public function testTransactionalThrowsInvalidArgumentExceptionIfNonCallablePassed() |
||
218 | |||
219 | public function transactionalCallback($em) |
||
224 | |||
225 | public function testCreateInvalidConnection() |
||
234 | |||
235 | /** |
||
236 | * @group #5796 |
||
237 | */ |
||
238 | public function testTransactionalReThrowsThrowables() |
||
252 | |||
253 | /** |
||
254 | * @group 6017 |
||
255 | */ |
||
256 | public function testClearManagerWithObject() |
||
264 | |||
265 | /** |
||
266 | * @group 6017 |
||
267 | */ |
||
268 | public function testClearManagerWithUnknownEntityName() |
||
274 | |||
275 | /** |
||
276 | * @group 6017 |
||
277 | */ |
||
278 | public function testClearManagerWithProxyClassName() |
||
292 | |||
293 | /** |
||
294 | * @group 6017 |
||
295 | */ |
||
296 | public function testClearManagerWithNullValue() |
||
308 | } |
||
309 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.