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.

Implementing ContainerAwareInterface like shown in other posts is better way of doing things.


FeatureContext.php


namespace Football\TeamBundle\Features\Context;

use Behat\MinkExtension\Context\MinkContext;
use Behat\Symfony2Extension\Context\KernelAwareInterface;
use Symfony\Component\HttpKernel\KernelInterface;

class FeatureContext extends MinkContext implements KernelAwareInterface
{
private $kernel;

public function setKernel(KernelInterface $kernelInterface)
{
$this->kernel = $kernelInterface;
}

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

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

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