aWuttig / codeception-api-validator

Validate API Requests and Responses against Swagger / OpenAPI definitions
18 stars 5 forks source link

Fatal error: Too few arguments to function Codeception\Module\ApiValidator::_inject() #2

Open tbreuss opened 2 years ago

tbreuss commented 2 years ago

Trying to test with your package fails with the following fatal error.

$ php vendor/bin/codecept run
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Codeception\Module\ApiValidator::_inject(), 1 passed and exactly 2 expected in /app/vendor/awuttig/codeception-api-validator/src/ApiValidator.php:139
Stack trace:
#0 [internal function]: Codeception\Module\ApiValidator->_inject(Object(Codeception\Module\REST))
#1 /app/vendor/codeception/codeception/src/Codeception/Lib/ModuleContainer.php(380): call_user_func_array(Array, Array)
#2 /app/vendor/codeception/codeception/src/Codeception/Lib/ModuleContainer.php(132): Codeception\Lib\ModuleContainer->injectModuleDependencies('ApiValidator', Object(Codeception\Module\ApiValidator))
#3 /app/vendor/codeception/codeception/src/Codeception/SuiteManager.php(70): Codeception\Lib\ModuleContainer->create('ApiValidator')
#4 /app/vendor/codeception/codeception/src/Codeception/Codecept.php(203): Codeception\SuiteManager->__construct(Object(Symfony\Component\EventDispatcher\EventDispatcher), 'acceptance', Array)
#5 /app/vendor/codeception/codeception/src/Codeception/Code in /app/vendor/awuttig/codeception-api-validator/src/ApiValidator.php on line 139

My codeception setup is:

actor: AcceptanceTester
modules:
    enabled:
        - REST:
              depends: PhpBrowser
              url: http://localhost/api/
              shortDebugResponse: 300
        - ApiValidator:
              depends: REST
              schema: '/openapi/openapi.v1.yaml'            
step_decorators: ~

My relevant composer packages are:

awuttig/codeception-api-validator  1.1.0   Validate API Requests and Responses against Swagger / OpenAPI definitions
codeception/codeception            4.2.2   BDD-style testing framework
codeception/lib-asserts            1.13.2  Assertion methods used by Codeception core and Asserts module
codeception/lib-innerbrowser       1.5.1   Parent library for all Codeception framework modules and PhpBrowser
codeception/module-asserts         1.3.1   Codeception module containing various assertions
codeception/module-phpbrowser      1.0.3   Codeception module for testing web application over HTTP
codeception/module-rest            1.4.2   REST module for Codeception
codeception/phpunit-wrapper        9.0.9   PHPUnit classes used by Codeception
codeception/stub                   4.0.2   Flexible Stub wrapper for PHPUnit's Mock Builder

And I'm running PHP 7.4.

tbreuss commented 2 years ago

Tried it also with ApiTester actor.

actor: ApiTester
modules:
    enabled:
        - REST:
              url: http://serviceapp/api/v1/
              depends: PhpBrowser
        - ApiValidator:
              depends: REST
              schema: '/openapi/openapi.v1.yaml'              
        - \Helper\Api

Is failing when trying to php vendor/bin/codecept run, too.

The error is about the same like above.

FATAL ERROR. TESTS NOT FINISHED.
Uncaught ArgumentCountError: Too few arguments to function Codeception\Module\ApiValidator::_inject(), 1 passed and exactly 2 expected in /app/vendor/awuttig/codeception-api-validator/src/ApiValidator.php:139
Stack trace:
#0 [internal function]: Codeception\Module\ApiValidator->_inject(Object(Codeception\Module\REST))
#1 /app/vendor/codeception/codeception/src/Codeception/Lib/ModuleContainer.php(380): call_user_func_array(Array, Array)
#2 /app/vendor/codeception/codeception/src/Codeception/Lib/ModuleContainer.php(132): Codeception\Lib\ModuleContainer->injectModuleDependencies('ApiValidator', Object(Codeception\Module\ApiValidator))
#3 /app/vendor/codeception/codeception/src/Codeception/SuiteManager.php(70): Codeception\Lib\ModuleContainer->create('ApiValidator')
#4 /app/vendor/codeception/codeception/src/Codeception/Codecept.php(203): Codeception\SuiteManager->__construct(Object(Symfony\Component\EventDispatcher\EventDispatcher), 'api', Array)
#5 /app/vendor/codeception/codeception/src/Codeception/Codecept.ph 
in /app/vendor/awuttig/codeception-api-validator/src/ApiValidator.php:139
addow commented 2 years ago

@tbreuss I was able to fix it by defining an extra (required) dependency: [REST, PhpBrowser] or in my case [REST, Laravel]

actor: AcceptanceTester
modules:
    enabled:
        - PhpBrowser:
              url: &url 'http://localhost/api/'
        - REST:
              depends: PhpBrowser
              url: *url
              shortDebugResponse: 300
        - ApiValidator:
              depends: [REST, PhpBrowser]
              schema: '/openapi/openapi.v1.yaml'            
step_decorators: ~

or with the ApiTester actor:

actor: ApiTester
modules:
    enabled:
        - PhpBrowser:
              url: &url 'http://serviceapp/api/v1/'
        - REST:
              depends: PhpBrowser
              url: *url
        - ApiValidator:
              depends: [REST, PhpBrowser]
              schema: '/openapi/openapi.v1.yaml'              
        - \Helper\Api
tbreuss commented 2 years ago

@addow Great, thanks. I will try this the next days.