jeudi 4 juin 2015

Symfony: how to mock services (FormBuilder and Router)

I have an handler i wrote that has the following signature:

public function __construct(
    Store $store,
    array $orders,
    FormFactory $formFactory,
    Router $router)
{

How can i mock FormFactory and Router?

I've tryied the following:

$formFactory = $this->getMock('\Symfony\Component\Form\FormFactory')
$router = $this->getMock('\Symfony\Bundle\FrameworkBundle\Routing\Router')

But i receive the following error:

AppBundle\Tests\Handler\SetUpHandlerTest::testConstructor Argument 1 passed to Symfony\Bundle\FrameworkBundle\Routing\Router::__construct() must implement interface Symfony\Component\DependencyInjection\ContainerInterface, none given, called in /DevRoot/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php on line 254 and defined

It seems there is a problem with the interface ContainerInterface.

How can i mock this service?

Aucun commentaire:

Enregistrer un commentaire