Mongolid\DataMapper\DataMapperTest::testShouldGetNullIfFirstCantFindAnything PHP Метод

testShouldGetNullIfFirstCantFindAnything() публичный Метод

    public function testShouldGetNullIfFirstCantFindAnything()
    {
        // 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];
        $schema->entityClass = 'stdClass';
        $mapper->setSchema($schema);
        $mapper->shouldAllowMockingProtectedMethods();
        // Expect
        $mapper->shouldReceive('prepareValueQuery')->once()->with($query)->andReturn($preparedQuery);
        $mapper->shouldReceive('getCollection')->once()->andReturn($collection);
        $collection->shouldReceive('findOne')->once()->with($preparedQuery, ['projection' => []])->andReturn(null);
        // Act
        $result = $mapper->first($query);
        // Assert
        $this->assertNull($result);
    }