Skip to content

Commit 0774c79

Browse files
committed
[Locale] added some more stubs for the number formatter
1 parent 2e87d1d commit 0774c79

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

src/Symfony/Component/Locale/Stub/StubNumberFormatter.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ class StubNumberFormatter
221221
'negative' => -9223372036854775808
222222
);
223223

224+
private static $enSymbols = array(
225+
self::DECIMAL => array('.', ',', ';', '%', '0', '#', '-', '+', '¤', '¤¤', '.', 'E', '', '*', '', 'NaN', '@', ','),
226+
self::CURRENCY => array('.', ',', ';', '%', '0', '#', '-', '+', '¤', '¤¤', '.', 'E', '', '*', '', 'NaN', '@', ','),
227+
);
228+
229+
private static $enTextAttributes = array(
230+
self::DECIMAL => array('', '', '-', '', '*', '', ''),
231+
self::CURRENCY => array('¤', '', '', ')', '*', ''),
232+
);
233+
224234
/**
225235
* Constructor
226236
*
@@ -435,12 +445,10 @@ public function getPattern()
435445
* @return Boolean|string The symbol value or false on error
436446
*
437447
* @see http://www.php.net/manual/en/numberformatter.getsymbol.php
438-
*
439-
* @throws MethodNotImplementedException
440448
*/
441449
public function getSymbol($attr)
442450
{
443-
throw new MethodNotImplementedException(__METHOD__);
451+
return array_key_exists($this->style, self::$enSymbols) && array_key_exists($attr, self::$enSymbols[$this->style]) ? self::$enSymbols[$this->style][$attr] : false;
444452
}
445453

446454
/**
@@ -451,12 +459,10 @@ public function getSymbol($attr)
451459
* @return Boolean|string The attribute value or false on error
452460
*
453461
* @see http://www.php.net/manual/en/numberformatter.gettextattribute.php
454-
*
455-
* @throws MethodNotImplementedException
456462
*/
457463
public function getTextAttribute($attr)
458464
{
459-
throw new MethodNotImplementedException(__METHOD__);
465+
return array_key_exists($this->style, self::$enTextAttributes) && array_key_exists($attr, self::$enTextAttributes[$this->style]) ? self::$enTextAttributes[$this->style][$attr] : false;
460466
}
461467

462468
/**

src/Symfony/Component/Locale/Tests/Stub/StubNumberFormatterTest.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -707,22 +707,36 @@ public function testGetPattern()
707707
$formatter->getPattern();
708708
}
709709

710-
/**
711-
* @expectedException \Symfony\Component\Locale\Exception\MethodNotImplementedException
712-
*/
713710
public function testGetSymbol()
714711
{
715-
$formatter = $this->getStubFormatterWithDecimalStyle();
716-
$formatter->getSymbol(null);
712+
$this->skipIfIntlExtensionIsNotLoaded();
713+
714+
$intlDecimalFormatter = new \NumberFormatter('en', \NumberFormatter::DECIMAL);
715+
$intlCurrencyFormatter = new \NumberFormatter('en', \NumberFormatter::CURRENCY);
716+
717+
$stubDecimalFormatter = $this->getStubFormatterWithDecimalStyle();
718+
$stubCurrencyFormatter = $this->getStubFormatterWithCurrencyStyle();
719+
720+
for ($i = 0; $i <= 17; $i++) {
721+
$this->assertSame($stubDecimalFormatter->getSymbol($i), $intlDecimalFormatter->getSymbol($i), $i);
722+
$this->assertSame($stubCurrencyFormatter->getSymbol($i), $intlCurrencyFormatter->getSymbol($i), $i);
723+
}
717724
}
718725

719-
/**
720-
* @expectedException \Symfony\Component\Locale\Exception\MethodNotImplementedException
721-
*/
722726
public function testGetTextAttribute()
723727
{
724-
$formatter = $this->getStubFormatterWithDecimalStyle();
725-
$formatter->getTextAttribute(null);
728+
$this->skipIfIntlExtensionIsNotLoaded();
729+
730+
$intlDecimalFormatter = new \NumberFormatter('en', \NumberFormatter::DECIMAL);
731+
$intlCurrencyFormatter = new \NumberFormatter('en', \NumberFormatter::CURRENCY);
732+
733+
$stubDecimalFormatter = $this->getStubFormatterWithDecimalStyle();
734+
$stubCurrencyFormatter = $this->getStubFormatterWithCurrencyStyle();
735+
736+
for ($i = 0; $i <= 5; $i++) {
737+
$this->assertSame($stubDecimalFormatter->getTextAttribute($i), $intlDecimalFormatter->getTextAttribute($i), $i);
738+
$this->assertSame($stubCurrencyFormatter->getTextAttribute($i), $intlCurrencyFormatter->getTextAttribute($i), 'fooo '.$i);
739+
}
726740
}
727741

728742
/**

0 commit comments

Comments
 (0)