So I just started using PHPUnit and I’m writing tests for a very simple library. It only consists of two classes so I figured it would be great place to start so I can get the hang of how Unit Testing works.
I made first class tests without any problems, but second one gives me a headache because I just can’t figure out whats wrong with this. It seems to be some error with my data provider.
<?php
use PIFlex\Roulette\Roulette;
class RouletteTest extends PHPUnit_Framework_TestCase
{
protected $roulette;
public function setUp()
{
$this->roulette = new Roulette();
}
/*
* @dataProvider addItemDataProvider
*/
public function testAddItem($item)
{
$this->assertInstanceOf(
'PIFlex\Roulette\Roulette',
$this->roulette->addItem($item, 1)
);
}
public function addItemDataProvider()
{
return array(
array("string"),
array(1),
);
}
}
It throws me the following error:
There was 1 error:
1) RouletteTest::testAddItem
Missing argument 1 for RouletteTest::testAddItem()
/home/igor/Dropbox/www/Github/PIFlexRoulette/test/PHPUnit/Roulette/RouletteTest.php:22
FAILURES!
Tests: 12, Assertions: 11, Errors: 1.
You have wrong annotation comment. It should started with “**”, so just change:
into: