phpstan / phpstan-doctrine

Doctrine extensions for PHPStan
MIT License
585 stars 96 forks source link

\Doctrine\Bundle\MongoDBBundle\ManagerRegistry::getRepository should return DocumentRepository instead of EntityRepository #115

Closed teohhanhui closed 2 years ago

teohhanhui commented 4 years ago
<?php

declare(strict_types=1);

namespace ApiPlatform\Core\Test;

use ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Dummy;
use Doctrine\Bundle\MongoDBBundle\Tests\TestCase;
use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;

abstract class DoctrineMongoDbOdmFilterTestCase extends KernelTestCase
{
    /**
     * @var ManagerRegistry
     */
    protected $managerRegistry;

    /**
     * @var DocumentRepository
     */
    protected $repository;

    protected function setUp(): void
    {
        self::bootKernel();

        $manager = TestCase::createTestDocumentManager();
        $this->managerRegistry = self::$kernel->getContainer()->get('doctrine_mongodb');
        $this->repository = $manager->getRepository(Dummy::class);
    }
}

Together with phpstan/phpstan-symfony this gives:

 ------ --------------------------------------------------------------------------------------------------------------------------------------------------- 
  Line   src/Test/DoctrineMongoDbOdmFilterTestCase.php                                                                                                      
 ------ --------------------------------------------------------------------------------------------------------------------------------------------------- 
  56     Property ApiPlatform\Core\Test\DoctrineMongoDbOdmFilterTestCase::$repository (Doctrine\ODM\MongoDB\Repository\DocumentRepository) does not accept  
         Doctrine\ORM\EntityRepository<ApiPlatform\Core\Tests\Fixtures\TestBundle\Document\Dummy>.                                                          
 ------ ---------------------------------------------------------------------------------------------------------------------------------------------------
andythorne commented 3 years ago

I had this error, you can set the repository class in the phpstan.neon settings to point to the correct class:

parameters:
    doctrine:
        repositoryClass: Doctrine\ODM\MongoDB\Repository\DocumentRepository
github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.