public function test_getter_and_setter() { $s = new Saldo(); $this->assertNull($s->getCurrency()); $this->assertNull($s->getAmount()); $this->assertNull($s->getValuta()); // test currency $s->setCurrency('EUR'); $this->assertSame('EUR', $s->getCurrency()); // test amount $s->setAmount(12.0); $this->assertSame(12.0, $s->getAmount()); $d = new \DateTime(); $s->setValuta($d); $this->assertEquals($d, $s->getValuta()); }
/** * Creates a Saldo model from array. * * @param array $array * @return Saldo * @throws \Exception */ protected function createModelFromArray(array $array) { $model = new Saldo(); $saldoDeg = $this->splitDeg($array[3]); $amount = str_replace(',', '.', $saldoDeg[1]); $creditDebit = trim($saldoDeg[0]); if (static::SALDO_DEBIT == $creditDebit) { $amount = -(double) $amount; } elseif (static::SALDO_CREDIT == $creditDebit) { $amount = (double) $amount; } else { throw new \Exception('Invalid Soll-Haben-Kennzeichen: ' . $creditDebit); } $model->setAmount($amount); $model->setCurrency($saldoDeg[2]); $valutaDate = $saldoDeg[3]; preg_match('/(\\d{4})(\\d{2})(\\d{2})/', $valutaDate, $m); $valutaDate = new \DateTime($m[1] . '-' . $m[2] . '-' . $m[3]); $model->setValuta($valutaDate); return $model; }