Mongolid\DataMapper\DataMapperTest::testShouldParseObjectToDocumentAndPutResultingIdIntoTheGivenObject PHP Method

testShouldParseObjectToDocumentAndPutResultingIdIntoTheGivenObject() public method

    public function testShouldParseObjectToDocumentAndPutResultingIdIntoTheGivenObject()
    {
        // Arrange
        $connPool = m::mock(Pool::class);
        $mapper = m::mock(DataMapper::class . '[getSchemaMapper]', [$connPool]);
        $entity = m::mock();
        $parsedDocument = ['a_field' => 123, '_id' => 'bacon'];
        $schemaMapper = m::mock(Schema::class . '[]');
        $mapper->shouldAllowMockingProtectedMethods();
        // Expect
        $mapper->shouldReceive('getSchemaMapper')->once()->andReturn($schemaMapper);
        $schemaMapper->shouldReceive('map')->once()->with($entity)->andReturn($parsedDocument);
        // Act
        $result = $this->callProtected($mapper, 'parseToDocument', $entity);
        // Assert
        $this->assertEquals($parsedDocument, $result);
        $this->assertEquals('bacon', $entity->_id);
    }