Symfony 3工厂存储库

时间:2016-07-10 15:57:52

标签: php symfony dependency-injection phpunit config

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

我试着在测试中调用它 -

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

}

我收到错误(失败) -

  

AccessTokenRepositoryTest :: testDi   断言Doctrine \ ORM \ EntityRepository对象(...)是类" Ftob \ OauthServerApp \ Repositories \ AccessTokenRepository"的实例失败。

     

/var/www/tests/Repositories/AccessTokenRepositoryTest.php:23

     

FAILURES!

     

测试:1,断言:1,失败:1。

为什么调用实例Doctrine \ ORM \ EntityRepository,而不调用AccessTokenRepository?

谢谢!

0 个答案:

没有答案