Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function subtract(Money $other)
 {
     $toSub = new BaseMoney($other->getAmount(), $other->getCurrency());
     $result = $this->valueObject->subtract($toSub);
     return new static(['amount' => $result->getAmount(), 'currency' => $this->currency]);
 }
Ejemplo n.º 2
0
 public function testSubtract()
 {
     $mocks['currency'] = $this->getMockBuilder('\\SerendipityHQ\\Component\\ValueObjects\\Currency\\Currency')->disableOriginalConstructor()->getMock();
     $mocks['currency']->method('getSubUnit')->willReturn(100);
     $mocks['currency']->method('getDefaultFractionDigits')->willReturn(2);
     $test = ['amount' => 100, 'currency' => $mocks['currency']];
     $resource = new Money($test);
     $toAdd = new Money($test);
     $result = $resource->subtract($toAdd);
     // Test the value object direct interface
     $this->assertInstanceOf(MoneyInterface::class, $result);
     // Test the type of value object interface
     $this->assertInstanceOf(ComplexValueObjectInterface::class, $result);
     $this->assertInstanceOf(CurrencyInterface::class, $result->getCurrency());
     $this->assertEquals(0, $result->getAmount());
 }