Closed
Description
Symfony 4.1 introduced new testing service container which allows to get private services in tests.
For example following code is correct:
namespace App\Tests\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaTool;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DefaultControllerTest extends WebTestCase
{
public function testIndex(): void
{
$client = static::createClient();
/** @var ContainerInterface $container */
$container = $client->getContainer();
$entityManager = $container->get(EntityManagerInterface::class);
// do something with entity manager
$client->request('GET', '/');
$this->assertSame(200, $client->getResponse()->getStatusCode());
}
}
But PHPStan throws error "Service "Doctrine\ORM\EntityManagerInterface" is private."
Metadata
Metadata
Assignees
Labels
No labels