1

I am working on project built in yii2 and the front end is angular 12 and i am trying to integrate api testing in my project (locally), i am following the documentation but not able to integrate it properly.

i setup my Api.suite.yml as

actor: ApiTester
suite_namespace: \Api
modules:
    # enable helpers as array
    enabled:
        - REST:
            url: http://localhost:4454/meteorwms/backend/web/index.php
            depends: Yii2

an i have created a new test with the name of CreateUserCest

<?php


namespace Api;

use \ApiTester;

class CreateUserCest
{
    public function _before(ApiTester $I)
    {
    }

    // tests
    public function tryToTest(ApiTester $I)
    {
    }

    public function createUserViaAPI(ApiTester $I)
    {
        $I->amHttpAuthenticated('admin', '123');
        $I->haveHttpHeader('accept', 'application/json');
        $I->haveHttpHeader('content-type', 'application/json');
        $I->sendGet('?r=configuration/user&expand=roles.permissions,companies,warehouses,adjustmentTypes,defaultCompany,defaultWarehouse&per-page=10&page=1');
        $I->seeResponseCodeIs(200);
        $I->seeResponseIsJson();
        
    }
}

the url is in this pattern

http://localhost:4454/meteorwms/backend/web/index.php?r=configuration/user&expand=roles.permissions,companies,warehouses,adjustmentTypes,defaultCompany,defaultWarehouse&per-page=10&page=1,

whenever i run the test case it returns

Yii-log: [yii\web\HttpException:404] 'yii\base\InvalidRouteException: Unable to resolve the request "configuration/user". in C:\laragon\www\meteorwms\backend\vendor\yiisoft\yii2\base\Module.php:561 Stack trace: #0 C:\laragon\www\meteorwms\backend\vendor\yiisoft\yii2\web\Application.php(103): yii\base\Module->runAction('configuration/u...', Array) #1 C:\laragon\www\meteorwms\backend\vendor\codeception\module-yii2\src\Codeception\Lib\Connector\Yii2.php(371): yii\web\Application->handleRequest(Object(yii\web\Request)) #2 C:\laragon\www\meteorwms\backend\vendor\symfony\browser-kit\AbstractBrowser.php(385): Codeception\Lib\Connector\Yii2->doRequest(Object(Symfony\Component\BrowserKit\Request)) #3 C:\laragon\www\meteorwms\backend\vendor\codeception\lib-innerbrowser\src\Codeception\Lib\InnerBrowser.php(243): Symfony\Component\BrowserKit\AbstractBrowser->request('GET', 'http://localhos...', Array, Array, Array, NULL, true)

any guidance in this is appreciated

in the last of error it returnns

Html: C:\laragon\www\meteorwms\backend\tests/_output\Api.CreateUserCest.createUserViaAPI.fail.html Response: C:\laragon\www\meteorwms\backend\tests/_output\Api.CreateUserCest.createUserViaAPI.fail.html Body:

Not Found: Page not found.

it is not catching the url through it , i have tried hitting the url with postman and it works fine , but i am not able to hit the url in the test case, am i missing something or is there any other requirement that need to be fulfilled ??

1 Answer 1

0

Solved the Issue , Needed to install a package for PhpBrowser , using the command

composer require codeception/module-phpbrowser --dev  ,

then run the build command

then set the Api.suite.yml as

actor: ApiTester
modules:
    enabled:
        - Yii2:
            configFile: 'codeception/config/api.php'
        - REST:
            depends: PhpBrowser  # Use PhpBrowser as backend
            url: http://localhost:4454/meteorwms/backend/web/index.php 

and then we can test

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.