Skip to content

[Bug]: 2.7.2 - Doctrine MongoDB Manager can not be used anymore #258

Open
@possi

Description

@possi

Preconditions

  • PHP 8.1.27
  • doctrine/mongodb-odm 2.6.2
  • doctrine/mongodb-odm-bundle 4.7.0
  • liip/test-fixtures-bundle 2.7.2
  • symfony/framework-bundle 5.4.34
  • phpunit/phpunit 10.4.2
  • symfony/phpunit-bridge 5.4.34

Steps to reproduce

class AppTest extends KernelTestCase
{
    protected function setUp(): void
    {
        self::bootKernel();
        dump(static::getContainer()->get(DatabaseToolCollection::class)->get(null, 'doctrine_mongodb'));
    }
}

Expected result

Liip\TestFixturesBundle\Services\DatabaseTools\MongoDBDatabaseTool {#2000
  #container: ContainerYyoQOI7\TestInstance_TestKernelTestDebugContainer {#483 …20}
  #eventDispatcher: Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher {#2575 …8}
  #fixturesLoaderFactory: Liip\TestFixturesBundle\Services\FixturesLoaderFactory {#2002
    ...
  }
  #registry: Doctrine\Bundle\MongoDBBundle\ManagerRegistry {#2148
    -name: "MongoDB"
    -connections: array:1 [
      "default" => "doctrine_mongodb.odm.default_connection"
    ]
    -managers: array:1 [
      "default" => "doctrine_mongodb.odm.default_document_manager"
    ]
    -defaultConnection: "default"
    -defaultManager: "default"
    -proxyInterfaceName: "ProxyManager\Proxy\GhostObjectInterface"
    #container: ContainerYyoQOI7\TestInstance_TestKernelTestDebugContainer {#483 …20}
  }
  #omName: null
  #registryName: "doctrine"
  #om: Doctrine\ODM\MongoDB\DocumentManager {#2049 …15}
  #connection: MongoDB\Client {#2145
    -manager: MongoDB\Driver\Manager {#2144}
    -readConcern: MongoDB\Driver\ReadConcern {#2143}
    -readPreference: MongoDB\Driver\ReadPreference {#2142
      +"mode": "primary"
    }
    -uri: "mongodb://localhost:27017"
    -typeMap: array:2 [
      "root" => "array"
      "document" => "array"
    ]
    -writeConcern: MongoDB\Driver\WriteConcern {#2141}
    manager: MongoDB\Driver\Manager {#2144}
    uri: "mongodb://localhost:27017"
    typeMap: array:2 [
      "root" => "array"
      "document" => "array"
    ]
    writeConcern: MongoDB\Driver\WriteConcern {#2141}
  }
  #purgeMode: null
  #databaseCacheEnabled: true
  #excludedDoctrineTables: []
}

Actual result

TypeError: Cannot assign MongoDB\Client to property Liip\TestFixturesBundle\Services\DatabaseTools\AbstractDatabaseTool::$connection of type Doctrine\DBAL\Connection

.../vendor/liip/test-fixtures-bundle/src/Services/DatabaseTools/AbstractDatabaseTool.php:109
.../vendor/liip/test-fixtures-bundle/src/Services/DatabaseToolCollection.php:62

Explenation / Recommendation

The property $connection in AbstractDatabaseTool changed from PHPDoc-Typehint to strict PHP Typing. The MongoDB Manager doesn't use DBAL (as it is NoSQL),
I would recommend:

  • Create an DatabaseToolInterface (to be used as the typings in DatabaseToolCollection)
  • Move the property $connection to an inbetween-class AbstractDbalTool which is used by ORMDatabaseTool and ORMSqliteDatbaseTool
  • Implement the Interface in MongoDBDAtabaseTool and PHPCRDatabaseTool without AbstractDbalTool (may still share some other methods using AbstractDatabaseTool)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions