A PHPUnit data provider allows the return of an iteratorですが、AppendIteratorを使用する場合は、最後のイテレーターのみを使用します。 PHPUnitデータプロバイダとしてAppendIteratorsを使用できないのですか?phpunitとAppendIteratorデータプロバイダ?
テストファイル:
<?php
use PHPUnit\Framework\TestCase;
class AppendIteratorTest extends TestCase
{
/**
* @dataProvider getAppendIterator
*/
public function testAppendIterator($item) {
echo PHP_EOL."test> $item".PHP_EOL;
}
public function getAppendIterator() {
$iterator = new AppendIterator();
$iterator->append(new ArrayIterator([[0], [1]]));
$iterator->append(new ArrayIterator([[2], [3]]));
$iterator->append(new ArrayIterator([[4], [5]]));
foreach($iterator as $i) {
echo 'foreach> '.print_r($i, true);
}
return $iterator;
}
}
テストファイル出力:
$ vendor/bin/phpunit --debug AppendIteratorTest.php
foreach> Array
(
[0] => 0
)
foreach> Array
(
[0] => 1
)
foreach> Array
(
[0] => 2
)
foreach> Array
(
[0] => 3
)
foreach> Array
(
[0] => 4
)
foreach> Array
(
[0] => 5
)
PHPUnit 6.2.3 by Sebastian Bergmann and contributors.
Starting test 'AppendIteratorTest::testAppendIterator with data set #0 (4)'.
R
test> 4
Starting test 'AppendIteratorTest::testAppendIterator with data set #1 (5)'.
R 2/2 (100%)
test> 5
Time: 24 ms, Memory: 4.00MB
There were 2 risky tests:
1) AppendIteratorTest::testAppendIterator with data set #0 (4)
This test did not perform any assertions
2) AppendIteratorTest::testAppendIterator with data set #1 (5)
This test did not perform any assertions
OK, but incomplete, skipped, or risky tests!
Tests: 2, Assertions: 0, Risky: 2.
THANKS @hakre!あなたの答えを読んだので、それは完全に意味があります。 – Shawn