Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Rules/PHPUnit/EmptyDataProviderRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function processNode(Node $node, Scope $scope): array
foreach ($returnStatements as $returnStatement) {
$returnExpr = $returnStatement->getReturnNode()->expr;
if ($returnExpr === null) {
return [];
continue;
}

$returnType = $returnStatement->getScope()->getType($returnExpr);
Expand Down
4 changes: 4 additions & 0 deletions tests/Rules/PHPUnit/EmptyDataProviderRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public function testRule(?int $version): void
'Data provider method provideData() provides no data sets, which is an error in PHPUnit 10 and newer.',
158,
];
$errors[] = [
'Data provider method provideData() provides no data sets, which is an error in PHPUnit 10 and newer.',
190,
];
Comment on lines +66 to +69

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➜  phpstan-phpunit git:(impr) ✗ cat test.php                
<?php

use PHPUnit\Framework\TestCase;

class BareReturnTest extends TestCase
{

        /**
         * @dataProvider provideData
         */
        public function testFoo(string $input): void
        {
        }

        public static function provideData(bool $flag = false)
        {
                if ($flag) {
                        return;
                }

                return [];
        }

}
➜  phpstan-phpunit git:(impr) ✗ vendor/bin/phpunit test.php
PHPUnit 11.5.57 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.5.12
Configuration: /Users/m.staab/dvl/phpstan-phpunit/phpunit.xml
Random Seed:   1794502306

There was 1 PHPUnit error:

1) BareReturnTest::testFoo
The data provider specified for BareReturnTest::testFoo is invalid
Data Provider method BareReturnTest::provideData() expects an argument

/Users/m.staab/dvl/phpstan-phpunit/test.php:11

--

There was 1 PHPUnit test runner warning:

1) No tests found in class "BareReturnTest".

No tests executed!

}

// DataProviderHelper only reads the attribute when the detected major version supports it.
Expand Down
22 changes: 22 additions & 0 deletions tests/Rules/PHPUnit/data/empty-data-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,25 @@ public static function provideData(bool $flag = false)
}

}

class IteratorWithEmptyReturn extends \PHPUnit\Framework\TestCase
{

/**
* @return iterable<mixed>
*/
public function dataFileAsserts(): iterable
{
if (PHP_VERSION_ID >= 80000) {
return [];
}

yield 1;
yield 2;
}

/**
* @dataProvider dataFileAsserts
*/
public function testFileAsserts() {}
}
Loading