Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dry-run on throws Return value must be of type int, Codeception\Util\Maybe returned in ... #6463

Closed
lonesoft opened this issue May 25, 2022 · 4 comments

Comments

@lonesoft
Copy link

What are you trying to achieve?

Dryrun my tests

What do you get instead?

Any Actions with a return type specified will throw:

PHP Fatal error: Uncaught TypeError: FunctionalTester::haveInDatabase(): Return value must be of type int, Codeception\Util\Maybe returned in ... tests/_support/_generated/FunctionalTesterActions.php:91

command

vendor/bin/codecept dry-run functional

result

Functional Tests (1) ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: \Helper\Functional, Db, \First4Figures\Magento\Codeception\Helper\Magento\Driver, \First4Figures\Magento\Codeception\Helper\Magento
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
TestCest: Test
Signature: TestCest:Test
Test: tests/functional/TestCest.php:Test
Scenario --
 I have in database "x",[]
PHP Fatal error:  Uncaught TypeError: FunctionalTester::haveInDatabase(): Return value must be of type int, Codeception\Util\Maybe returned in /mnt/d/Projects/vc2/mage/001.www/tests/_support/_generated/FunctionalTesterActions.php:91

tests/functional/TestCest.php

<?php
class TestCest
{
    public function Test(FunctionalTester $I){
        $I->haveInDatabase('x', []);
    }
}

tests/_support/_generated/FunctionalTesterActions.php (excerpt: return $this-> ... is on line 91)

    /**
     * [!] Method is generated. Documentation taken from corresponding module.
     *
     * Inserts an SQL record into a database. This record will be erased after the test.
     *
     * ```php
     * <?php
     * $I->haveInDatabase('users', array('name' => 'miles', 'email' => 'miles@davis.com'));
     * ```
     * @see \Codeception\Module\Db::haveInDatabase()
     */
    public function haveInDatabase(string $table, array $data): int {
        return $this->getScenario()->runStep(new \Codeception\Step\Action('haveInDatabase', func_get_args()));
    }

Details

  • Codeception version: 4.1.29
  • PHP Version: 8.1.5
  • Operating System: ubuntu on window subsystem for linux
  • Installation type: Composer
@Naktibalda
Copy link
Member

Thanks for report. If dry-run is important to you, downgrade codeception/module-db to 1.*

@lonesoft
Copy link
Author

Thank you for the feedback.
In truth the codeception/module-db was just an example, this behavior happens for any Action with return value.
In my opinion the intrinsic problem is that it does not make sense to return value during a dry-run.
However this would prevent the code to run as it throws errors.
A way to fix it would be to modify the template that generate the code above to return a default value for each type (e.g. false for bool, 0 for int etc.) if actual Action returns a Codeception\Util\Maybe.

@DavertMik
Copy link
Member

If you use grabbers this actually makes sense

@Naktibalda
Copy link
Member

Fixed in 4.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants