aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvan Enderlin <ivan.enderlin@hoa-project.net>2014-12-24 08:44:59 +0100
committerIvan Enderlin <ivan.enderlin@hoa-project.net>2014-12-24 08:44:59 +0100
commita1ff879f19ad7e95b06d9a3437e4c9415a7f1011 (patch)
tree9b7e3c7a9bb08f6be2e30a04347633ae804711c6
parent63f712b244d872f95161831b32cc49dbb61a55df (diff)
downloadUstring-a1ff879f19ad7e95b06d9a3437e4c9415a7f1011.zip
Ustring-a1ff879f19ad7e95b06d9a3437e4c9415a7f1011.tar.gz
Ustring-a1ff879f19ad7e95b06d9a3437e4c9415a7f1011.tar.bz2
Review.2.14.12.24
Thanks @jubianchi!
-rw-r--r--String.php7
-rw-r--r--Test/Unit/String.php31
2 files changed, 13 insertions, 25 deletions
diff --git a/String.php b/String.php
index 294c2a2..6371a95 100644
--- a/String.php
+++ b/String.php
@@ -285,10 +285,10 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
*/
public function compare ( $string ) {
- if(false === class_exists('Collator', false))
+ if(null === $collator = static::getCollator())
return strcmp($this->_string, (string) $string);
- return static::getCollator()->compare($this->_string, $string);
+ return $collator->compare($this->_string, $string);
}
/**
@@ -299,6 +299,9 @@ class String implements \ArrayAccess, \Countable, \IteratorAggregate {
*/
public static function getCollator ( ) {
+ if(false === class_exists('Collator', false))
+ return null;
+
if(null === static::$_collator)
static::$_collator = new \Collator(setlocale(LC_COLLATE, null));
diff --git a/Test/Unit/String.php b/Test/Unit/String.php
index 1d81430..3a95b40 100644
--- a/Test/Unit/String.php
+++ b/Test/Unit/String.php
@@ -57,10 +57,7 @@ class String extends Test\Unit\Suite {
->given(
$this->function->function_exists = function ( $name ) {
- if('mb_substr' === $name)
- return false;
-
- return true;
+ return 'mb_substr' !== $name;
}
)
->exception(function ( ) {
@@ -172,10 +169,7 @@ class String extends Test\Unit\Suite {
->given(
$this->function->class_exists = function ( $name ) {
- if('Collator' === $name)
- return false;
-
- return true;
+ return 'Collator' !== $name;
},
$string = new LUT('b')
)
@@ -278,7 +272,7 @@ class String extends Test\Unit\Suite {
->integer($result)
->isEqualTo(0)
->array($matches)
- ->isEqualTo([]);
+ ->isEmpty();
}
public function case_match_with_offset ( ) {
@@ -860,10 +854,7 @@ class String extends Test\Unit\Suite {
->given(
$this->function->class_exists = function ( $name ) {
- if('Normalizer' === $name)
- return false;
-
- return true;
+ return 'Normalizer' !== $name;
},
$string = new LUT('Un été brûlant sur la côte')
)
@@ -880,10 +871,7 @@ class String extends Test\Unit\Suite {
->given(
$this->function->class_exists = function ( $name ) {
- if('Normalizer' === $name)
- return false;
-
- return true;
+ return 'Normalizer' !== $name;
},
$string = new LUT('Un été brûlant sur la côte')
)
@@ -920,13 +908,10 @@ class String extends Test\Unit\Suite {
public function case_toString ( ) {
$this
- ->given(
- $datum = $this->sample($this->realdom->regex('/\w{7,42}/')),
- $string = new LUT($datum)
- )
- ->when($result = (string) $string)
+ ->given($datum = $this->sample($this->realdom->regex('/\w{7,42}/')))
+ ->when($result = new LUT($datum))
->then
- ->string($result)
+ ->castToString($result)
->isEqualTo($datum);
}
}