Scalr\Tests\Functional\Api\ApiTestCase::tearDownAfterClass PHP Method

tearDownAfterClass() public static method

Removes API key and Entities generated for test
public static tearDownAfterClass ( )
    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();
    }

Usage Example

Esempio n. 1
0
 /**
  * Also Removes Cost Centers properties generated for test
  *
  * {@inheritdoc}
  * @see Scalr\Tests\Functional\Api\ApiTestCase::tearDownAfterClass()
  */
 public static function tearDownAfterClass()
 {
     ksort(static::$testData, SORT_REGULAR);
     foreach (static::$testData as $priority => $data) {
         foreach ($data as $class => $ids) {
             if ($class === 'Scalr\\Stats\\CostAnalytics\\Entity\\CostCentreEntity') {
                 $ids = array_unique($ids, SORT_REGULAR);
                 foreach ($ids as $entry) {
                     /* @var $cc CostCentreEntity */
                     $cc = $class::findPk(...$entry);
                     if (!empty($cc)) {
                         try {
                             CostCentrePropertyEntity::deleteByCcId($cc->ccId);
                             AccountCostCenterEntity::deleteByCcId($cc->ccId);
                             $cc->delete();
                         } catch (\Exception $e) {
                             \Scalr::logException($e);
                         }
                     }
                 }
                 unset(static::$testData[$priority][$class]);
             }
         }
     }
     parent::tearDownAfterClass();
 }
All Usage Examples Of Scalr\Tests\Functional\Api\ApiTestCase::tearDownAfterClass