PHPUnit: “Valore non valido passato a setPost ()” quando passa Zend_Db_Table_Row_Abstract convertiti usando toArray ()

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

Domanda

Il seguente codice non getta uno Zend_Controller_Exception ( "valore valido passato a setPost (); deve essere o array di valori o chiave coppia valore /")

/** 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);

Ho fatto un var_dump () per assicurare $ fixtureArray era il tipo corretto, e formattata correttamente ... problemi visibili.

È stato utile?

Soluzione

Sono una delle colonne nel vostro programma di fila elemento annullabile?

Il metodo setPost() si definisce per ogni coppia chiave / valore si passa in un array. Ma se un valore è nullo, viene generata un'eccezione.

Potrebbe essere necessario un loop all'interno di array e setPost() solo i valori che sono non nullo:

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

Oppure assicurarsi che la fila si recupera dal database nel metodo getScheduleItem() non contiene valori null.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top