Fork me on GitHub
a Sensio Labs Product

15 Keys (v3.53.0) edition

Rule php_unit_data_provider_return_type

The return type of PHPUnit data provider must be iterable.

Description

Data provider must return iterable, either an array of arrays or an object that implements the Traversable interface.

Warning

Using this rule is risky

Risky when relying on signature of the data provider.

Examples

Example #1

--- Original
+++ New
 <?php
 class FooTest extends TestCase {
     /**
      * @dataProvider provideSomethingCases
      */
     public function testSomething($expected, $actual) {}
-    public function provideSomethingCases(): array {}
+    public function provideSomethingCases(): iterable {}
 }

Example #2

--- Original
+++ New
 <?php
 class FooTest extends TestCase {
     /**
      * @dataProvider provideSomethingCases
      */
     public function testSomething($expected, $actual) {}
-    public function provideSomethingCases() {}
+    public function provideSomethingCases(): iterable {}
 }

Rule sets

The rule is part of the following rule set:

References

The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.