I’ve problem when I used PHPUnit test framework Yii in Netbeans.
I’ve a class DemoController.php extends from class Controller of Yii. And I’ve a class DemoControllerTest.php.
I can test all function in class by PHPUnit, but when I used @group annotation (support by PHPUnit) to test a group function. It not runs.
DemoController.php:
class DemoController extends Controller {
public function add($a, $b)
{
return $a + $b;
}
}
DemoControllerTest.php:
require_once dirname(__FILE__) . '/../fixtures/dataProvider.php';
require_once dirname(__FILE__) . '/../controllers/DemoController.php';
class DemoControllerTest extends PHPUnit_Framework_TestCase{
protected $object;
protected function setUp() {
$this->object = new Calculator;
}
/**
* @group Calculator
*
* @dataProvider dataProvider
*/
public function testCalculator($expectValue, $inputA, $inputB) {
$this->assertEquals($expectValue, $this->object->add($inputA, $inputB));
}
function dataProvider(){
$result = dataProvider::dataProvider();
return $result;
}
}
And here is dataProvider.php:
class dataProvider {
static function dataProvider(){
return array(
array(0, 0, 0),
array(0, 1, 1),
array(1, 0, 1),
array(1, 1, 3)
);
}
}
To use test groups in NetBeans you need to ensure that you have the settings configured correctly for your project. Ensure that your tests are annotated correctly with the group notation
@group group-name. Then in your project properties ensure that the checkbox for test groups is checked.Then when you run your tests you will see a dialog popup with a selection of your groups.
If you don’t see the dialog box above when you press
Ctrl+F6then try right clicking on the file and selectingTest. For more information see the Netbeans PHPUnit documentation.