|
From: Jason S. <jsw...@ya...> - 2003-11-26 04:57:15
|
class TestPlant extends UnitTestCase
{
function TestPlant(){
$this->UnitTestCase();
Mock::Generate('DataCache');
}
function Setup() {
$this->_moCache =& new MockDataCache($this);
$this->_moCache->SetReturnValue('IsCached', false);
$this->_moCache->SetReturnValueAt(0, 'IsCached', true);
}
function TestGetInvt(){
$o_cache =& $this->_moCache;
$s_id = PLANT_CACHE_ID.TEST_PLANT_ID;
$a_test_val = array(100000,200000,300000);
//this gives array key errors in expectation.php (228 and 231)
//$o_plant =& $this->NewPlant();
$o_cache->SetReturnValue('IsCached', true, array($s_id));
$o_cache->SetReturnValue('GetCache', array('invt' => $a_test_val),
array($s_id));
// this works fine
$o_plant =& $this->NewPlant();
$this->AssertTrue($a_invt = $o_plant->GetInvt(), 'Inventory list has
values');
$this->AssertEqual($a_test_val, $a_invt);
}
function &NewPlant()
{
$o =& new Plant(TEST_PLANT_ID, $this->_moCache);
return $o;
}
}
Plant looks like:
class Plant
{
function Plant($piId, &$poCache){
if (!$poCache->IsCached(PLANT_CACHE_ID.$piId)) {
trigger_error("Plant Id '$piId' is not setup");
$this = NULL;
return;
}
$this->_moCache =& $poCache;
$this->_maData = $poCache->GetCache(PLANT_CACHE_ID.$piId);
}
function GetInvt(){
return $this->_maData['invt'];
}
}
I believe everything is being passed by ref okay. Can't figure out why the
location of the factory method call would cause the errors. I put the
Mock::Genrate() in the constructor so it will only get called once for the test
case. I do now understand that SetUp() is called for each test method ;), but
that still looks fine to me, the test should be independant of all others, and
should be using the current $this->_moCache created by SetUp() for the
TestGetInvt() method. I had tried eliminating the intermediate variable
($o_cache) without an impact on the problems as well.
Any thoughts?
Jason
__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/
|