Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Commit

Permalink
Review.
Browse files Browse the repository at this point in the history
Thanks @jubianchi!
  • Loading branch information
Hywan committed Dec 24, 2014
1 parent 63f712b commit a1ff879
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 25 deletions.
7 changes: 5 additions & 2 deletions String.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,10 @@ public function pad ( $length, $piece, $side = self::END ) {
*/
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);
}

/**
Expand All @@ -299,6 +299,9 @@ public function compare ( $string ) {
*/
public static function getCollator ( ) {

if(false === class_exists('Collator', false))
return null;

if(null === static::$_collator)
static::$_collator = new \Collator(setlocale(LC_COLLATE, null));

Expand Down
31 changes: 8 additions & 23 deletions Test/Unit/String.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,7 @@ public function case_no_mbstring ( ) {
->given(
$this->function->function_exists = function ( $name ) {

if('mb_substr' === $name)
return false;

return true;
return 'mb_substr' !== $name;
}
)
->exception(function ( ) {
Expand Down Expand Up @@ -172,10 +169,7 @@ public function case_compare_no_collator ( ) {
->given(
$this->function->class_exists = function ( $name ) {

if('Collator' === $name)
return false;

return true;
return 'Collator' !== $name;
},
$string = new LUT('b')
)
Expand Down Expand Up @@ -278,7 +272,7 @@ public function case_match_offset ( ) {
->integer($result)
->isEqualTo(0)
->array($matches)
->isEqualTo([]);
->isEmpty();
}

public function case_match_with_offset ( ) {
Expand Down Expand Up @@ -860,10 +854,7 @@ public function case_to_ascii_no_normalizer ( ) {
->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')
)
Expand All @@ -880,10 +871,7 @@ public function case_to_ascii_no_normalizer_try ( ) {
->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')
)
Expand Down Expand Up @@ -920,13 +908,10 @@ public function case_copy ( ) {
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);
}
}

0 comments on commit a1ff879

Please sign in to comment.