Skip to content

Commit

Permalink
[11.x] Add tests for accessible and take method (#51724)
Browse files Browse the repository at this point in the history
* add tests for accessible and take method

* fixes code style

* fixes code style
  • Loading branch information
saMahmoudzadeh authored Jun 6, 2024
1 parent 948d1aa commit ae0bc31
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions tests/Support/SupportArrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand All @@ -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()
Expand Down Expand Up @@ -1442,17 +1447,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()
Expand Down

0 comments on commit ae0bc31

Please sign in to comment.