Ejemplo n.º 1
0
 public function testConvertWithPhpMagicMethod()
 {
     $exchange = M::mock('Hexcores\\Currency\\Contract\\ExchangeContract');
     $exchange->shouldReceive('make')->twice()->andReturn(1000);
     $formatter = M::mock('Hexcores\\Currency\\Contract\\FormatterContract');
     $formatter->shouldReceive('make')->twice()->andReturn('1,000.00Ks');
     $converter = new Converter($exchange, $formatter);
     $result1 = $converter->convert(1, 'USD', 'MMK');
     // Covert with original value
     $result2 = $converter->convertToMMK();
     $this->assertSame($result1, $result2);
 }
Ejemplo n.º 2
0
<?php

// Display Errors On
ini_set('display_errors', 'On');
$autoload = __DIR__ . '/../vendor/autoload.php';
if (!file_exists($autoload)) {
    exit("Need to run \"composer install\" for example");
}
require __DIR__ . '/../vendor/autoload.php';
use Hexcores\Currency\Type;
use Hexcores\Currency\Converter;
use Hexcores\Currency\Http\Client;
use Hexcores\Currency\Formatter\BaseFormatter;
use Hexcores\Currency\Exchange\CentralBankMyanmarExchange;
$ex = new CentralBankMyanmarExchange(new Client());
$f = new BaseFormatter();
$converter = new Converter($ex, $f);
echo "Current USD is 2500<br>";
echo "========================";
echo "<br>Convert USD to MMK: " . $converter->convert(2500, Type::USD, Type::MMK);
echo "<br> <code style='color:#0086b3;'>\$converter->convert(2500, Type::USD, Type::MMK)</code>";
echo "<br>------------------------------------------";
echo "<br>Convert USD to AUD: " . $converter->convert(2500, Type::USD, Type::AUD);
echo "<br> <code style='color:#0086b3;'>\$converter->convert(2500, Type::USD, Type::AUD)</code>";
echo "<br>------------------------------------------";
echo "<br>Convert USD to JPY with magic method: " . $converter->convertToJPY();
echo "<br> <code style='color:#0086b3;'>\$converter->convertToJPY()</code>";
echo "<br>------------------------------------------";
echo "<br>Convert USD to JPY 1200 with magic method: " . $converter->convertToJPY(1200);
echo "<br> <code style='color:#0086b3;'>\$converter->convertToJPY(1200)</code>";