eZ Community » Forums » eZ Publish 5 Platform » Call 'ezpublish.connection' service...
expandshrink

Call 'ezpublish.connection' service from a functional test

Call 'ezpublish.connection' service from a functional test

Thursday 10 April 2014 5:47:54 pm - 1 reply

I have a helper class which executes a query to a custom table on my ez5 db. As the class doesn't have access to the db, i must inject a service container. I can do this passing the ContainerInterface from a controller to my classes constructor function.

This works:

 use Symfony\Component\DependencyInjection\ContainerInterface;
class MyClass{
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

   ...

   public function myFunction(){
        ...
        $db = $this->container->get('ezpublish.connection');
        $rows = $db->query( 'SELECT * FROM table' );
   }
}

 

The problem is in my functional tests. As 'ezpublish.connection' is NOT a lazy service, when i call this service, i think that the database hasn't bee instantiated, so i get the following error:

 ezcBaseValueException: The value '' that you were trying to assign to parameter 'dbParams' is invalid. Allowed values are: string or array.

 

This is how i am getting the service container in my functional test class:

 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class MyClassTest extends WebTestCase
{
protected $container;

public function setUp() {
        $client = static::createClient();
        $this->container = $client->getContainer();
}

public function testFoo(){
    $obj = new MyClass($this->container);
    $result = $obj->myFunction();

    ....
}

}

Does anyone know how i can call 'ezpublish.connection' service with the db instantiated?

 

Thank you

Friday 11 April 2014 9:09:22 am

I have this issue too. I have the same problem. Any suggestion ?

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from