Yii Framework Forum: Can not get REST tests to work - Yii Framework Forum

Jump to content

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

Can not get REST tests to work

#1 User is offline   Jonny 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 26-December 11

Posted 23 October 2017 - 08:41 AM

Hi

I feel like I've tried a 100 different variations of this to try and get REST working but not managed to get it yet.

I seem to get either

Quote

[GuzzleHttp\Exception\RequestException] cURL error 3: <url> malformed (see http://curl.haxx.se/...url-errors.html)


or

Quote

[yii\base\InvalidParamException] Unable to resolve the relative route: report/index. No active controller is available.


This is my config:

class_name: ApiTester
modules:
    enabled:
      - REST:
          depends: PhpBrowser
          url: /api/
          part: Json
      - Yii2:
          part: [orm, fixtures]
          configFile: 'config/web.php'


I have this in my urlManager:

 [
                'class' => 'yii\rest\UrlRule',
                'controller' => ['api/report'],
             ],


These tests work in postman, the URL I'm trying to access is/api/reports. Which is just the inherited RESTful controller route. I think this is a problem with urlManager not being loaded. But I know the config file is loaded.


    public function userIsNotAuthenticated(\ApiTester $I)
    {
        $I->amGoingTo('Test a non-authenticated person can\'t log in');
        $I->sendGET(Url::toRoute('report/index')); // Unable to resolve the relative route: report/index. No active controller is available.
        // $I->sendGET('reports'); //doesn't work cURL error 3: <url> malformed (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
        $I->seeResponseCodeIs(\Codeception\Util\HttpCode::UNAUTHORIZED); // 401
    }


Not sure what i've done wrong here?
0

#2 User is offline   Jonny 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 240
  • Joined: 26-December 11

Posted 26 October 2017 - 08:59 AM

I had to make the url absolute.
$I->sendGET(Url::toRoute('/api/reports', true)); 


But I still can't authenticate. I've tried,

$I->amHttpAuthenticated('my_email', 'my_password');
$I->haveHttpHeader('Authorization', 'Basic super long token goes here');


The Authorization header works for postman requests :unsure:
0

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