I create a container in service.php
$container->setDefinition('repository.access_token', new Definition(\Ftob\OauthServerApp\Repositories\AccessTokenRepository::class)) ->setFactory([new Reference('doctrine'), 'getRepository']) ->setArguments([\Ftob\OauthServerApp\Entity\AccessToken::class]);
Trying to call him in the test -
class AccessTokenRepositoryTest extends KernelTestCase { protected $repository; public function setUp() { $this->bootKernel(); $this->repository = self::$kernel->getContainer()->get('repository.access_token'); } public function testDi() { $this->assertInstanceOf( AccessTokenRepository::class, $this->repository); } } I get an error (fail) -
AccessTokenRepositoryTest::testDi Failed asserting that Doctrine\ORM\EntityRepository Object (...) is an instance of class "Ftob\OauthServerApp\Repositories\AccessTokenRepository". /var/www/tests/Repositories/AccessTokenRepositoryTest.php:23 FAILURES! Tests: 1, Assertions: 1, Failures: 1. Actually, the question is ... Why is Doctrine\ORM\EntityRepository and not AccessTokenRepository ?
Thank you in advance!