Skip to content

Commit

Permalink
Hardens the Utils\is_multi_obj() and resolves #157
Browse files Browse the repository at this point in the history
  • Loading branch information
mikevanwinkle committed Feb 24, 2015
1 parent 54d22b4 commit 71a5925
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion php/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ function is_hermes() {
**/
function result_is_multiobj( $result ) {
$iter = new ArrayIterator($result);
if( is_object( $iter->current() ) OR is_array( $iter->current() ) ) {
if(is_int($iter->key()) AND (is_object( $iter->current() ) OR is_array( $iter->current()))) {
return true;
}
unset($iter);
Expand Down
5 changes: 4 additions & 1 deletion tests/test-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function testResultIsMultiObj() {

$this->assertFalse( \Terminus\Utils\result_is_multiobj( $arraysimple ));
$this->assertTrue( \Terminus\Utils\result_is_multiobj( $arraymultiobj ));
// real world results.
$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}';
$this->assertFalse(\Terminus\utils\result_is_multiobj(json_decode($object1)));
}

function testFilenameFromUrl() {
Expand All @@ -52,4 +55,4 @@ function testDestinationIsValid() {
$this->assertFileExists($testdir);
$this->assertEquals($testdir,$destination);
}
}
}

0 comments on commit 71a5925

Please sign in to comment.