Преглед изворни кода

[ZF-9522] Zend_Currency:

- changed exchange rate to be more intuitive

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@21646 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas пре 16 година
родитељ
комит
66a90f2226

+ 4 - 4
documentation/manual/en/module_specs/Zend_Currency-Exchange.xml

@@ -70,7 +70,7 @@ class SimpleExchange implements Zend_Currency_CurrencyInterface
 $currency = new Zend_Currency(
     array(
         'value'    => 1000,
-        'currency' => 'USD',
+        'currency' => 'EUR',
     )
 );
 
@@ -82,7 +82,7 @@ $currency->setService($service);
 $currency2 = new Zend_Currency(
     array(
         'value'    => 1000,
-        'currency' => 'EUR',
+        'currency' => 'USD',
     )
 );
 
@@ -90,8 +90,8 @@ print $currency->add($currency2);
 ]]></programlisting>
 
     <para>
-        The above example will return '$ 3.000' because the 1.000 <acronym>EUR</acronym> will be
-        converted by a rate of 2 to 2.000 <acronym>USD</acronym>.
+        The above example will return '$ 3.000' because the 1.000 <acronym>USD</acronym> will be
+        converted by a rate of 2 to 2.000 <acronym>EUR</acronym>.
     </para>
 
     <note>

+ 1 - 1
library/Zend/Currency.php

@@ -760,7 +760,7 @@ class Zend_Currency
                 throw new Zend_Currency_Exception('No exchange service applied');
             }
 
-            $rate = $service->getRate($this->getShortName(), $currency);
+            $rate = $service->getRate($currency, $this->getShortName());
         }
 
         $value *= $rate;

+ 7 - 1
tests/Zend/Currency/ExchangeTest.php

@@ -44,6 +44,12 @@ class ExchangeTest implements Zend_Currency_CurrencyInterface
      */
     public function getRate($from, $to)
     {
-        return 2;
+        if ($from == "RUB") {
+            return 2;
+        } else if ($from == "USD") {
+            return 0.5;
+        } else {
+            return 1;
+        }
     }
 }

+ 1 - 1
tests/Zend/CurrencyTest.php

@@ -813,7 +813,7 @@ class Zend_CurrencyTest extends PHPUnit_Framework_TestCase
         $this->assertTrue($currency->getService() instanceof Zend_Currency_CurrencyInterface);
 
         $currency->setValue(100, 'USD');
-        $this->assertEquals(200, $currency->getValue());
+        $this->assertEquals(50, $currency->getValue());
         $this->assertEquals('RUB', $currency->getShortName());
     }
 }