Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
possi opened this issue Jan 22, 2024 · 2 comments
Open

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

possi opened this issue Jan 22, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@possi
Copy link

possi commented Jan 22, 2024

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)
@possi possi added the bug Something isn't working label Jan 22, 2024
@alexislefebvre
Copy link
Collaborator

Thanks for the report.

Would you be able to open a PR? What about just reverting the change from PHPDoc to typing? (in other words, restore the previous code that accepted a MongoDB connection)

@alexislefebvre
Copy link
Collaborator

It would be nice to have some tests with MongoDB in this bundle.

  1. Add a Kernel with a MongoDB config in this directory: https://github.com/liip/LiipTestFixturesBundle/tree/2.x/tests
  2. Add a test that use this Kernel in this other directory https://github.com/liip/LiipTestFixturesBundle/tree/2.x/tests/Test
  3. Add a MongoDB service in docker-compose.yml: https://github.com/liip/LiipTestFixturesBundle/blob/2.x/docker-compose.yml
  4. Add a MongoDB service for GitHub actions: https://github.com/liip/LiipTestFixturesBundle/blob/2.x/.github/workflows/tests.yml#L49
  5. Submit a PR 🚀
  6. We'll fix the issues that may appear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants