public function testGetters() { $c1 = new Currency('BRL'); $this->assertEquals('BRL', $c1->getCurrency()); $this->assertEquals('Brazilian Real', $c1->getName()); $this->assertEquals(986, $c1->getCode()); $this->assertEquals(2, $c1->getPrecision()); $this->assertEquals(100, $c1->getSubunit()); $this->assertEquals('R$', $c1->getSymbol()); $this->assertEquals(true, $c1->isSymbolFirst()); $this->assertEquals(',', $c1->getDecimalMark()); $this->assertEquals('.', $c1->getThousandsSeparator()); $this->assertEquals('R$ ', $c1->getPrefix()); $this->assertEquals('', $c1->getSuffix()); $this->assertNotEmpty($c1->toArray()['BRL']); $this->assertJson($c1->toJson()); $this->assertNotEmpty($c1->jsonSerialize()['BRL']); $c2 = new Currency('CDF'); $this->assertEquals('CDF', $c2->getCurrency()); $this->assertEquals('Congolese Franc', $c2->getName()); $this->assertEquals(976, $c2->getCode()); $this->assertEquals(2, $c2->getPrecision()); $this->assertEquals(100, $c2->getSubunit()); $this->assertEquals('Fr', $c2->getSymbol()); $this->assertEquals(false, $c2->isSymbolFirst()); $this->assertEquals('.', $c2->getDecimalMark()); $this->assertEquals(',', $c2->getThousandsSeparator()); $this->assertEquals('', $c2->getPrefix()); $this->assertEquals('Fr', $c2->getSuffix()); $this->assertNotEmpty($c2->toArray()['CDF']); $this->assertJson($c2->toJson()); $this->assertNotEmpty($c2->jsonSerialize()['CDF']); }
/** * formatLocale. * * @param string $locale * @param Closure $callback * * @throws \BadFunctionCallException * * @return string */ public function formatLocale($locale = null, Closure $callback = null) { if (!class_exists('\\NumberFormatter')) { throw new BadFunctionCallException('Class NumberFormatter not exists. Require ext-intl extension.'); } $formatter = new \NumberFormatter($locale ?: static::getLocale(), \NumberFormatter::CURRENCY); if (is_callable($callback)) { $callback($formatter); } return $formatter->formatCurrency($this->getValue(), $this->currency->getCurrency()); }
/** * equals. * * @param \ClickNow\Money\Currency $currency * * @return bool */ public function equals(self $currency) { return $this->getCurrency() === $currency->getCurrency(); }