1

I'm trying to setup some Codeception tests to test an API that I'm building but I seem to be doing something wrong.

Following a tutorial* I have run php codecept.phar generate:suite api which creates the ./tests/api.suite.yml file which looks like this:

class_name: ApiTester
    modules:
        enabled:
            - \Helper\Api

I modified this file to be the same as the one in the tutorial (adding my URL) like this:

class_name: ApiTester
    modules:
        enabled:
          - REST:
              url: http://serviceapp/api/v1/
              depends: PhpBrowser

And then generate a test script generate:cept api ReadUser and add my tests such as

<?php 

$I = new ApiTester($scenario);
$I->wantTo('perform actions and see result');
$I->sendGet('/user/1');

However when I run the test I get the error Call to undefined method ApiTester::sendGet

What do I need to add to have methods like sendGet, sendPost and all the others available?

The Codeception version is 2.1.5

*http://codeception.com/docs/10-WebServices

Fixed: I removed the tests directory and started again and it is working now. Not sure what is different. Yii2 build the tests path initially so maybe it did something different.

Dubby
  • 2,290
  • 4
  • 27
  • 38

1 Answers1

0

It's important to pay attention to upper and lower case writing. The name of the method is $I->sendGET() (uppercase GET).

Try this

<?php 

  $I = new ApiTester($scenario);
  $I->wantTo('perform actions and see result');
  $I->sendGET('/user/1');
rickroyce
  • 950
  • 11
  • 24