diff --git a/tests/Support/SupportArrTest.php b/tests/Support/SupportArrTest.php index 2f9b2c85d60..1971fd8f283 100644 --- a/tests/Support/SupportArrTest.php +++ b/tests/Support/SupportArrTest.php @@ -12,7 +12,7 @@ class SupportArrTest extends TestCase { - public function testAccessible() + public function testAccessible(): void { $this->assertTrue(Arr::accessible([])); $this->assertTrue(Arr::accessible([1, 2])); @@ -23,6 +23,11 @@ public function testAccessible() $this->assertFalse(Arr::accessible('abc')); $this->assertFalse(Arr::accessible(new stdClass)); $this->assertFalse(Arr::accessible((object) ['a' => 1, 'b' => 2])); + $this->assertFalse(Arr::accessible(123)); + $this->assertFalse(Arr::accessible(12.34)); + $this->assertFalse(Arr::accessible(true)); + $this->assertFalse(Arr::accessible(new \DateTime)); + $this->assertFalse(Arr::accessible(static fn () => null)); } public function testAdd() @@ -1387,17 +1392,24 @@ public function testPrependKeysWith() ], Arr::prependKeysWith($array, 'test.')); } - public function testTake() + public function testTake(): void { $array = [1, 2, 3, 4, 5, 6]; - $this->assertEquals([ - 1, 2, 3, - ], Arr::take($array, 3)); + // Test with a positive limit, should return the first 'limit' elements. + $this->assertEquals([1, 2, 3], Arr::take($array, 3)); - $this->assertEquals([ - 4, 5, 6, - ], Arr::take($array, -3)); + // Test with a negative limit, should return the last 'abs(limit)' elements. + $this->assertEquals([4, 5, 6], Arr::take($array, -3)); + + // Test with zero limit, should return an empty array. + $this->assertEquals([], Arr::take($array, 0)); + + // Test with a limit greater than the array size, should return the entire array. + $this->assertEquals([1, 2, 3, 4, 5, 6], Arr::take($array, 10)); + + // Test with a negative limit greater than the array size, should return the entire array. + $this->assertEquals([1, 2, 3, 4, 5, 6], Arr::take($array, -10)); } public function testSelect()