2

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]);

I try to call it 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 receive 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.

Why call instance Doctrine\ORM\EntityRepository, not AccessTokenRepository?

Thanks!

Jakub Matczak
  • 15,341
  • 5
  • 46
  • 64
  • 1
    Does Doctrine know, that you are using custom repository? http://symfony.com/doc/current/book/doctrine.html#custom-repository-classes – michaJlS Jul 10 '16 at 19:03

0 Answers0