Skip to content

Commit 49b63d6

Browse files
authored
[9.x] Improve Test For Replaces method in Collection (#43396)
add some case for index and associative array and item will be add when there is no match in collection
1 parent b13a1bc commit 49b63d6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/Support/SupportCollectionTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,6 +1348,12 @@ public function testReplaceArray($collection)
13481348
{
13491349
$c = new $collection(['a', 'b', 'c']);
13501350
$this->assertEquals(['a', 'd', 'e'], $c->replace([1 => 'd', 2 => 'e'])->all());
1351+
1352+
$c = new $collection(['a', 'b', 'c']);
1353+
$this->assertEquals(['a', 'd', 'e', 'f', 'g'], $c->replace([1 => 'd', 2 => 'e', 3 => 'f', 4 => 'g'])->all());
1354+
1355+
$c = new $collection(['name' => 'amir', 'family' => 'otwell']);
1356+
$this->assertEquals(['name' => 'taylor', 'family' => 'otwell', 'age' => 26], $c->replace(['name' => 'taylor', 'age' => 26])->all());
13511357
}
13521358

13531359
/**
@@ -1360,6 +1366,18 @@ public function testReplaceCollection($collection)
13601366
['a', 'd', 'e'],
13611367
$c->replace(new $collection([1 => 'd', 2 => 'e']))->all()
13621368
);
1369+
1370+
$c = new $collection(['a', 'b', 'c']);
1371+
$this->assertEquals(
1372+
['a', 'd', 'e', 'f', 'g'],
1373+
$c->replace(new $collection([1 => 'd', 2 => 'e', 3 => 'f', 4 => 'g']))->all()
1374+
);
1375+
1376+
$c = new $collection(['name' => 'amir', 'family' => 'otwell']);
1377+
$this->assertEquals(
1378+
['name' => 'taylor', 'family' => 'otwell', 'age' => 26],
1379+
$c->replace(new $collection(['name' => 'taylor', 'age' => 26]))->all()
1380+
);
13631381
}
13641382

13651383
/**
@@ -1378,6 +1396,9 @@ public function testReplaceRecursiveArray($collection)
13781396
{
13791397
$c = new $collection(['a', 'b', ['c', 'd']]);
13801398
$this->assertEquals(['z', 'b', ['c', 'e']], $c->replaceRecursive(['z', 2 => [1 => 'e']])->all());
1399+
1400+
$c = new $collection(['a', 'b', ['c', 'd']]);
1401+
$this->assertEquals(['z', 'b', ['c', 'e'], 'f'], $c->replaceRecursive(['z', 2 => [1 => 'e'], 'f'])->all());
13811402
}
13821403

13831404
/**

0 commit comments

Comments
 (0)