Codeception / Codeception

Full-stack testing PHP framework
http://codeception.com
MIT License
4.76k stars 1.3k forks source link

Return values not being passed to dependent tests #6576

Closed zerioni closed 1 year ago

zerioni commented 1 year ago

What are you trying to achieve?

I have a test ends with a return value, and a dependent test that need to use that value: this type of setup from phpunit

What do you get instead?

Nothing is passed from the test with the return, the dependent test errors with too few arguments to function on the dependent test

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

Modules: Asserts, \Helper\Unit
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
✔ DependencyTest: Parent (0.03s)
E DependencyTest: Dependent (0.01s)
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 00:00.224, Memory: 24.00 MB

There was 1 error:
1) DependencyTest: Dependent
 Test  unit/DependencyTest.php:testDependent

  [ArgumentCountError] Too few arguments to function DependencyTest::testDependent(), 0 passed in /var/www/html/vendor/phpunit/phpunit/src/Framework/TestCase.php on line 1545 and exactly 1 expected  

#1  /var/www/html/tests/unit/DependencyTest.php:15
#2  /var/www/html/vendor/bin/codecept:117

ERRORS!
Tests: 2, Assertions: 0, Errors: 1.
Script $VENDORBIN/codecept run -c $APPLICATION_ROOT/tests 20-unit handling the unit event returned with error code 1

Provide test source code if related

<?php

use Codeception\PHPUnit\TestCase;

class DependencyTest extends TestCase
{
    public function testParent()
    {
        return 123;
    }

    /**
     * @depends testParent
     */
    public function testDependent(int $number)
    {
        $this->assertEquals(123, $number);
    }
}

Details

actor_prefix: Tester
paths:
  tests: .
  output: _output
  data: _data
  support: _support
  envs: _envs
bootstrap: _bootstrap.php
settings:
  colors: true
  memory_limit: 3072M
extensions:
  enabled:
    - Codeception\Extension\RunFailed
    - Codeception\Extension\ShareTestContext
    - Codeception\Extension\ReportSlowTests
    - Codeception\Extension\ReportEnvironment

Same test runs perfectly when called with PHPUnit directly

zerioni commented 1 year ago

Just commenting to add this thread from the Codeception Slack, indicating that this is a missed feature, and suggesting a possible fix: https://codeception.slack.com/archives/C93HPU7NZ/p1663341734485169

Naktibalda commented 1 year ago

@zerioni Could you install "codeception/codeception": "dev-pass-test-result-to-dependent-method as 5.0.99" and run your real testsuite that uses this feature to check if I haven't missed anything?

zerioni commented 1 year ago

@Naktibalda This works a treat! Flew through my dependent tests without a hiccup.