Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

You can use service container as you use it in your controllers or service. You can also use EntityManager and repositories.


FeatureContext.php


namespace Application\BackendBundle\Features\Context;

use Behat\MinkExtension\Context\MinkContext;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;

class FeatureContext extends MinkContext implements ContainerAwareInterface
{
private $container;

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

public function getParameter()
{
$myParameter = $this->container->getParameter('name_of_the_param');
}

public function getService()
{
$myService = $this->container->get('name_of_the_service');
}

public function runDbQuery($ame)
{
$em = $this->container->get('doctrine')->getManager();
$repo = $em->getRepository('FootballTeamBundle:Country');
$country = $repo->findOneBy(array('name' => $name));
}
}