unit-testingphpunitzend-framework3laminas

Laminas Unit-test controller-action POST parameter does not work


I have a controller extends AbstractHttpControllerTestCase.

I try to pass a parameter (some_uuid) to the dispatch() function (inside my testFoo function):

$this->dispatch('/my-special-url', 'POST', ['some_uuid' => '16294469-f531-40d6-89e9-3ab677a47c45']);
$this->assertResponseStatusCode(200);

Why the parameter is not in the controller?

[EDIT] There isn't a lot of code. But, if someone wants to see everything:

class ProductStockAjaxControllerTest extends AbstractHttpControllerTestCase
{
    protected function setUp(): void
    {
        $configOverrides = [];

        $this->setApplicationConfig(ArrayUtils::merge(
            include __DIR__ . '/../../../../../../config/application.config.php',
            $configOverrides
        ));
        parent::setUp();

        /** @var UserService $userService */
        $userService = $this->getApplication()->getServiceManager()->get(UserService::class);
        $userService->setSessionHashManually('151956ad612953e61533b9d2d5844d65df5b5c8c4e35f5e49375ef77711b6676');
    }

    public function testIndexActionCanBeAccessed()
    {
        $this->dispatch('/my-special-url', 'POST'
        , ['some_uuid' => '16294469-f531-40d6-89e9-3ab677a47c45', 'ano_uuid' => '0a6cea79-9869-4da4-b8db-02bd21d1488a']);
        //$this->assertResponseStatusCode(200);
        $this->assertModuleName('lerp');
        $this->assertControllerName(ProductStockAjaxController::class);
        $this->assertControllerClass('ProductStockAjaxController');
        $this->assertMatchedRouteName('my_special_url');
    }
}

Solution

  • The problem is in the controller that I want to test. There i use filter_input() to get the POST values!

    If i fetch the POST values with $this->getRequest()->getPost('some_uuid') it works fine and my unit test says OK.