/** * Removes API key and Entities generated for test * * @throws \Scalr\Exception\ModelException */ public static function tearDownAfterClass() { foreach (array_reverse(static::$testData) as $rec) { $class = $rec['class']; $entry = $rec['pk']; $initProperties = $rec['initProp']; $entity = new $class(); /* @var $entity AbstractEntity */ foreach ($entity->getIterator()->getPrimaryKey() as $pos => $prop) { $entity->{$prop} = $entry[$pos]; } //we should init properties which will be used in delete action foreach ($initProperties as $prop => $value) { $entity->{$prop} = $value; } try { //deletePk method does not remove related objects $entity->delete(); } catch (Exception $e) { //we should remove all created Entities \Scalr::logException($e); } } static::$testData = []; if (!empty(static::$apiKeyEntity)) { static::$apiKeyEntity->delete(); } static::changeLoggerConfiguration(); }
/** * Remove API key generated for test * * @afterClass */ public static function tearDownAfterClass() { foreach (static::$testData as $class => $ids) { $ids = array_unique($ids, SORT_REGULAR); foreach ($ids as $entry) { if (!empty($entry)) { $entity = call_user_func_array([$class, 'findPk'], is_object($entry) ? [$entry] : (array) $entry); if (!empty($entity)) { try { $entity->delete(); } catch (Exception $e) { error_log($e->getMessage()); error_log($class); error_log(print_r($entry, true)); } } } } } if (!empty(static::$apiKeyEntity)) { static::$apiKeyEntity->delete(); } }
/** * Removes API key generated for test * * @afterClass */ public static function tearDownAfterClass() { ksort(static::$testData, SORT_REGULAR); foreach (static::$testData as $priority => $data) { foreach ($data as $class => $ids) { $ids = array_unique($ids, SORT_REGULAR); foreach ($ids as $entry) { if (!empty($entry)) { $entity = call_user_func_array([$class, 'findPk'], is_object($entry) ? [$entry] : (array) $entry); if (!empty($entity)) { try { $entity->delete(); } catch (Exception $e) { // error_log("{$class}:\t" . $e->getMessage() . "\n " . str_replace("\n", "\n ", print_r($entry, true))); } } } } } } if (!empty(static::$apiKeyEntity)) { static::$apiKeyEntity->delete(); } }