rackspace / php-opencloud

The PHP SDK for OpenStack clouds
developer.rackspace.com
Other
451 stars 250 forks source link

Fix certificateMappingList returning valid CertificateMappings when iterated #706

Closed Darunada closed 7 years ago

Darunada commented 7 years ago

The following code was returning empty CertificateMapping objects when iterated.

// snippet roughly from the documentation...
$mappingsIterator = $loadBalancer->certificateMappingList();
while ($mappingsIterator->valid()) {
    $mapping = $mappingsIterator->current();
    echo $mapping->id; // EMPTY ID
    $mappingsIterator->next();
}

// the foreach syntax has the same problem...

Inspecting the $elements property on $mappingsIterator was showing the elements in the following structure with correct values:

$elements = [
    0=>{
        certificateMapping => {
            id: 1234
            hostName: whatever.com
        }
    },
    1=>{...}
    2=>{...}
]

However, looping the iterator was returning CertificateMapping objects without the id and hostName properties set. This was caused because of the second level in the $elements array being passed into populate, recognizing that there is no property called "certificateMapping" and issuing a warning "Attempted to set certificateMapping with value {id...hostname...}, but the property has not been defined. Please define first."

Adding this method allows populate to recognize that certificateMapping structure and repopulate with the actual values.

It now returns valid CertificateMapping objects with the id and hostname set, making it actually useful.

There were no tests to this portion of the platform so I did not add any to check this behavior.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.05%) to 88.771% when pulling 3bf08b23054609370669de133a8d28d18d89ff5a on Darunada:fix-load-balancer-certificateMappingList into cce4c2c8d58d9d7726c7eb542730c349c16dcf82 on rackspace:working.

Mortalife commented 6 years ago

I just pushed a change for this not realising it was on working branch - any idea when the current working branch will be available from composer?