Fix an array access error in Scenario No.4 of testK8sCostResourceStoreTest

Created on 31 July 2024, 5 months ago
Updated 15 August 2024, 4 months ago

Problem/Motivation

Fix the following error in testK8sUpdateResourceStorageTest

 1)
    Drupal\Tests\k8s\Functional\cloud\cloud_store\K8sCloudStoreTest::testK8sCostResourceStoreTest
    Trying to access array offset on null
    
    /builds/project/cloud/modules/cloud_service_providers/k8s/tests/src/Functional/cloud/cloud_store/K8sCloudStoreTest.php:458
    /builds/project/cloud/vendor/phpunit/phpunit/src/Framework/TestResult.php:729
    
    ERRORS!
    Tests: 3, Assertions: 123, Errors: 1.

It seems like the array_pop in the following code will return the entity that does not have any value for field_cost

    $cost_entity = array_pop($cost_entities);
    $costs = Yaml::decode(!empty($cost_entity->get('field_costs')->value) ? $cost_entity->get('field_costs')->value : '');
    $controller = \Drupal::classResolver()->getInstanceFromDefinition(K8sCostsControllerBase::class);
    $cost_types = array_keys($controller->getEc2CostTypes());
    foreach ($cost_types ?: [] as $cost_type) {
      $this->assertEquals(round($costs[$cost_type], 3), round($result['costs'][$cost_type], 3));
    }
πŸ› Bug report
Status

Fixed

Version

7.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States baldwinlouie

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024