The extra arguments test can be skipped for HHVM (as was done in #74).
The read preference and write concern tests attempt to cover all permutations of invalid arguments. Detailed exceptions are only possible where we apply array options to the structures, since libmongoc currently provides no detailed errors when URI parsing fails (see: CDRIVER-782).
The read preference and write concern are complex structures, so we can't simply set their options on the URI as we do for other things (e.g. auth credentials).
If the URI cannot be parsed, we should throw an InvalidArgumentException. Failing to initialize the client from a valid URI can remain a RuntimeException.
This avoids a possible segfault in calling code, were it to zval_ptr_dtor() state->zchild before initialization (i.e. bson_to_zval() returns early on error).
The original test was problematic for HHVM, since it injects the __pclass value differently. Although changing the bsonSerialize() field order should ensure identical hex_dump() output on HHVM, we'll split the test cases.
See: fddd88ff9d
This revises the UnexpectedValueException message for an invalid return value (PHPC-331).
Additionally, we consolidated the previous BSON-encoding error tests.
ODM behavior should override only the default type map and named class. Array and stdClass object modes still take precedence.
The PHONGO_TYPEMAP_CLASS switch cases were simplified, since we can trust that the root/document or ODM class implements Unserializable (thanks to php_phongo_bson_typemap_to_state() and php_phongo_bson_visit_binary(), respectively).
Per the serialization spec, we should check that the class (1) exists, (2), is instantiatable, and (3) implements Unserializable.
Additionally, this refactors some code duplication out of apply_classname_to_state(). We should also always check to free classname, since an empty string might have been allocated (i.e. classname_len is zero).