Skip to content

Commit f8b902c

Browse files
authored
[9.x] Improve test For Split method In Collection (#43408)
1 parent a52f623 commit f8b902c

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/Support/SupportCollectionTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4606,6 +4606,11 @@ public function testCollectionFromBackedEnum($collection)
46064606
public function testSplitCollectionWithADivisableCount($collection)
46074607
{
46084608
$data = new $collection(['a', 'b', 'c', 'd']);
4609+
$split = $data->split(2);
4610+
4611+
$this->assertSame(['a', 'b'], $split->get(0)->all());
4612+
$this->assertSame(['c', 'd'], $split->get(1)->all());
4613+
$this->assertInstanceOf($collection, $split);
46094614

46104615
$this->assertEquals(
46114616
[['a', 'b'], ['c', 'd']],
@@ -4615,6 +4620,10 @@ public function testSplitCollectionWithADivisableCount($collection)
46154620
);
46164621

46174622
$data = new $collection([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
4623+
$split = $data->split(2);
4624+
4625+
$this->assertSame([1, 2, 3, 4, 5], $split->get(0)->all());
4626+
$this->assertSame([6, 7, 8, 9, 10], $split->get(1)->all());
46184627

46194628
$this->assertEquals(
46204629
[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]],
@@ -4630,6 +4639,10 @@ public function testSplitCollectionWithADivisableCount($collection)
46304639
public function testSplitCollectionWithAnUndivisableCount($collection)
46314640
{
46324641
$data = new $collection(['a', 'b', 'c']);
4642+
$split = $data->split(2);
4643+
4644+
$this->assertSame(['a', 'b'], $split->get(0)->all());
4645+
$this->assertSame(['c'], $split->get(1)->all());
46334646

46344647
$this->assertEquals(
46354648
[['a', 'b'], ['c']],
@@ -4645,6 +4658,10 @@ public function testSplitCollectionWithAnUndivisableCount($collection)
46454658
public function testSplitCollectionWithCountLessThenDivisor($collection)
46464659
{
46474660
$data = new $collection(['a']);
4661+
$split = $data->split(2);
4662+
4663+
$this->assertSame(['a'], $split->get(0)->all());
4664+
$this->assertNull($split->get(1));
46484665

46494666
$this->assertEquals(
46504667
[['a']],
@@ -4660,6 +4677,11 @@ public function testSplitCollectionWithCountLessThenDivisor($collection)
46604677
public function testSplitCollectionIntoThreeWithCountOfFour($collection)
46614678
{
46624679
$data = new $collection(['a', 'b', 'c', 'd']);
4680+
$split = $data->split(3);
4681+
4682+
$this->assertSame(['a', 'b'], $split->get(0)->all());
4683+
$this->assertSame(['c'], $split->get(1)->all());
4684+
$this->assertSame(['d'], $split->get(2)->all());
46634685

46644686
$this->assertEquals(
46654687
[['a', 'b'], ['c'], ['d']],
@@ -4675,6 +4697,11 @@ public function testSplitCollectionIntoThreeWithCountOfFour($collection)
46754697
public function testSplitCollectionIntoThreeWithCountOfFive($collection)
46764698
{
46774699
$data = new $collection(['a', 'b', 'c', 'd', 'e']);
4700+
$split = $data->split(3);
4701+
4702+
$this->assertSame(['a', 'b'], $split->get(0)->all());
4703+
$this->assertSame(['c', 'd'], $split->get(1)->all());
4704+
$this->assertSame(['e'], $split->get(2)->all());
46784705

46794706
$this->assertEquals(
46804707
[['a', 'b'], ['c', 'd'], ['e']],
@@ -4690,6 +4717,14 @@ public function testSplitCollectionIntoThreeWithCountOfFive($collection)
46904717
public function testSplitCollectionIntoSixWithCountOfTen($collection)
46914718
{
46924719
$data = new $collection(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']);
4720+
$split = $data->split(6);
4721+
4722+
$this->assertSame(['a', 'b'], $split->get(0)->all());
4723+
$this->assertSame(['c', 'd'], $split->get(1)->all());
4724+
$this->assertSame(['e', 'f'], $split->get(2)->all());
4725+
$this->assertSame(['g', 'h'], $split->get(3)->all());
4726+
$this->assertSame(['i'], $split->get(4)->all());
4727+
$this->assertSame(['j'], $split->get(5)->all());
46934728

46944729
$this->assertEquals(
46954730
[['a', 'b'], ['c', 'd'], ['e', 'f'], ['g', 'h'], ['i'], ['j']],
@@ -4705,6 +4740,10 @@ public function testSplitCollectionIntoSixWithCountOfTen($collection)
47054740
public function testSplitEmptyCollection($collection)
47064741
{
47074742
$data = new $collection;
4743+
$split = $data->split(2);
4744+
4745+
$this->assertNull($split->get(0));
4746+
$this->assertNull($split->get(1));
47084747

47094748
$this->assertEquals(
47104749
[],

0 commit comments

Comments
 (0)