Do not use array_unique() in case we have non-scalar identifiers

array_unique() performs string casts to compare elements, which makes it unsuitable for handling non-scalar identifiers. Using the serialized ID as a key will prevent duplication in its place.

Using the PHP identifier value here should be OK, since elements are grouped by class name. Therefore, we shouldn't have a situation where MongoId string values are conflicting with strings that look like MongoIds unless a very weird custom type class was in use.
Group identityMap and scheduledForDirtyCheck by class

Group these arrays by class name instead of root document class. This is necessary since documents in the same inheritance hierarchy may have the same ID. Perhaps they are stored in different collections, or a child document is embedded. It is not strictly necessary for scheduledForDirtyCheck, but we'll do it to be consistent.

Always store the serialized database identifier value in the identity map, to avoid potential conflicts among PHP values (e.g. MongoId and string).

The internal tryGetById() and getById() methods now take ClassMetadata, so they can ensure the $id argument is converted to a database value.

Functionality to clear UnitOfWork by a root document class will no longer work. It will be necessary to ensure root ClassMetadata instances know all of their child classes (currently only done for discriminated classes) for this functionality to be restored.
Use IDs if available when registering embedded documents with UnitOfWork

If the identifier is not available, the SPL object hash is used. Previously, it was always used for embedded documents.
Allow for falsey, non-null identifiers in persistNew()
Fix getPartialReference() test to not use invalid identifier per mapping

This leaves a todo item for registerManaged(). As-is, this test failed because registering a document with an identifier not valid for its mapping would lead to an inconsistency in the UnitOfWork maps. The CmsUser document's identifier uses IdType, so we should use a MongoId (or compatible string) here.
Use base test's DocumentManager in IdTest
Extend common BinDataType class and ensure DB conversion is idempotent
Default MongoBinData subtype to 0 and create BinDataByteArrayType for BC

Previously, BinDataType used MongoBinData::BYTE_ARRAY. That subtype, 2, is deprecated in the BSON specification. Use 0, the new default, for BinDataType and create BinDataByteArrayType for users that prefer the old subtype.

See: https://jira.mongodb.org/browse/PHP-407
Update driver version check in BinDataTest, and copy fix to IdTest
Changelog entry for BinDataType subtype change and BinDataByteArrayType
Merge pull request #758 from doctrine/bindata-id-types

Identity map refactoring and fix BinData tests