Codeception: ApiTester Asserts Not Available

Created on 22 Nov 2017  路  4Comments  路  Source: Codeception/Codeception

What are you trying to achieve?

Use asserts in ApiTester.

What do you get instead?

[RuntimeException] Call to undefined method ApiTester::assertEquals

Provide console output if related. Use -vvv mode for more details.

Codeception PHP Testing Framework v2.3.6
Powered by PHPUnit 6.4.4 by Sebastian Bergmann and contributors.

Test.api Tests (1) --------------------------------------------------------------------------------------------------------
Modules: Asserts, REST, Laravel5, \Test\Helper\Api
---------------------------------------------------------------------------------------------------------------------------------
TestCest: Test
Signature: TestCest:test
Test: tests/api/Http/Controllers/v1/TestCest.php:test
Scenario --
  [Database] Transaction started
 ERROR 

  [Database] Transaction cancelled; all changes reverted.
---------------------------------------------------------------------------------------------------------------------------------


Time: 5.97 seconds, Memory: 14.00MB

There was 1 error:

---------
1) TestCest: Test
 Test  tests/api/Http/Controllers/v1/TestCest.php:test

  [RuntimeException] Call to undefined method ApiTester::assertEquals  

/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/Actor.php:44
/home/vagrant/Code/api.application.app/public_html/modules/Test/Tests/tests/api/Http/Controllers/v1/TestCest.php:61
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/Lib/Di.php:127
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/Test/Cest.php:136
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/Test/Cest.php:148
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/Test/Cest.php:82
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/Test/Test.php:87
/home/vagrant/Code/api.application.app/public_html/vendor/phpunit/phpunit/src/Framework/TestSuite.php:744
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php:106
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/SuiteManager.php:157
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/Codecept.php:188
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/Codecept.php:157
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/Command/Run.php:341
/home/vagrant/Code/api.application.app/public_html/vendor/symfony/console/Command/Command.php:240
/home/vagrant/Code/api.application.app/public_html/vendor/symfony/console/Application.php:860
/home/vagrant/Code/api.application.app/public_html/vendor/symfony/console/Application.php:218
/home/vagrant/Code/api.application.app/public_html/vendor/symfony/console/Application.php:122
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/src/Codeception/Application.php:103
/home/vagrant/Code/api.application.app/public_html/vendor/codeception/codeception/codecept:36


ERRORS!
Tests: 1, Assertions: 0, Errors: 1.

Provide test source code if related

<?php

class TestCest
{
    /**
     * Api Helper
     *
     * @var \Helper\Api
     */
    protected $api;

    /**
     * Load required helpers for cest
     *
     * @param \Helper\Api $api
     */
    protected function _inject(\Helper\Api $api): void
    {
        $this->api = $api;
    }

    /**
     * Actions executed before cest
     *
     * @param ApiTester $I
     */
    public function _before(ApiTester $I): void
    {
    }

    /**
     * Actions executed after cest
     *
     * @param ApiTester $I
     */
    public function _after(ApiTester $I): void
    {
    }

    public function test(ApiTester $I)
    {
        $I->assertEquals(1, 1);
    }
}

Details

  • Codeception version: ^2.3
  • PHP Version: 7.1
  • Operating System: Ubuntu 16.04.3 LTS
  • Installation type: Composer
  • List of installed packages (composer show)
  • Suite configuration:
class_name: ApiTester
modules:
    enabled:
        - Asserts
        - REST:
            url: /v1/sportsbook
            depends: Laravel5
        - Laravel5:
            bootstrap: ../../../bootstrap/app.php
            vendor_dir: ../../../vendor
            environment_file: .env.testing
            cleanup: true
            run_database_migrations: true
        - \Sportsbook\Helper\Api

Most helpful comment

Wow! Thank you. It's only require to adding " - Asserts" module in config file and run codecept build!

All 4 comments

One possible sulution is to include \Codeception\Util\Shared\Asserts trait But still not sure about why I'm not able to call directly through ApiTester.

Strange... It should be there!
COuld you try to executed

codecept build

and try to look into _support/_generated/ApiActions.php to see if assertions are there

Worked like a charm!

Wow! Thank you. It's only require to adding " - Asserts" module in config file and run codecept build!

Was this page helpful?
0 / 5 - 0 ratings