I try to set up unit tests for a new project. Added unittest and the laminas-test module. My issue is when i just follow the tutorials, i run into an error not getting the right request type in the application.
Error : Call to undefined method Laminas\Console\Request::getQuery()
…/vendor/laminas/laminas-test/src/PHPUnit/Controller/AbstractControllerTestCase.php:238
…/vendor/laminas/laminas-test/src/PHPUnit/Controller/AbstractControllerTestCase.php:308
i call the unit test by cmd:
./vendor/bin/phpunit
The test function has one line:
$this->dispatch(’/document/search’);
I get a console request instead of a php environment request. Which is not very surprising when called by cmd. But how can i setup test for the controllers with the right request type?
Any hints how to solve this?
Thats the test class
<?php
namespace SbDocument\Test;
use Laminas\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
class DocumentTest extends AbstractHttpControllerTestCase
{
protected function setUp(): void
{
if (!defined('ROOT_PATH')) {
define('ROOT_PATH', realpath(__DIR__ . '/../../../../../'));
}
$this->setApplicationConfig(
include ROOT_PATH . '/config/application.test.config.php'
);
parent::setUp();
}
public function testIndexActionCanBeAccessed()
{
$this->dispatch('/document/search');
}
}
Which version of laminas-test are you using?
(In the last version the support of laminas-console was removed.)
No, that has nothing to do with it. If you use the class for HTTP controller tests then everything should work and the correct requests are generated.
i use laminas-test 4.0.0
i have laminas-console in use, and it seems to be the problem. Thanks for your Help.
laminas-console has been obsolete for a while, use laminas-cli instead.
Hi stefan So i am going through this issue presently how did you resolve it
laminas-console is who changes the request type. remove it (or at least temporarily) and you can run tests