Refactor batch construction in function tests
PHP-1116: Fix ID extraction for legacy upserts

When "_id" is not an ObjectId, pre-2.6 servers will not return it and we attempt to extract it from the query/newObj objects.

The newObj object should be checked before query, as that is the priority used by the server.