MaketRandevu/tests/Unit/Helper/ArrayHelperTest.php

54 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2023-03-23 09:49:11 +03:00
<?php
namespace Tests\Unit\Helper;
2023-03-23 09:49:11 +03:00
use Tests\TestCase;
2023-03-23 09:49:11 +03:00
2023-03-23 10:05:14 +03:00
class ArrayHelperTest extends TestCase {
public function testIsAssocReturnsTrueOnAssociativeArray(): void
2023-03-23 09:49:11 +03:00
{
$this->assertTrue(is_assoc(['test' => 'value']));
}
public function testIsAssocReturnsFalseOnIndexedArray(): void
2023-03-23 09:49:11 +03:00
{
$this->assertFalse(is_assoc(['one', 'two', 'three']));
}
public function testIsAssocReturnsTrueOnMixedArray(): void
2023-03-23 09:49:11 +03:00
{
$this->assertTrue(is_assoc(['one', 'two', 'three' => 'value']));
}
public function testArrayFindReturnsCorrectElement(): void
2023-03-23 09:49:11 +03:00
{
$arr = [
[
'id' => 1
],
[
'id' => 2
],
[
'id' => 3
],
];
$this->assertSame($arr[0], array_find($arr, fn($element) => $element['id'] === 1));
}
public function testArrayFieldsReturnsStrippedArray(): void
2023-03-23 09:49:11 +03:00
{
$arr = [
'name' => 'John',
'email' => 'john@example.org',
];
$stripped = array_fields($arr, ['name']);
$this->assertArrayHasKey('name', $stripped);
2023-03-23 09:49:11 +03:00
$this->assertArrayNotHasKey('email', $stripped);
}
}