Total Complexity | 78 |
Total Lines | 822 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like OrmFunctionalTestCase often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use OrmFunctionalTestCase, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | abstract class OrmFunctionalTestCase extends OrmTestCase |
||
31 | { |
||
32 | /** |
||
33 | * The metadata cache shared between all functional tests. |
||
34 | * |
||
35 | * @var \Doctrine\Common\Cache\Cache|null |
||
36 | */ |
||
37 | private static $metadataCacheImpl = null; |
||
38 | |||
39 | /** |
||
40 | * The query cache shared between all functional tests. |
||
41 | * |
||
42 | * @var \Doctrine\Common\Cache\Cache|null |
||
43 | */ |
||
44 | private static $queryCacheImpl = null; |
||
45 | |||
46 | /** |
||
47 | * Shared connection when a TestCase is run alone (outside of its functional suite). |
||
48 | * |
||
49 | * @var \Doctrine\DBAL\Connection|null |
||
50 | */ |
||
51 | protected static $sharedConn; |
||
52 | |||
53 | /** |
||
54 | * @var \Doctrine\ORM\EntityManagerInterface |
||
55 | */ |
||
56 | protected $em; |
||
57 | |||
58 | /** |
||
59 | * @var \Doctrine\ORM\Tools\SchemaTool |
||
60 | */ |
||
61 | protected $schemaTool; |
||
62 | |||
63 | /** |
||
64 | * @var \Doctrine\DBAL\Logging\DebugStack |
||
65 | */ |
||
66 | protected $sqlLoggerStack; |
||
67 | |||
68 | /** |
||
69 | * The names of the model sets used in this testcase. |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $usedModelSets = []; |
||
74 | |||
75 | /** |
||
76 | * To be configured by the test that uses result set cache |
||
77 | * |
||
78 | * @var \Doctrine\Common\Cache\Cache|null |
||
79 | */ |
||
80 | protected $resultCacheImpl; |
||
81 | |||
82 | /** |
||
83 | * Whether the database schema has already been created. |
||
84 | * |
||
85 | * @var array |
||
86 | */ |
||
87 | protected static $tablesCreated = []; |
||
88 | |||
89 | /** |
||
90 | * Array of entity class name to their tables that were created. |
||
91 | * |
||
92 | * @var array |
||
93 | */ |
||
94 | protected static $entityTablesCreated = []; |
||
95 | |||
96 | /** |
||
97 | * List of model sets and their classes. |
||
98 | * |
||
99 | * @var array |
||
100 | */ |
||
101 | protected static $modelSets = [ |
||
102 | 'cms' => [ |
||
103 | Models\CMS\CmsUser::class, |
||
104 | Models\CMS\CmsPhonenumber::class, |
||
105 | Models\CMS\CmsAddress::class, |
||
106 | Models\CMS\CmsEmail::class, |
||
107 | Models\CMS\CmsGroup::class, |
||
108 | Models\CMS\CmsTag::class, |
||
109 | Models\CMS\CmsArticle::class, |
||
110 | Models\CMS\CmsComment::class, |
||
111 | ], |
||
112 | 'company' => [ |
||
113 | Models\Company\CompanyPerson::class, |
||
114 | Models\Company\CompanyEmployee::class, |
||
115 | Models\Company\CompanyManager::class, |
||
116 | Models\Company\CompanyOrganization::class, |
||
117 | Models\Company\CompanyEvent::class, |
||
118 | Models\Company\CompanyAuction::class, |
||
119 | Models\Company\CompanyRaffle::class, |
||
120 | Models\Company\CompanyCar::class, |
||
121 | Models\Company\CompanyContract::class, |
||
122 | ], |
||
123 | 'ecommerce' => [ |
||
124 | Models\ECommerce\ECommerceCart::class, |
||
125 | Models\ECommerce\ECommerceCustomer::class, |
||
126 | Models\ECommerce\ECommerceProduct::class, |
||
127 | Models\ECommerce\ECommerceShipping::class, |
||
128 | Models\ECommerce\ECommerceFeature::class, |
||
129 | Models\ECommerce\ECommerceCategory::class |
||
130 | ], |
||
131 | 'generic' => [ |
||
132 | Models\Generic\BooleanModel::class, |
||
133 | Models\Generic\DateTimeModel::class, |
||
134 | Models\Generic\DecimalModel::class, |
||
135 | Models\Generic\SerializationModel::class, |
||
136 | ], |
||
137 | 'routing' => [ |
||
138 | Models\Routing\RoutingLeg::class, |
||
139 | Models\Routing\RoutingLocation::class, |
||
140 | Models\Routing\RoutingRoute::class, |
||
141 | Models\Routing\RoutingRouteBooking::class, |
||
142 | ], |
||
143 | 'navigation' => [ |
||
144 | Models\Navigation\NavUser::class, |
||
145 | Models\Navigation\NavCountry::class, |
||
146 | Models\Navigation\NavPhotos::class, |
||
147 | Models\Navigation\NavTour::class, |
||
148 | Models\Navigation\NavPointOfInterest::class, |
||
149 | ], |
||
150 | 'directorytree' => [ |
||
151 | Models\DirectoryTree\AbstractContentItem::class, |
||
152 | Models\DirectoryTree\File::class, |
||
153 | Models\DirectoryTree\Directory::class, |
||
154 | ], |
||
155 | 'ddc117' => [ |
||
156 | Models\DDC117\DDC117Article::class, |
||
157 | Models\DDC117\DDC117Reference::class, |
||
158 | Models\DDC117\DDC117Translation::class, |
||
159 | Models\DDC117\DDC117ArticleDetails::class, |
||
160 | Models\DDC117\DDC117ApproveChanges::class, |
||
161 | Models\DDC117\DDC117Editor::class, |
||
162 | Models\DDC117\DDC117Link::class, |
||
163 | ], |
||
164 | 'ddc3699' => [ |
||
165 | Models\DDC3699\DDC3699Parent::class, |
||
166 | Models\DDC3699\DDC3699RelationOne::class, |
||
167 | Models\DDC3699\DDC3699RelationMany::class, |
||
168 | Models\DDC3699\DDC3699Child::class, |
||
169 | ], |
||
170 | 'stockexchange' => [ |
||
171 | Models\StockExchange\Bond::class, |
||
172 | Models\StockExchange\Stock::class, |
||
173 | Models\StockExchange\Market::class, |
||
174 | ], |
||
175 | 'legacy' => [ |
||
176 | Models\Legacy\LegacyUser::class, |
||
177 | Models\Legacy\LegacyUserReference::class, |
||
178 | Models\Legacy\LegacyArticle::class, |
||
179 | Models\Legacy\LegacyCar::class, |
||
180 | ], |
||
181 | 'customtype' => [ |
||
182 | Models\CustomType\CustomTypeChild::class, |
||
183 | Models\CustomType\CustomTypeParent::class, |
||
184 | Models\CustomType\CustomTypeUpperCase::class, |
||
185 | ], |
||
186 | 'compositekeyinheritance' => [ |
||
187 | Models\CompositeKeyInheritance\JoinedRootClass::class, |
||
188 | Models\CompositeKeyInheritance\JoinedChildClass::class, |
||
189 | Models\CompositeKeyInheritance\SingleRootClass::class, |
||
190 | Models\CompositeKeyInheritance\SingleChildClass::class, |
||
191 | ], |
||
192 | 'taxi' => [ |
||
193 | Models\Taxi\PaidRide::class, |
||
194 | Models\Taxi\Ride::class, |
||
195 | Models\Taxi\Car::class, |
||
196 | Models\Taxi\Driver::class, |
||
197 | ], |
||
198 | 'cache' => [ |
||
199 | Models\Cache\Country::class, |
||
200 | Models\Cache\State::class, |
||
201 | Models\Cache\City::class, |
||
202 | Models\Cache\Traveler::class, |
||
203 | Models\Cache\TravelerProfileInfo::class, |
||
204 | Models\Cache\TravelerProfile::class, |
||
205 | Models\Cache\Travel::class, |
||
206 | Models\Cache\Attraction::class, |
||
207 | Models\Cache\Restaurant::class, |
||
208 | Models\Cache\Beach::class, |
||
209 | Models\Cache\Bar::class, |
||
210 | Models\Cache\Flight::class, |
||
211 | Models\Cache\Token::class, |
||
212 | Models\Cache\Login::class, |
||
213 | Models\Cache\Client::class, |
||
214 | Models\Cache\Person::class, |
||
215 | Models\Cache\Address::class, |
||
216 | Models\Cache\Action::class, |
||
217 | Models\Cache\ComplexAction::class, |
||
218 | Models\Cache\AttractionInfo::class, |
||
219 | Models\Cache\AttractionContactInfo::class, |
||
220 | Models\Cache\AttractionLocationInfo::class |
||
221 | ], |
||
222 | 'tweet' => [ |
||
223 | Models\Tweet\User::class, |
||
224 | Models\Tweet\Tweet::class, |
||
225 | Models\Tweet\UserList::class, |
||
226 | ], |
||
227 | 'ddc2504' => [ |
||
228 | Models\DDC2504\DDC2504RootClass::class, |
||
229 | Models\DDC2504\DDC2504ChildClass::class, |
||
230 | Models\DDC2504\DDC2504OtherClass::class, |
||
231 | ], |
||
232 | 'ddc3346' => [ |
||
233 | Models\DDC3346\DDC3346Author::class, |
||
234 | Models\DDC3346\DDC3346Article::class, |
||
235 | ], |
||
236 | 'quote' => [ |
||
237 | Models\Quote\Address::class, |
||
238 | Models\Quote\City::class, |
||
239 | Models\Quote\FullAddress::class, |
||
240 | Models\Quote\Group::class, |
||
241 | Models\Quote\NumericEntity::class, |
||
242 | Models\Quote\Phone::class, |
||
243 | Models\Quote\User::class |
||
244 | ], |
||
245 | 'vct_onetoone' => [ |
||
246 | Models\ValueConversionType\InversedOneToOneEntity::class, |
||
247 | Models\ValueConversionType\OwningOneToOneEntity::class |
||
248 | ], |
||
249 | 'vct_onetoone_compositeid' => [ |
||
250 | Models\ValueConversionType\InversedOneToOneCompositeIdEntity::class, |
||
251 | Models\ValueConversionType\OwningOneToOneCompositeIdEntity::class |
||
252 | ], |
||
253 | 'vct_onetoone_compositeid_foreignkey' => [ |
||
254 | Models\ValueConversionType\AuxiliaryEntity::class, |
||
255 | Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity::class, |
||
256 | Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity::class |
||
257 | ], |
||
258 | 'vct_onetomany' => [ |
||
259 | Models\ValueConversionType\InversedOneToManyEntity::class, |
||
260 | Models\ValueConversionType\OwningManyToOneEntity::class |
||
261 | ], |
||
262 | 'vct_onetomany_compositeid' => [ |
||
263 | Models\ValueConversionType\InversedOneToManyCompositeIdEntity::class, |
||
264 | Models\ValueConversionType\OwningManyToOneCompositeIdEntity::class |
||
265 | ], |
||
266 | 'vct_onetomany_compositeid_foreignkey' => [ |
||
267 | Models\ValueConversionType\AuxiliaryEntity::class, |
||
268 | Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity::class, |
||
269 | Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity::class |
||
270 | ], |
||
271 | 'vct_onetomany_extralazy' => [ |
||
272 | Models\ValueConversionType\InversedOneToManyExtraLazyEntity::class, |
||
273 | Models\ValueConversionType\OwningManyToOneExtraLazyEntity::class |
||
274 | ], |
||
275 | 'vct_manytomany' => [ |
||
276 | Models\ValueConversionType\InversedManyToManyEntity::class, |
||
277 | Models\ValueConversionType\OwningManyToManyEntity::class |
||
278 | ], |
||
279 | 'vct_manytomany_compositeid' => [ |
||
280 | Models\ValueConversionType\InversedManyToManyCompositeIdEntity::class, |
||
281 | Models\ValueConversionType\OwningManyToManyCompositeIdEntity::class |
||
282 | ], |
||
283 | 'vct_manytomany_compositeid_foreignkey' => [ |
||
284 | Models\ValueConversionType\AuxiliaryEntity::class, |
||
285 | Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity::class, |
||
286 | Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity::class |
||
287 | ], |
||
288 | 'vct_manytomany_extralazy' => [ |
||
289 | Models\ValueConversionType\InversedManyToManyExtraLazyEntity::class, |
||
290 | Models\ValueConversionType\OwningManyToManyExtraLazyEntity::class |
||
291 | ], |
||
292 | 'geonames' => [ |
||
293 | Models\GeoNames\Country::class, |
||
294 | Models\GeoNames\Admin1::class, |
||
295 | Models\GeoNames\Admin1AlternateName::class, |
||
296 | Models\GeoNames\City::class |
||
297 | ], |
||
298 | 'custom_id_object_type' => [ |
||
299 | Models\CustomType\CustomIdObjectTypeParent::class, |
||
300 | Models\CustomType\CustomIdObjectTypeChild::class, |
||
301 | ], |
||
302 | 'pagination' => [ |
||
303 | Models\Pagination\Company::class, |
||
304 | Models\Pagination\Logo::class, |
||
305 | Models\Pagination\Department::class, |
||
306 | Models\Pagination\User::class, |
||
307 | Models\Pagination\User1::class, |
||
308 | ], |
||
309 | 'versioned_many_to_one' => [ |
||
310 | Models\VersionedManyToOne\Category::class, |
||
311 | Models\VersionedManyToOne\Article::class, |
||
312 | ], |
||
313 | 'issue5989' => [ |
||
314 | Models\Issue5989\Issue5989Person::class, |
||
315 | Models\Issue5989\Issue5989Employee::class, |
||
316 | Models\Issue5989\Issue5989Manager::class, |
||
317 | ], |
||
318 | ]; |
||
319 | |||
320 | /** |
||
321 | * @param string $setName |
||
322 | * |
||
323 | * @return void |
||
324 | */ |
||
325 | protected function useModelSet($setName) |
||
326 | { |
||
327 | $this->usedModelSets[$setName] = true; |
||
328 | } |
||
329 | |||
330 | /** |
||
331 | * Sweeps the database tables and clears the EntityManager. |
||
332 | * |
||
333 | * @return void |
||
334 | */ |
||
335 | protected function tearDown() |
||
336 | { |
||
337 | $conn = static::$sharedConn; |
||
338 | |||
339 | // In case test is skipped, tearDown is called, but no setup may have run |
||
340 | if ( ! $conn) { |
||
341 | return; |
||
342 | } |
||
343 | |||
344 | $platform = $conn->getDatabasePlatform(); |
||
345 | |||
346 | $this->sqlLoggerStack->enabled = false; |
||
347 | |||
348 | if (isset($this->usedModelSets['cms'])) { |
||
349 | $conn->executeUpdate('DELETE FROM cms_users_groups'); |
||
350 | $conn->executeUpdate('DELETE FROM cms_groups'); |
||
351 | $conn->executeUpdate('DELETE FROM cms_users_tags'); |
||
352 | $conn->executeUpdate('DELETE FROM cms_tags'); |
||
353 | $conn->executeUpdate('DELETE FROM cms_addresses'); |
||
354 | $conn->executeUpdate('DELETE FROM cms_phonenumbers'); |
||
355 | $conn->executeUpdate('DELETE FROM cms_comments'); |
||
356 | $conn->executeUpdate('DELETE FROM cms_articles'); |
||
357 | $conn->executeUpdate('DELETE FROM cms_users'); |
||
358 | $conn->executeUpdate('DELETE FROM cms_emails'); |
||
359 | } |
||
360 | |||
361 | if (isset($this->usedModelSets['ecommerce'])) { |
||
362 | $conn->executeUpdate('DELETE FROM ecommerce_carts_products'); |
||
363 | $conn->executeUpdate('DELETE FROM ecommerce_products_categories'); |
||
364 | $conn->executeUpdate('DELETE FROM ecommerce_products_related'); |
||
365 | $conn->executeUpdate('DELETE FROM ecommerce_carts'); |
||
366 | $conn->executeUpdate('DELETE FROM ecommerce_customers'); |
||
367 | $conn->executeUpdate('DELETE FROM ecommerce_features'); |
||
368 | $conn->executeUpdate('DELETE FROM ecommerce_products'); |
||
369 | $conn->executeUpdate('DELETE FROM ecommerce_shippings'); |
||
370 | $conn->executeUpdate('UPDATE ecommerce_categories SET parent_id = NULL'); |
||
371 | $conn->executeUpdate('DELETE FROM ecommerce_categories'); |
||
372 | } |
||
373 | |||
374 | if (isset($this->usedModelSets['company'])) { |
||
375 | $conn->executeUpdate('DELETE FROM company_contract_employees'); |
||
376 | $conn->executeUpdate('DELETE FROM company_contract_managers'); |
||
377 | $conn->executeUpdate('DELETE FROM company_contracts'); |
||
378 | $conn->executeUpdate('DELETE FROM company_persons_friends'); |
||
379 | $conn->executeUpdate('DELETE FROM company_managers'); |
||
380 | $conn->executeUpdate('DELETE FROM company_employees'); |
||
381 | $conn->executeUpdate('UPDATE company_persons SET spouse_id = NULL'); |
||
382 | $conn->executeUpdate('DELETE FROM company_persons'); |
||
383 | $conn->executeUpdate('DELETE FROM company_raffles'); |
||
384 | $conn->executeUpdate('DELETE FROM company_auctions'); |
||
385 | $conn->executeUpdate('UPDATE company_organizations SET main_event_id = NULL'); |
||
386 | $conn->executeUpdate('DELETE FROM company_events'); |
||
387 | $conn->executeUpdate('DELETE FROM company_organizations'); |
||
388 | } |
||
389 | |||
390 | if (isset($this->usedModelSets['generic'])) { |
||
391 | $conn->executeUpdate('DELETE FROM boolean_model'); |
||
392 | $conn->executeUpdate('DELETE FROM date_time_model'); |
||
393 | $conn->executeUpdate('DELETE FROM decimal_model'); |
||
394 | $conn->executeUpdate('DELETE FROM serialize_model'); |
||
395 | } |
||
396 | |||
397 | if (isset($this->usedModelSets['routing'])) { |
||
398 | $conn->executeUpdate('DELETE FROM RoutingRouteLegs'); |
||
399 | $conn->executeUpdate('DELETE FROM RoutingRouteBooking'); |
||
400 | $conn->executeUpdate('DELETE FROM RoutingRoute'); |
||
401 | $conn->executeUpdate('DELETE FROM RoutingLeg'); |
||
402 | $conn->executeUpdate('DELETE FROM RoutingLocation'); |
||
403 | } |
||
404 | |||
405 | if (isset($this->usedModelSets['navigation'])) { |
||
406 | $conn->executeUpdate('DELETE FROM navigation_tour_pois'); |
||
407 | $conn->executeUpdate('DELETE FROM navigation_photos'); |
||
408 | $conn->executeUpdate('DELETE FROM navigation_pois'); |
||
409 | $conn->executeUpdate('DELETE FROM navigation_tours'); |
||
410 | $conn->executeUpdate('DELETE FROM navigation_countries'); |
||
411 | } |
||
412 | |||
413 | if (isset($this->usedModelSets['directorytree'])) { |
||
414 | $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("file")); |
||
415 | // MySQL doesn't know deferred deletions therefore only executing the second query gives errors. |
||
416 | $conn->executeUpdate('DELETE FROM Directory WHERE parentDirectory_id IS NOT NULL'); |
||
417 | $conn->executeUpdate('DELETE FROM Directory'); |
||
418 | } |
||
419 | |||
420 | if (isset($this->usedModelSets['ddc117'])) { |
||
421 | $conn->executeUpdate('DELETE FROM ddc117editor_ddc117translation'); |
||
422 | $conn->executeUpdate('DELETE FROM DDC117Editor'); |
||
423 | $conn->executeUpdate('DELETE FROM DDC117ApproveChanges'); |
||
424 | $conn->executeUpdate('DELETE FROM DDC117Link'); |
||
425 | $conn->executeUpdate('DELETE FROM DDC117Reference'); |
||
426 | $conn->executeUpdate('DELETE FROM DDC117ArticleDetails'); |
||
427 | $conn->executeUpdate('DELETE FROM DDC117Translation'); |
||
428 | $conn->executeUpdate('DELETE FROM DDC117Article'); |
||
429 | } |
||
430 | |||
431 | if (isset($this->usedModelSets['stockexchange'])) { |
||
432 | $conn->executeUpdate('DELETE FROM exchange_bonds_stocks'); |
||
433 | $conn->executeUpdate('DELETE FROM exchange_bonds'); |
||
434 | $conn->executeUpdate('DELETE FROM exchange_stocks'); |
||
435 | $conn->executeUpdate('DELETE FROM exchange_markets'); |
||
436 | } |
||
437 | |||
438 | if (isset($this->usedModelSets['legacy'])) { |
||
439 | $conn->executeUpdate('DELETE FROM legacy_users_cars'); |
||
440 | $conn->executeUpdate('DELETE FROM legacy_users_reference'); |
||
441 | $conn->executeUpdate('DELETE FROM legacy_articles'); |
||
442 | $conn->executeUpdate('DELETE FROM legacy_cars'); |
||
443 | $conn->executeUpdate('DELETE FROM legacy_users'); |
||
444 | } |
||
445 | |||
446 | if (isset($this->usedModelSets['customtype'])) { |
||
447 | $conn->executeUpdate('DELETE FROM customtype_parent_friends'); |
||
448 | $conn->executeUpdate('DELETE FROM customtype_parents'); |
||
449 | $conn->executeUpdate('DELETE FROM customtype_children'); |
||
450 | $conn->executeUpdate('DELETE FROM customtype_uppercases'); |
||
451 | } |
||
452 | |||
453 | if (isset($this->usedModelSets['compositekeyinheritance'])) { |
||
454 | $conn->executeUpdate('DELETE FROM JoinedChildClass'); |
||
455 | $conn->executeUpdate('DELETE FROM JoinedRootClass'); |
||
456 | $conn->executeUpdate('DELETE FROM SingleRootClass'); |
||
457 | } |
||
458 | |||
459 | if (isset($this->usedModelSets['taxi'])) { |
||
460 | $conn->executeUpdate('DELETE FROM taxi_paid_ride'); |
||
461 | $conn->executeUpdate('DELETE FROM taxi_ride'); |
||
462 | $conn->executeUpdate('DELETE FROM taxi_car'); |
||
463 | $conn->executeUpdate('DELETE FROM taxi_driver'); |
||
464 | } |
||
465 | |||
466 | if (isset($this->usedModelSets['tweet'])) { |
||
467 | $conn->executeUpdate('DELETE FROM tweet_tweet'); |
||
468 | $conn->executeUpdate('DELETE FROM tweet_user_list'); |
||
469 | $conn->executeUpdate('DELETE FROM tweet_user'); |
||
470 | } |
||
471 | |||
472 | if (isset($this->usedModelSets['cache'])) { |
||
473 | $conn->executeUpdate('DELETE FROM cache_attraction_location_info'); |
||
474 | $conn->executeUpdate('DELETE FROM cache_attraction_contact_info'); |
||
475 | $conn->executeUpdate('DELETE FROM cache_attraction_info'); |
||
476 | $conn->executeUpdate('DELETE FROM cache_visited_cities'); |
||
477 | $conn->executeUpdate('DELETE FROM cache_flight'); |
||
478 | $conn->executeUpdate('DELETE FROM cache_attraction'); |
||
479 | $conn->executeUpdate('DELETE FROM cache_travel'); |
||
480 | $conn->executeUpdate('DELETE FROM cache_traveler'); |
||
481 | $conn->executeUpdate('DELETE FROM cache_traveler_profile_info'); |
||
482 | $conn->executeUpdate('DELETE FROM cache_traveler_profile'); |
||
483 | $conn->executeUpdate('DELETE FROM cache_city'); |
||
484 | $conn->executeUpdate('DELETE FROM cache_state'); |
||
485 | $conn->executeUpdate('DELETE FROM cache_country'); |
||
486 | $conn->executeUpdate('DELETE FROM cache_login'); |
||
487 | $conn->executeUpdate('DELETE FROM cache_token'); |
||
488 | $conn->executeUpdate('DELETE FROM cache_complex_action'); |
||
489 | $conn->executeUpdate('DELETE FROM cache_action'); |
||
490 | $conn->executeUpdate('DELETE FROM cache_client'); |
||
491 | } |
||
492 | |||
493 | if (isset($this->usedModelSets['ddc3346'])) { |
||
494 | $conn->executeUpdate('DELETE FROM ddc3346_articles'); |
||
495 | $conn->executeUpdate('DELETE FROM ddc3346_users'); |
||
496 | } |
||
497 | |||
498 | if (isset($this->usedModelSets['quote'])) { |
||
499 | $conn->executeUpdate( |
||
500 | sprintf( |
||
501 | 'UPDATE %s SET %s = NULL', |
||
502 | $platform->quoteIdentifier("quote-address"), |
||
503 | $platform->quoteIdentifier('user-id') |
||
504 | ) |
||
505 | ); |
||
506 | |||
507 | $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier('quote-users-groups')); |
||
508 | $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("quote-group")); |
||
509 | $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("quote-phone")); |
||
510 | $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("quote-user")); |
||
511 | $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("quote-address")); |
||
512 | $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier('quote-city')); |
||
513 | } |
||
514 | |||
515 | if (isset($this->usedModelSets['vct_onetoone'])) { |
||
516 | $conn->executeUpdate('DELETE FROM vct_owning_onetoone'); |
||
517 | $conn->executeUpdate('DELETE FROM vct_inversed_onetoone'); |
||
518 | } |
||
519 | |||
520 | if (isset($this->usedModelSets['vct_onetoone_compositeid'])) { |
||
521 | $conn->executeUpdate('DELETE FROM vct_owning_onetoone_compositeid'); |
||
522 | $conn->executeUpdate('DELETE FROM vct_inversed_onetoone_compositeid'); |
||
523 | } |
||
524 | |||
525 | if (isset($this->usedModelSets['vct_onetoone_compositeid_foreignkey'])) { |
||
526 | $conn->executeUpdate('DELETE FROM vct_owning_onetoone_compositeid_foreignkey'); |
||
527 | $conn->executeUpdate('DELETE FROM vct_inversed_onetoone_compositeid_foreignkey'); |
||
528 | $conn->executeUpdate('DELETE FROM vct_auxiliary'); |
||
529 | } |
||
530 | |||
531 | if (isset($this->usedModelSets['vct_onetomany'])) { |
||
532 | $conn->executeUpdate('DELETE FROM vct_owning_manytoone'); |
||
533 | $conn->executeUpdate('DELETE FROM vct_inversed_onetomany'); |
||
534 | } |
||
535 | |||
536 | if (isset($this->usedModelSets['vct_onetomany_compositeid'])) { |
||
537 | $conn->executeUpdate('DELETE FROM vct_owning_manytoone_compositeid'); |
||
538 | $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_compositeid'); |
||
539 | } |
||
540 | |||
541 | if (isset($this->usedModelSets['vct_onetomany_compositeid_foreignkey'])) { |
||
542 | $conn->executeUpdate('DELETE FROM vct_owning_manytoone_compositeid_foreignkey'); |
||
543 | $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_compositeid_foreignkey'); |
||
544 | $conn->executeUpdate('DELETE FROM vct_auxiliary'); |
||
545 | } |
||
546 | |||
547 | if (isset($this->usedModelSets['vct_onetomany_extralazy'])) { |
||
548 | $conn->executeUpdate('DELETE FROM vct_owning_manytoone_extralazy'); |
||
549 | $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_extralazy'); |
||
550 | } |
||
551 | |||
552 | if (isset($this->usedModelSets['vct_manytomany'])) { |
||
553 | $conn->executeUpdate('DELETE FROM vct_xref_manytomany'); |
||
554 | $conn->executeUpdate('DELETE FROM vct_owning_manytomany'); |
||
555 | $conn->executeUpdate('DELETE FROM vct_inversed_manytomany'); |
||
556 | } |
||
557 | |||
558 | if (isset($this->usedModelSets['vct_manytomany_compositeid'])) { |
||
559 | $conn->executeUpdate('DELETE FROM vct_xref_manytomany_compositeid'); |
||
560 | $conn->executeUpdate('DELETE FROM vct_owning_manytomany_compositeid'); |
||
561 | $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_compositeid'); |
||
562 | } |
||
563 | |||
564 | if (isset($this->usedModelSets['vct_manytomany_compositeid_foreignkey'])) { |
||
565 | $conn->executeUpdate('DELETE FROM vct_xref_manytomany_compositeid_foreignkey'); |
||
566 | $conn->executeUpdate('DELETE FROM vct_owning_manytomany_compositeid_foreignkey'); |
||
567 | $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_compositeid_foreignkey'); |
||
568 | $conn->executeUpdate('DELETE FROM vct_auxiliary'); |
||
569 | } |
||
570 | |||
571 | if (isset($this->usedModelSets['vct_manytomany_extralazy'])) { |
||
572 | $conn->executeUpdate('DELETE FROM vct_xref_manytomany_extralazy'); |
||
573 | $conn->executeUpdate('DELETE FROM vct_owning_manytomany_extralazy'); |
||
574 | $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_extralazy'); |
||
575 | } |
||
576 | |||
577 | if (isset($this->usedModelSets['geonames'])) { |
||
578 | $conn->executeUpdate('DELETE FROM geonames_admin1_alternate_name'); |
||
579 | $conn->executeUpdate('DELETE FROM geonames_admin1'); |
||
580 | $conn->executeUpdate('DELETE FROM geonames_city'); |
||
581 | $conn->executeUpdate('DELETE FROM geonames_country'); |
||
582 | } |
||
583 | |||
584 | if (isset($this->usedModelSets['custom_id_object_type'])) { |
||
585 | $conn->executeUpdate('DELETE FROM custom_id_type_child'); |
||
586 | $conn->executeUpdate('DELETE FROM custom_id_type_parent'); |
||
587 | } |
||
588 | |||
589 | if (isset($this->usedModelSets['pagination'])) { |
||
590 | $conn->executeUpdate('DELETE FROM pagination_logo'); |
||
591 | $conn->executeUpdate('DELETE FROM pagination_department'); |
||
592 | $conn->executeUpdate('DELETE FROM pagination_company'); |
||
593 | $conn->executeUpdate('DELETE FROM pagination_user'); |
||
594 | } |
||
595 | |||
596 | if (isset($this->usedModelSets['versioned_many_to_one'])) { |
||
597 | $conn->executeUpdate('DELETE FROM versioned_many_to_one_article'); |
||
598 | $conn->executeUpdate('DELETE FROM versioned_many_to_one_category'); |
||
599 | } |
||
600 | |||
601 | if (isset($this->usedModelSets['issue5989'])) { |
||
602 | $conn->executeUpdate('DELETE FROM issue5989_persons'); |
||
603 | $conn->executeUpdate('DELETE FROM issue5989_employees'); |
||
604 | $conn->executeUpdate('DELETE FROM issue5989_managers'); |
||
605 | } |
||
606 | |||
607 | $this->em->clear(); |
||
608 | } |
||
609 | |||
610 | /** |
||
611 | * @param array $classNames |
||
612 | * |
||
613 | * @return void |
||
614 | * |
||
615 | * @throws \RuntimeException |
||
616 | */ |
||
617 | protected function setUpEntitySchema(array $classNames) |
||
618 | { |
||
619 | if ($this->em === null) { |
||
620 | throw new \RuntimeException("EntityManager not set, you have to call parent::setUp() before invoking this method."); |
||
621 | } |
||
622 | |||
623 | $classes = []; |
||
624 | |||
625 | foreach ($classNames as $className) { |
||
626 | if ( ! isset(static::$entityTablesCreated[$className])) { |
||
627 | static::$entityTablesCreated[$className] = true; |
||
628 | $classes[] = $this->em->getClassMetadata($className); |
||
629 | } |
||
630 | } |
||
631 | |||
632 | if ($classes) { |
||
633 | $this->schemaTool->createSchema($classes); |
||
634 | } |
||
635 | } |
||
636 | |||
637 | /** |
||
638 | * Creates a connection to the test database, if there is none yet, and |
||
639 | * creates the necessary tables. |
||
640 | * |
||
641 | * @return void |
||
642 | */ |
||
643 | protected function setUp() |
||
673 | } |
||
674 | |||
675 | /** |
||
676 | * Gets an EntityManager for testing purposes. |
||
677 | * |
||
678 | * @return EntityManagerInterface |
||
679 | * |
||
680 | * @throws \Doctrine\ORM\ORMException |
||
681 | */ |
||
682 | protected function getEntityManager(Connection $connection = null, MappingDriver $mappingDriver = null) |
||
683 | { |
||
684 | // NOTE: Functional tests use their own shared metadata cache, because |
||
685 | // the actual database platform used during execution has effect on some |
||
686 | // metadata mapping behaviors (like the choice of the ID generation). |
||
687 | if (null === self::$metadataCacheImpl) { |
||
688 | if (isset($GLOBALS['DOCTRINE_CACHE_IMPL'])) { |
||
689 | self::$metadataCacheImpl = new $GLOBALS['DOCTRINE_CACHE_IMPL']; |
||
690 | } else { |
||
691 | self::$metadataCacheImpl = new ArrayCache(); |
||
692 | } |
||
693 | } |
||
694 | |||
695 | if (null === self::$queryCacheImpl) { |
||
696 | self::$queryCacheImpl = new ArrayCache(); |
||
697 | } |
||
698 | |||
699 | $this->sqlLoggerStack = new DebugStack(); |
||
700 | $this->sqlLoggerStack->enabled = false; |
||
701 | |||
702 | //FIXME: two different configs! $conn and the created entity manager have |
||
703 | // different configs. |
||
704 | $config = new Configuration(); |
||
705 | |||
706 | $config->setMetadataCacheImpl(self::$metadataCacheImpl); |
||
707 | $config->setQueryCacheImpl(self::$queryCacheImpl); |
||
708 | $config->setAutoGenerateProxyClasses(ProxyFactory::AUTOGENERATE_EVAL); |
||
709 | $config->setProxyNamespace('Doctrine\Tests\Proxies'); |
||
710 | |||
711 | if (null !== $this->resultCacheImpl) { |
||
712 | $config->setResultCacheImpl($this->resultCacheImpl); |
||
713 | } |
||
714 | |||
715 | $enableSecondLevelCache = getenv('ENABLE_SECOND_LEVEL_CACHE'); |
||
716 | |||
717 | if ($this->isSecondLevelCacheEnabled || $enableSecondLevelCache) { |
||
718 | $cacheConfig = new CacheConfiguration(); |
||
719 | $cache = $this->getSharedSecondLevelCacheDriverImpl(); |
||
720 | $factory = new DefaultCacheFactory($cacheConfig->getRegionsConfiguration(), $cache); |
||
721 | |||
722 | $this->secondLevelCacheFactory = $factory; |
||
723 | |||
724 | if ($this->isSecondLevelCacheLogEnabled) { |
||
725 | $this->secondLevelCacheLogger = new StatisticsCacheLogger(); |
||
726 | $cacheConfig->setCacheLogger($this->secondLevelCacheLogger); |
||
727 | } |
||
728 | |||
729 | $cacheConfig->setCacheFactory($factory); |
||
730 | $config->setSecondLevelCacheEnabled(true); |
||
731 | $config->setSecondLevelCacheConfiguration($cacheConfig); |
||
732 | |||
733 | $this->isSecondLevelCacheEnabled = true; |
||
734 | } |
||
735 | |||
736 | $conn = $connection ?: static::$sharedConn; |
||
737 | |||
738 | $config->setMetadataDriverImpl( |
||
739 | $mappingDriver ?? $config->newDefaultAnnotationDriver([ |
||
740 | realpath(__DIR__ . '/Models/Cache'), |
||
741 | realpath(__DIR__ . '/Models/GeoNames') |
||
742 | ]) |
||
743 | ); |
||
744 | |||
745 | $conn->getConfiguration()->setSQLLogger($this->sqlLoggerStack); |
||
746 | |||
747 | // get rid of more global state |
||
748 | $evm = $conn->getEventManager(); |
||
749 | |||
750 | foreach ($evm->getListeners() as $event => $listeners) { |
||
751 | foreach ($listeners as $listener) { |
||
752 | $evm->removeEventListener([$event], $listener); |
||
753 | } |
||
754 | } |
||
755 | |||
756 | if ($enableSecondLevelCache) { |
||
757 | $evm->addEventListener('loadClassMetadata', new CacheMetadataListener()); |
||
758 | } |
||
759 | |||
760 | if (isset($GLOBALS['db_event_subscribers'])) { |
||
761 | foreach (explode(",", $GLOBALS['db_event_subscribers']) as $subscriberClass) { |
||
762 | $subscriberInstance = new $subscriberClass(); |
||
763 | $evm->addEventSubscriber($subscriberInstance); |
||
764 | } |
||
765 | } |
||
766 | |||
767 | if (isset($GLOBALS['debug_uow_listener'])) { |
||
768 | $evm->addEventListener(['onFlush'], new DebugUnitOfWorkListener()); |
||
769 | } |
||
770 | |||
771 | return EntityManager::create($conn, $config); |
||
772 | } |
||
773 | |||
774 | /** |
||
775 | * @param \Throwable $e |
||
776 | * |
||
777 | * @return void |
||
778 | * |
||
779 | * @throws \Throwable |
||
780 | */ |
||
781 | protected function onNotSuccessfulTest(\Throwable $e) |
||
782 | { |
||
783 | if ($e instanceof AssertionFailedError) { |
||
784 | throw $e; |
||
785 | } |
||
786 | |||
787 | if (isset($this->sqlLoggerStack->queries) && count($this->sqlLoggerStack->queries)) { |
||
788 | $queries = ""; |
||
789 | $last25queries = array_slice(array_reverse($this->sqlLoggerStack->queries, true), 0, 25, true); |
||
790 | |||
791 | foreach ($last25queries as $i => $query) { |
||
792 | $params = array_map( |
||
793 | function($p) { |
||
794 | return is_object($p) ? get_class($p) : var_export($p, true); |
||
795 | }, |
||
796 | $query['params'] ?: [] |
||
797 | ); |
||
798 | |||
799 | $queries .= $i.". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; |
||
800 | } |
||
801 | |||
802 | $trace = $e->getTrace(); |
||
803 | $traceMsg = ""; |
||
804 | |||
805 | foreach ($trace as $part) { |
||
806 | if (isset($part['file'])) { |
||
807 | if (strpos($part['file'], "PHPUnit/") !== false) { |
||
808 | // Beginning with PHPUnit files we don't print the trace anymore. |
||
809 | break; |
||
810 | } |
||
811 | |||
812 | $traceMsg .= $part['file'].":".$part['line'].PHP_EOL; |
||
813 | } |
||
814 | } |
||
815 | |||
816 | $message = "[".get_class($e)."] ".$e->getMessage().PHP_EOL.PHP_EOL."With queries:".PHP_EOL.$queries.PHP_EOL."Trace:".PHP_EOL.$traceMsg; |
||
817 | |||
818 | throw new \Exception($message, (int)$e->getCode(), $e); |
||
819 | } |
||
820 | |||
821 | throw $e; |
||
822 | } |
||
823 | |||
824 | public static function assertSQLEquals($expectedSql, $actualSql) |
||
830 | ); |
||
831 | } |
||
832 | |||
833 | /** |
||
834 | * Using the SQL Logger Stack this method retrieves the current query count executed in this test. |
||
835 | * |
||
836 | * @return int |
||
837 | */ |
||
838 | protected function getCurrentQueryCount() |
||
839 | { |
||
840 | return count($this->sqlLoggerStack->queries); |
||
841 | } |
||
842 | |||
843 | /** |
||
844 | * Configures DBAL types required in tests |
||
845 | */ |
||
846 | protected function setUpDBALTypes() |
||
852 | } |
||
853 | } |
||
854 | } |
||
855 |