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

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

Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top