Skip to content

Commit 71a5925

Browse files
committed
Hardens the Utils\is_multi_obj() and resolves #157
1 parent 54d22b4 commit 71a5925

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

php/utils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ function is_hermes() {
432432
**/
433433
function result_is_multiobj( $result ) {
434434
$iter = new ArrayIterator($result);
435-
if( is_object( $iter->current() ) OR is_array( $iter->current() ) ) {
435+
if(is_int($iter->key()) AND (is_object( $iter->current() ) OR is_array( $iter->current()))) {
436436
return true;
437437
}
438438
unset($iter);

tests/test-utils.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ function testResultIsMultiObj() {
2828

2929
$this->assertFalse( \Terminus\Utils\result_is_multiobj( $arraysimple ));
3030
$this->assertTrue( \Terminus\Utils\result_is_multiobj( $arraymultiobj ));
31+
// real world results.
32+
$object1 = '{"params": {"environment_id": "testlog", "deploy": {"clone_files": {"from_environment": "testlog"}, "annotation": "Create the environment.", "clone_database": {"from_environment": "testlog"}}}, "role": "owner", "site_id": "aaa313ea-d667-4cf6-b165-31a4a03abbc0", "task_ids": ["b76f4a72-bc51-11e4-b8ed-bc764e111d20", "b88cc1c8-bc51-11e4-b8ed-bc764e111d20", "b88ee85e-bc51-11e4-b8ed-bc764e111d20", "b891de74-bc51-11e4-b8ed-bc764e111d20", "b8be13cc-bc51-11e4-b8ed-bc764e111d20", "b8befdf0-bc51-11e4-b8ed-bc764e111d20", "b8bfc19a-bc51-11e4-b8ed-bc764e111d20", "b8d836f8-bc51-11e4-b8ed-bc764e111d20", "b8da08f2-bc51-11e4-b8ed-bc764e111d20", "b8dcf65c-bc51-11e4-b8ed-bc764e111d20", "b8e2c0a0-bc51-11e4-b8ed-bc764e111d20", "b8e532fe-bc51-11e4-b8ed-bc764e111d20", "b8fcfbd2-bc51-11e4-b8ed-bc764e111d20", "b8fec3ae-bc51-11e4-b8ed-bc764e111d20", "b900cf8c-bc51-11e4-b8ed-bc764e111d20", "b91e6c7c-bc51-11e4-b8ed-bc764e111d20", "b91fbeb0-bc51-11e4-b8ed-bc764e111d20", "b92315c4-bc51-11e4-b8ed-bc764e111d20", "b9267f98-bc51-11e4-b8ed-bc764e111d20"], "type": "create_cloud_development_environment", "user_id": "94212cf6-b7e1-44fc-bfc8-8a48214aa5fd", "waiting_for_task_id": "b88cc1c8-bc51-11e4-b8ed-bc764e111d20", "id": "b76f40ae-bc51-11e4-b8ed-bc764e111d20", "key": "1424800800", "environment": null, "environment_id": null, "result": null, "keep_forever": false, "final_task_id": null, "created_at": 1424801988.385195, "total_time": null, "active_description": "Creating a cloud development environment", "description": "Create a cloud development environment", "final_task": null}';
33+
$this->assertFalse(\Terminus\utils\result_is_multiobj(json_decode($object1)));
3134
}
3235

3336
function testFilenameFromUrl() {
@@ -52,4 +55,4 @@ function testDestinationIsValid() {
5255
$this->assertFileExists($testdir);
5356
$this->assertEquals($testdir,$destination);
5457
}
55-
}
58+
}

0 commit comments

Comments
 (0)