PHPUnit: “Invalid value passed to setPost()” when passing Zend_Db_Table_Row_Abstract converted using toArray()

StackOverflow https://stackoverflow.com/questions/3876743

문제

The following code fails throws a Zend_Controller_Exception ("Invalid value passed to setPost(); must be either array of values or key/value pair")

/** Model_Audit_Luminaire */
$luminaireModel = new Model_Audit_Luminaire();
if (!$fixture = $luminaireModel->getScheduleItem($scheduleId)) {
    $this->fail('Could not retrieve fixture from database');
}
$fixtureArray = $fixture->toArray();

$this->getRequest()
    ->setMethod('POST')
    ->setPost($fixtureArray);

I did a var_dump() to ensure $fixtureArray was the correct type, and formatted properly...no visible problems.

도움이 되었습니까?

해결책

Are any of the columns in your schedule item row nullable?

The setPost() method calls itself for each key/value pair you pass in an array. But if any value is null, it throws an exception.

You may have to loop over the array and setPost() only values that are non-null:

$this->getRequest()->setMethod("POST");
foreach ($fixtureArray as $key => $value) {
  if ($value === null) { continue; }
  $this->getRequest()->setPost($key, $value);
}

Or else ensure that the row you fetch from the database in your getScheduleItem() method contains no nulls.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top