You need a value (array item) for each input to the test method:
public function precomputedCodes()
{
return [
'precomputed_dataset' => [
["V101", "0000"],
["X101", "1111"],
],
];
}
Summer Sale! All accounts are 50% off this week.
I'm trying to set up a unit test to make sure that a method that transforms an input returns the output it should, and am doing this with a DataProvider. "8805" is the result returned when "0000" is passed to my decoder method, so both the values 0000 and 1111 - the rightmost column of the data - are being passed into the decoder used while seemingly ignoring the leftmost column entirely.
I'm pretty sure the error is in the array syntax for my data provider, but given that I have a few hundred values it isn't easy to see where, and I'd like to both a) understand exactly what I'm doing wrong and b) be sure that my tests are working exactly as I expect them to.
My unit test:
class DecoderTest extends TestCase
{
/**
*
*
* @dataProvider precomputedCodes
* @return void
*/
public function testDecoder($input, $output)
{
$manufacturer = new Manufacturer;
$this->assertEquals($output, $manufacturer->decoder($input));
}
public function precomputedCodes()
{
return [
"precomputed_dataset" => [
"V101" => "0000",
"X101" => "1111",
// a few hundred more values
],
];
}
}
The result of running php artisan test:
Warning: TTY mode is not supported on Windows platform.
FAIL Tests\Unit\DecoderTest
⨯ decoder with data set "precomputed_dataset"
---
• Tests\Unit\DecoderTest > decoder with data set "precomputed_dataset"
Failed asserting that two strings are equal.
at D:\Users\CurrentUser\Documents\Projects\Websites\Project\tests\Unit\DecoderTest.php:24
22▕
23▕ $manufacturer = new Manufacturer;
➜ 24▕ $this->assertEquals($output, $manufacturer->decoder($input));
25▕ }
26▕
27▕ public function precomputedCodes()
28▕ {
1 D:\Users\CurrentUser\Documents\Projects\Websites\Project\vendor\phpunit\phpunit\phpunit:98
PHPUnit\TextUI\Command::main()
--- Expected
+++ Actual
@@ @@
-'1111'
+'8805'
Tests: 1 failed
Time: 0.04s
@Hashim you don't need the key and wrapping array:
public function precomputedCodes()
{
return [
["V101", "0000"],
["X101", "1111"],
];
}
Please or to participate in this conversation.