Mongolid\DataMapper\DataMapperTest::testShouldGetWithWhereQuery PHP Method

testShouldGetWithWhereQuery() public method

    public function testShouldGetWithWhereQuery()
    {
        // Arrange
        $connPool = m::mock(Pool::class);
        $mapper = m::mock(DataMapper::class . '[prepareValueQuery,getCollection]', [$connPool]);
        $schema = m::mock(Schema::class);
        $collection = m::mock(Collection::class);
        $query = 123;
        $preparedQuery = ['_id' => 123];
        $projection = ['project' => true, '_id' => false];
        $schema->entityClass = 'stdClass';
        $mapper->setSchema($schema);
        $mapper->shouldAllowMockingProtectedMethods();
        // Expect
        $mapper->shouldReceive('prepareValueQuery')->with($query)->andReturn($preparedQuery);
        $mapper->shouldReceive('getCollection')->andReturn($collection);
        // Act
        $result = $mapper->where($query, $projection);
        $cacheableResult = $mapper->where($query, [], true);
        // Assert
        $this->assertInstanceOf(Cursor::class, $result);
        $this->assertNotInstanceOf(CacheableCursor::class, $result);
        $this->assertAttributeEquals($schema, 'entitySchema', $result);
        $this->assertAttributeEquals($collection, 'collection', $result);
        $this->assertAttributeEquals('find', 'command', $result);
        $this->assertAttributeEquals([$preparedQuery, ['projection' => $projection]], 'params', $result);
        $this->assertInstanceOf(CacheableCursor::class, $cacheableResult);
        $this->assertAttributeEquals($schema, 'entitySchema', $cacheableResult);
        $this->assertAttributeEquals($collection, 'collection', $cacheableResult);
        $this->assertAttributeEquals([$preparedQuery, ['projection' => []]], 'params', $cacheableResult);
    }