示例#1
0
 /**
  * @covers ::evaluate
  */
 public function testStringAmount()
 {
     $money = new Money();
     $money->setValue(['amount' => '50', 'currency' => 'XTS']);
     $this->assertTrue($money->isValid());
     $obj = $money->evaluate();
     $this->assertInstanceOf('SebastianBergmann\\Money\\Money', $obj);
     $this->assertSame(50, $obj->getAmount());
     $this->assertEquals(new \SebastianBergmann\Money\Currency('XTS'), $obj->getCurrency());
 }
 public function testHasAmount()
 {
     $obj = new MoneyTest_DataObject();
     $m = new Money();
     $obj->MyMoney = $m;
     $m->setValue(array('Amount' => 1));
     $this->assertTrue($obj->MyMoney->hasAmount());
     $m->setValue(array('Amount' => 1.0));
     $this->assertTrue($obj->MyMoney->hasAmount());
     $m->setValue(array('Amount' => 1.01));
     $this->assertTrue($obj->MyMoney->hasAmount());
     $m->setValue(array('Amount' => 0.99));
     $this->assertTrue($obj->MyMoney->hasAmount());
     $m->setValue(array('Amount' => 0.01));
     $this->assertTrue($obj->MyMoney->hasAmount());
     $m->setValue(array('Amount' => 0));
     $this->assertFalse($obj->MyMoney->hasAmount());
     $m->setValue(array('Amount' => 0.0));
     $this->assertFalse($obj->MyMoney->hasAmount());
     $m->setValue(array('Amount' => 0.0));
     $this->assertFalse($obj->MyMoney->hasAmount());
 }
 function testWriteToDataObject()
 {
     $obj = new MoneyTest_DataObject();
     $m = new Money();
     $m->setValue(array('Currency' => 'EUR', 'Amount' => 1.23));
     $obj->MyMoney = $m;
     $obj->write();
     $this->assertEquals('EUR', DB::query(sprintf('SELECT "MyMoneyCurrency" FROM "MoneyTest_DataObject" WHERE "ID" = %d', $obj->ID))->value());
     $this->assertEquals('1.23', DB::query(sprintf('SELECT "MyMoneyAmount" FROM "MoneyTest_DataObject" WHERE "ID" = %d', $obj->ID))->value());
 }
示例#4
0
 /**
  * Set the value of this field in various formats.
  * Used by {@link DataObject->getField()}, {@link DataObject->setCastedField()}
  * {@link DataObject->dbObject()} and {@link DataObject->write()}.
  * 
  * As this method is used both for initializing the field after construction,
  * and actually changing its values, it needs a {@link $markChanged}
  * parameter. 
  * 
  * @param DBField|array $value       Value to set
  * @param array         $record      Map of values loaded from the database
  * @param boolean       $markChanged Indicate wether this field should be marked changed. 
  *                                   Set to FALSE if you are initializing this field after construction, rather
  *                                   than setting a new value.
  * 
  * @return void
  */
 public function setValue($value, $record = null, $markChanged = true)
 {
     return parent::setValue($value, $record, $markChanged);
 }