Skip to content

bug in PHPUnit Manual 9.5: Examples 2.9 #225

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

Closed
ricfio opened this issue Mar 28, 2021 · 0 comments
Closed

bug in PHPUnit Manual 9.5: Examples 2.9 #225

ricfio opened this issue Mar 28, 2021 · 0 comments

Comments

@ricfio
Copy link
Contributor

ricfio commented Mar 28, 2021

Problem

Q A
PHPUnit version 9.5.4
PHP version 8.0.1
Installation Method Composer

Fatal error: A void function must not return a value in /workspaces/phpunit-tutorial/www/tests/DependencyAndDataProviderComboTest.php on line 15

Fix

master...ricfio:ricfio-patch-2

How to reproduce

Example 2.9 Combination of @depends and @dataProvider in same test

<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;

final class DependencyAndDataProviderComboTest extends TestCase
{
    public function provider(): array
    {
        return [['provider1'], ['provider2']];
    }

    public function testProducerFirst(): void
    {
        $this->assertTrue(true);

        return 'first';
    }

    public function testProducerSecond(): void
    {
        $this->assertTrue(true);

        return 'second';
    }

    /**
     * @depends testProducerFirst
     * @depends testProducerSecond
     * @dataProvider provider
     */
    public function testConsumer(): void
    {
        $this->assertSame(
            ['provider1', 'first', 'second'],
            func_get_args()
        );
    }
}
# phpunit tests/DependencyAndDataProviderComboTest.php
Fatal error: A void function must not return a value in /workspaces/phpunit-tutorial/www/tests/DependencyAndDataProviderComboTest.php on line 15

How to solve

In tests/DependencyAndDataProviderComboTest.php apply this two fixes

-   public function testProducerFirst(): void
+   public function testProducerFirst(): string

-   public function testProducerSecond(): void
+   public function testProducerSecond(): string
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

1 participant