Symfony\Bundle\FrameworkBundle\Controller\Controller::getDoctrine PHP Method

getDoctrine() protected method

Shortcut to return the Doctrine Registry service.
protected getDoctrine ( ) : Doctrine\Bundle\DoctrineBundle\Registry
return Doctrine\Bundle\DoctrineBundle\Registry
    protected function getDoctrine()
    {
        if (!$this->container->has('doctrine')) {
            throw new \LogicException('The DoctrineBundle is not registered in your application.');
        }
        return $this->container->get('doctrine');
    }

Usage Example

 public function testGetDoctrine()
 {
     $doctrine = $this->getMock('Doctrine\\Common\\Persistence\\ManagerRegistry');
     $container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
     $container->expects($this->at(0))->method('has')->will($this->returnValue(true));
     $container->expects($this->at(1))->method('get')->will($this->returnValue($doctrine));
     $controller = new Controller();
     $controller->setContainer($container);
     $this->assertEquals($doctrine, $controller->getDoctrine());
 }
All Usage Examples Of Symfony\Bundle\FrameworkBundle\Controller\Controller::getDoctrine