doctrine / DoctrineMongoDBBundle

Integrates Doctrine MongoDB ODM with Symfony
http://symfony.com/doc/current/bundles/DoctrineMongoDBBundle/index.html
MIT License
377 stars 229 forks source link

Registry constructor expected ManagerRegistry found DocumentManager #781

Closed mustanggb closed 10 months ago

mustanggb commented 10 months ago

Implementing a repository as per the Service Repositories docs:

i.e.

// src/App/Repository/ProductRepository.php
namespace App\Repository;

use App\Document\Product;
use Doctrine\Bundle\MongoDBBundle\ManagerRegistry;
use Doctrine\Bundle\MongoDBBundle\Repository\ServiceDocumentRepository;

/**
 * Remember to map this repository in the corresponding document's repositoryClass.
 * For more information on this see the previous chapter.
 */
class ProductRepository extends ServiceDocumentRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Product::class);
    }
}

Kicks out an issue with $registry in parent::__construct($registry, Product::class); of:

Expected type 'Doctrine\Persistence\ManagerRegistry'. Found 'Doctrine\ODM\MongoDB\DocumentManager'
@param \Doctrine\ODM\MongoDB\DocumentManager $registry

I had a dig around in ServiceRepositoryTrait but wasn't able to figure out how to solve it.

For reference, I also tested with the ORM's ServiceEntityRepository, but it did not experience the same problem.

malarzm commented 10 months ago

@mustanggb any chance you could provide us a PR with a failing test case? At a glance there seems to be a misconfiguration on your end, as per the error the repository is expecting an instance of ManagerRegistry while it's given a DocumentManager instead.

mustanggb commented 10 months ago

Okay I think I found the source:

/**
 * @extends ServiceDocumentRepository<Product>
 */
class ProductRepository extends ServiceDocumentRepository
{
    public function __construct(ManagerRegistry $registry)
    {
        parent::__construct($registry, Product::class);
    }
}

I also tried @template-extends ServiceDocumentRepository<Product> but it gives the same problem.

However changing to @extends ServiceDocumentRepository "fixes" it?

Could this be related to some of these:

malarzm commented 10 months ago

Ah so this is static analysis error! Whatever you're using seems to be taking PHPDoc from ODM's definition https://github.com/doctrine/mongodb-odm/blob/d3c8966b95059e9b572b3f873440b93ac7dd3907/lib/Doctrine/ODM/MongoDB/Repository/DocumentRepository.php#L61 instead of bundle's trait.

mustanggb commented 10 months ago

Thanks for the help, it seems this is due to a missing param: #782

mustanggb commented 10 months ago

Fixed by 0a533e9ff176f727459aa33ec097231deec2213e.