From 7a7b58d0f3ba41111372384ca1ce31b6d015e4af Mon Sep 17 00:00:00 2001 From: Florent Viogne Date: Fri, 3 Aug 2018 20:56:09 +0200 Subject: [PATCH] Updating the Pluralizer class to respect the grammar rule (#25063) [5.6] When count is -1, word must be in the singular --- src/Illuminate/Support/Pluralizer.php | 2 +- tests/Support/SupportPluralizerTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Pluralizer.php b/src/Illuminate/Support/Pluralizer.php index 6cc55ad7b885..75a2f6ac31d6 100755 --- a/src/Illuminate/Support/Pluralizer.php +++ b/src/Illuminate/Support/Pluralizer.php @@ -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; } diff --git a/tests/Support/SupportPluralizerTest.php b/tests/Support/SupportPluralizerTest.php index 78635d44a97f..71de8db32e30 100755 --- a/tests/Support/SupportPluralizerTest.php +++ b/tests/Support/SupportPluralizerTest.php @@ -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)); + } }