I'm learning Zend and also PHPUnit.
Here is what I have below
public function changeToIllegalState()
{
return array(
array( Application_Model_SomeModel::FAIL ),
array( Application_Model_SomeModel::SUCCESS )
);
}
/**
* @dataProvider changeToIllegalState
* @expectedException IllegalStateChangeException
*/
public function testIllegalStateChangeGeneratesException( $state )
{
$mapper = new Application_Model_Mapper_SomeModel();
$model = new Application_Model_SomeModel();
$model->changeState( $state );
$mapper->save( $model );
}
So as you can see here, the data provider provides some constants that represent different states from the model.
PHPUnit says that it can't find the Model class in the dataprovider method. However, if I try to use the constants within the test methods, it all works and there are no problems. I'm using the Zend autoloader to load my classes and it has all been dandy up till now. I know that I could just put in the values for the constants themselves, but I don't know why I'm getting this error.
I can only assume that the dataprovider methods are called before the setup method is called because I do all the autoloading business in the setup method.
EDIT :
I have also tried the following but it still won't work with the class consts.
protected $_FAIL;
protected $_model;
public function setUp()
{
parent::setUp();
$this->_model = new Application_Model_SomeModel();
$this->_FAIL = Application_Model_SomeModel::FAIL;
}
Now, when I try to use $_FAIL in the provider method I get a NULL value instead of the 'fail' string that I'm expecting. This is really weird.
$class = new ReflectionClass("Application_Model_SomeModel"); var_dump(class->getConstants())
andvar_dump(FAIL);
(without quotes) output when you write it in the setUp() ? – Valdes