jeudi 7 mai 2015

ZendFramework 2 Testing Console Route Action

I want to test a method triggered by a cronjob running a php script.

I have recently started using PHPunit in Zend Framework 2.

I came across the Zend\Test\PHPUnit\Controller\AbstractConsoleControllerTestCase, and the following example of implementing a console test:

public function testConsoleActionCanBeAccessed()
{
$this->dispatch('--your-arg');
$this->assertResponseStatusCode(0);

$this->assertModule('application');
$this->assertControllerName('application_console');
$this->assertControllerClass('ConsoleController');
$this->assertMatchedRouteName('myaction');
}

My implementation is as follows:

public function testInternReminderAction()
{
    $this->mockBjy();
    $this->mockZFC();

    $this->dispatch('internReminder');
    $this->assertModuleName('intern');
    $this->assertControllerName('intern\controller\intern');
    $this->assertControllerClass('InternController');
    $this->assertMatchedRouteName('internReminder');
}

I am unsure how to proceed at this point. I believe I need to change the route string in the dispatch method but unsure as to how. When I run the test as is I get the following error: run-time Exception 'you can only use this action from a console'. An exception I created if the instance is not one created via the $this->getServiceLocator()->get('console') method. Any ideas, suggestion and ultimately solutions will be most welcome.

Thanks

Aucun commentaire:

Enregistrer un commentaire