Yii Framework Forum: Run Codeception API Test with Yii2 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Run Codeception API Test with Yii2 Cannot get Codeception Test My API

#1 User is offline   Stefano Mtangoo 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 366
  • Joined: 02-January 12
  • Location:Dar es Salaam, Tanzania

Posted 18 July 2017 - 10:29 AM

I have been fighting with this problem for hours and cannot get through. I want to run API tests with Yii2 and (of course) Codeception. Here is my api.suite.yml

class_name: ApiTester
    	- REST:
        	url: /mobile
        	depends: Yii2
        	part: Json
    	- \Helper\Api
        	entryUrl: http://localhost:8080/index-test.php

and my test file UserLoginCept.php

$I = new ApiTester($scenario);
$I->wantTo('Test User Login');
$I->sendPOST('mobile/login', ['username' => 'uname', 'password' => '123456']);

Results are logged below. The problem is the Test is calling site/index which is in the root project not mobile module. I can sense that it is picking wrong URL somewhere as I cannot see any trace of the module being called. If I try URL on Browser it works fine http://localhost:808...obile/api/login


	"success": false,
	"token": ""


can someone help me spot what am doing wrong? I have read as much as I could could not find the issue.

Codeception Results:

Modules: REST, Yii2, \Helper\Api
UserLoginCept: Test User Login
Signature: UserLoginCept
Test: tests/api/UserLoginCept.php
Scenario --
 I send post "/mobile/api/login",{"username":"uname","password":"123456"}
  [Request] POST /mobile/mobile/api/login {"username":"uname","password":"123456"}
  [Request Headers] []
  [yii\db\Connection::open] 'Opening DB connection: mysql:host=localhost;dbname=database_name'

1) UserLoginCept: Test user login
 Test  tests/api/UserLoginCept.php

  [Error] Call to a member function isAdmin() on null  

Scenario Steps:

 1. $I->sendPOST("/mobile/api/login",{"username":"uname","password":"123456"}) at tests/api/UserLoginCept.php:4

#1  /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/View.php:328
#2  /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/View.php:250
#3  /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/Controller.php:396
#4  /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/Controller.php:382
#5  /Users/hosanna/Projects/Volcano/WebApp/controllers/SiteController.php:74
#6  app\controllers\SiteController->actionIndex
#7  /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/InlineAction.php:57
#8  /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/Controller.php:156
#9  /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/base/Module.php:523
#10 /Users/hosanna/Projects/Volcano/WebApp/vendor/yiisoft/yii2/web/Application.php:102
<!DOCTYPE html>
<html lang="en-US">
..... rest of HTML.....

Also asked in SO

And God said, Let there be science...and it was so! Jukwaa la wanaoongea Kiswahili Hapa, and its github repo here

Share this topic:

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users