Skip to content

Commit

Permalink
Updating the Pluralizer class to respect the grammar rule (#25063)
Browse files Browse the repository at this point in the history
[5.6] When count is -1, word must be in the singular
  • Loading branch information
florentVgn authored and taylorotwell committed Aug 3, 2018
1 parent f294134 commit 7a7b58d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Pluralizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Pluralizer
*/
public static function plural($value, $count = 2)
{
if ((int) $count === 1 || static::uncountable($value)) {
if ((int) abs($count) === 1 || static::uncountable($value)) {
return $value;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/Support/SupportPluralizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ public function testIfEndOfWordPlural()
$this->assertEquals('IndexFields', Str::plural('IndexField'));
$this->assertEquals('VertexFields', Str::plural('VertexField'));
}

public function testPluralWithNegativeCount() {
$this->assertEquals('test', Str::plural('test', 1));
$this->assertEquals('tests', Str::plural('test', 2));
$this->assertEquals('test', Str::plural('test', -1));
$this->assertEquals('tests', Str::plural('test', -2));
}
}

0 comments on commit 7a7b58d

Please sign in to comment.