[Locale] add missing StubCollator methods, with tests

This commit is contained in:
Igor Wiedler 2011-03-02 17:13:24 +01:00
parent 18e16860ae
commit c22a43860b
2 changed files with 158 additions and 0 deletions

View File

@ -22,6 +22,16 @@ use Symfony\Component\Locale\Exception\MethodArgumentValueNotImplementedExceptio
*/
class StubCollator
{
/**
* Constants defined by the intl extension, not class constants in IntlDateFormatter
* TODO: remove if the Form component drop the call to the intl_is_failure() function
*
* @see StubIntlDateFormatter::getErrorCode()
* @see StubIntlDateFormatter::getErrorMessage()
*/
const U_ZERO_ERROR = 0;
const U_ZERO_ERROR_MESSAGE = 'U_ZERO_ERROR';
const ON = 17;
const OFF = 16;
const DEFAULT_VALUE = -1;
@ -77,6 +87,77 @@ class StubCollator
return asort($array);
}
public function compare($a, $b)
{
throw new MethodNotImplementedException(__METHOD__);
}
public function getAttribute($attr)
{
throw new MethodNotImplementedException(__METHOD__);
}
/**
* Returns collator's last error code. Always returns the U_ZERO_ERROR class constant value
*
* @return int The error code from last collator call
*/
public function getErrorCode()
{
return self::U_ZERO_ERROR;
}
/**
* Returns collator's last error message. Always returns the U_ZERO_ERROR_MESSAGE class constant value
*
* @return string The error message from last collator call
*/
public function getErrorMessage()
{
return self::U_ZERO_ERROR_MESSAGE;
}
/**
* Returns the collator's locale
*
* @param int $type The locale name type to return between valid or actual (StubLocale::VALID_LOCALE or StubLocale::ACTUAL_LOCALE, respectively)
* @return string The locale name used to create the collator
*/
public function getLocale($type = StubLocale::ACTUAL_LOCALE)
{
return 'en';
}
public function getSortKey($string)
{
throw new MethodNotImplementedException(__METHOD__);
}
public function getStrength()
{
throw new MethodNotImplementedException(__METHOD__);
}
public function setAttribute($attr, $val)
{
throw new MethodNotImplementedException(__METHOD__);
}
public function setStrength($strength)
{
throw new MethodNotImplementedException(__METHOD__);
}
public function sortWithSortKeys(&$arr)
{
throw new MethodNotImplementedException(__METHOD__);
}
public function sort(&$arr, $sort_flag = null)
{
throw new MethodNotImplementedException(__METHOD__);
}
static public function create($locale)
{
return new self($locale);

View File

@ -70,9 +70,86 @@ class StubCollatorTest extends LocaleTestCase
);
}
/**
* @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
*/
public function testCompare()
{
$collator = $this->createStubCollator();
$collator->compare('a', 'b');
}
/**
* @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
*/
public function testGetAttribute()
{
$collator = $this->createStubCollator();
$collator->getAttribute(StubCollator::NUMERIC_COLLATION);
}
public function testGetErrorCode()
{
$collator = $this->createStubCollator();
$this->assertEquals(StubCollator::U_ZERO_ERROR, $collator->getErrorCode());
}
public function testGetErrorMessage()
{
$collator = $this->createStubCollator();
$this->assertEquals(StubCollator::U_ZERO_ERROR_MESSAGE, $collator->getErrorMessage());
}
public function testGetLocale()
{
$collator = $this->createStubCollator();
$this->assertEquals('en', $collator->getLocale());
}
/**
* @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
*/
public function testGetSortKey()
{
$collator = $this->createStubCollator();
$collator->getSortKey('Hello');
}
/**
* @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
*/
public function testGetStrength()
{
$collator = $this->createStubCollator();
$collator->getStrength();
}
/**
* @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
*/
public function testSetAttribute()
{
$collator = $this->createStubCollator();
$collator->setAttribute(StubCollator::NUMERIC_COLLATION, StubCollator::ON);
}
/**
* @expectedException Symfony\Component\Locale\Exception\MethodNotImplementedException
*/
public function testSetStrength()
{
$collator = $this->createStubCollator();
$collator->setStrength(StubCollator::PRIMARY);
}
public function testStaticCreate()
{
$collator = StubCollator::create('en');
$this->assertInstanceOf('Symfony\Component\Locale\Stub\StubCollator', $collator);
}
protected function createStubCollator()
{
return new StubCollator('en');
}
}