Mongolid\Model\DocumentEmbedderTest::testShouldEmbed PHP Method

testShouldEmbed() public method

public testShouldEmbed ( $originalField, $entity, $method, $expectation )
    public function testShouldEmbed($originalField, $entity, $method, $expectation)
    {
        // Arrange
        $parent = new stdClass();
        $parent->foo = $originalField;
        $embeder = new DocumentEmbedder();
        // Assert
        $embeder->{$method}($parent, 'foo', $entity);
        $result = $parent->foo;
        foreach ($expectation as $index => $expectedDoc) {
            if ($expectedDoc instanceof ObjectID) {
                $this->assertEquals($expectedDoc, $result[$index]);
                continue;
            }
            $expectedDocArray = (array) $expectedDoc;
            $resultDocArray = (array) $result[$index];
            foreach ($expectedDocArray as $field => $value) {
                if ($value instanceof Any) {
                    $this->assertTrue(isset($resultDocArray[$field]));
                } else {
                    $this->assertEquals($value, $resultDocArray[$field]);
                }
            }
        }
    }