Commit d86da1d3 by pana1990 Committed by Qiang Xue

add tests for sentence method

parent a87c55ff
......@@ -396,4 +396,30 @@ class ArrayHelperTest extends TestCase
$this->assertTrue(ArrayHelper::isIndexed([2 => 'a', 3 => 'b']));
$this->assertFalse(ArrayHelper::isIndexed([2 => 'a', 3 => 'b'], true));
}
public function testSentence()
{
$array = [];
$this->assertEquals('', ArrayHelper::sentence($array));
$array = ['Spain'];
$this->assertEquals('Spain', ArrayHelper::sentence($array));
$array = ['Spain', 'France'];
$this->assertEquals('Spain and France', ArrayHelper::sentence($array));
$array = ['Spain', 'France'];
$this->assertEquals('Spain or France', ArrayHelper::sentence($array, [
'twoWordsConnector' => ' or ',
]));
$array = ['Spain', 'France', 'Italy'];
$this->assertEquals('Spain, France, and Italy', ArrayHelper::sentence($array));
$array = ['Spain', 'France', 'Italy'];
$this->assertEquals('Spain - France - Italy', ArrayHelper::sentence($array, [
'wordsConnector' => ' - ',
'lastWordConnector' => ' - '
]));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment