0

So I installed codeception/module-rest and created an api.suite.yml containing:

modules:
  enabled:
    - Helper\JoomlaDb
    - Helper\Api
  config:
    Helper\JoomlaDb:
      dsn: "mysql:host=127.0.0.1;dbname=test"
      user: "root"
      password: "*****"
      prefix: "jos_"
    Helper\Api:
      MicrosoftEdgeInsiders: false 
      # localUser: "www-data" 

Then i updated the helper class with php vendor/bin/codecept build.

When starting one of the default api tests like this:

php vendor/bin/codecept run "tests/codeception/api/com_content/" -v --html --fail-fast 

I get an [RuntimeException] Call to undefined method ApiTester::amBearerAuthenticated

The default Joomla 4 tests looks like this:

public function testCrudOnArticle(ApiTester $I)
{
    $I->amBearerAuthenticated($I->getBearerToken());
    $I->haveHttpHeader('Content-Type', 'application/json');
    $I->haveHttpHeader('Accept', 'application/vnd.api+json');
    ...

When taking a look in the generated ApiTesterActions.php file there is only a getBearerToken Function included (besides all DB function).

What needs to be done, so all needed REST functions like amBearerAuthenticated get included in the generated ApiTesterActions.php file and can be used?

1 Answer 1

1

So the issue was that using the original api.suite.yml did not work for me. It looks like this:

actor: ApiTester
modules:
  enabled:
    - Helper\JoomlaDb
    - Helper\Api
  config:
    Helper\JoomlaDb:
      dsn: "mysql:host=127.0.0.1;dbname=test"
      user: "root"
      password: "*****"
      prefix: "jos_"
    Helper\Api:
      MicrosoftEdgeInsiders: falseInsiders
      # localUser: "www-data"
env:
   mysql:
     modules:
       enabled:
         - REST:
             url: http://127.0.0.1:8000/api/index.php/v1
             depends: PhpBrowser
             part: Json
       config:
         Helper\Api:
           url: "http://127.0.0.1:8000"
           cmsPath: "/"

Whats working for me is dropping the env databases and running it like this:

actor: ApiTester
modules:
  enabled:
    - Helper\JoomlaDb
    - Helper\Api
    - REST:
        url: http://127.0.0.1:8000/api/index.php/v1
        depends: PhpBrowser
        part: Json
  config:
    Helper\JoomlaDb:
      dsn: "mysql:host=127.0.0.1;dbname=test"
      user: "root"
      password: "*****"
      prefix: "jos_"
    Helper\Api:
      MicrosoftEdgeInsiders: falseInsiders
      # localUser: "www-data"

That way the REST functions get generated inside the ApiTesterActions.php

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.