You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TypeError: DataTest::testAdd(): Argument #1 ($a) must be of type int, string given, called in /workspaces/phpunit-tutorial/www/vendor/phpunit/phpunit/src/Framework/TestCase.php on line 1526
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class DataTest extends TestCase
{
/**
* @dataProvider additionProvider
*/
public function testAdd(int $a, int $b, int $expected): void
{
$this->assertSame($expected, $a + $b);
}
public function additionProvider(): CsvFileIterator
{
return new CsvFileIterator('data.csv');
}
}
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
final class CsvFileIterator implements Iterator
{
private $file;
private $key = 0;
private $current;
public function __construct(string $file)
{
$this->file = fopen($file, 'r');
}
public function __destruct()
{
fclose($this->file);
}
public function rewind(): void
{
rewind($this->file);
$this->current = fgetcsv($this->file);
$this->key = 0;
}
public function valid(): bool
{
return !feof($this->file);
}
public function key(): int
{
return $this->key;
}
public function current(): array
{
return $this->current;
}
public function next(): void
{
$this->current = fgetcsv($this->file);
$this->key++;
}
}
data.csv
0,0,0
0,1,1
1,0,1
1,1,3
# phpunit tests/DataTest.php
PHPUnit 9.5.4 by Sebastian Bergmann and contributors.
EEEE 4 / 4 (100%)
Time: 00:00.215, Memory: 4.00 MB
There were 4 errors:
1) DataTest::testAdd with data set #0 ('0', '0', '0')
TypeError: DataTest::testAdd(): Argument #1 ($a) must be of type int, string given, called in /workspaces/phpunit-tutorial/www/vendor/phpunit/phpunit/src/Framework/TestCase.php on line 1526
/workspaces/phpunit-tutorial/www/tests/DataTest.php:10
2) DataTest::testAdd with data set #1 ('0', '1', '1')
TypeError: DataTest::testAdd(): Argument #1 ($a) must be of type int, string given, called in /workspaces/phpunit-tutorial/www/vendor/phpunit/phpunit/src/Framework/TestCase.php on line 1526
/workspaces/phpunit-tutorial/www/tests/DataTest.php:10
3) DataTest::testAdd with data set #2 ('1', '0', '1')
TypeError: DataTest::testAdd(): Argument #1 ($a) must be of type int, string given, called in /workspaces/phpunit-tutorial/www/vendor/phpunit/phpunit/src/Framework/TestCase.php on line 1526
/workspaces/phpunit-tutorial/www/tests/DataTest.php:10
4) DataTest::testAdd with data set #3 ('1', '1', '3')
TypeError: DataTest::testAdd(): Argument #1 ($a) must be of type int, string given, called in /workspaces/phpunit-tutorial/www/vendor/phpunit/phpunit/src/Framework/TestCase.php on line 1526
/workspaces/phpunit-tutorial/www/tests/DataTest.php:10
ERRORS!
Tests: 4, Assertions: 0, Errors: 4.
Uh oh!
There was an error while loading. Please reload this page.
Problem
TypeError: DataTest::testAdd(): Argument #1 ($a) must be of type int, string given, called in /workspaces/phpunit-tutorial/www/vendor/phpunit/phpunit/src/Framework/TestCase.php on line 1526
Fix
master...ricfio:patch-1
How to reproduce
Example 2.7 Using a data provider that returns an Iterator object
Example 2.8 The CsvFileIterator class
data.csv
How to solve
In src/CsvFileIterator change this
with this
The text was updated successfully, but these errors were encountered: