This commit is contained in:
27
tests/TestCase.php
Normal file
27
tests/TestCase.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use CI_Controller;
|
||||
use EA_Controller;
|
||||
use PHPUnit\Framework\TestCase as PHPUnitTestCase;
|
||||
|
||||
/**
|
||||
* Parent test case sharing common test functionality.
|
||||
*/
|
||||
class TestCase extends PHPUnitTestCase {
|
||||
/**
|
||||
* @var EA_Controller|CI_Controller
|
||||
*/
|
||||
private static EA_Controller|CI_Controller $CI;
|
||||
|
||||
/**
|
||||
* Load the framework instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
self::$CI =& get_instance();
|
||||
}
|
||||
}
|
53
tests/Unit/Helper/ArrayHelperTest.php
Normal file
53
tests/Unit/Helper/ArrayHelperTest.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helper;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class ArrayHelperTest extends TestCase {
|
||||
public function testIsAssocReturnsTrueOnAssociativeArray(): void
|
||||
{
|
||||
$this->assertTrue(is_assoc(['test' => 'value']));
|
||||
}
|
||||
|
||||
public function testIsAssocReturnsFalseOnIndexedArray(): void
|
||||
{
|
||||
$this->assertFalse(is_assoc(['one', 'two', 'three']));
|
||||
}
|
||||
|
||||
public function testIsAssocReturnsTrueOnMixedArray(): void
|
||||
{
|
||||
$this->assertTrue(is_assoc(['one', 'two', 'three' => 'value']));
|
||||
}
|
||||
|
||||
public function testArrayFindReturnsCorrectElement(): void
|
||||
{
|
||||
$arr = [
|
||||
[
|
||||
'id' => 1
|
||||
],
|
||||
[
|
||||
'id' => 2
|
||||
],
|
||||
[
|
||||
'id' => 3
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertSame($arr[0], array_find($arr, fn($element) => $element['id'] === 1));
|
||||
}
|
||||
|
||||
public function testArrayFieldsReturnsStrippedArray(): void
|
||||
{
|
||||
$arr = [
|
||||
'name' => 'John',
|
||||
'email' => 'john@example.org',
|
||||
];
|
||||
|
||||
$stripped = array_fields($arr, ['name']);
|
||||
|
||||
$this->assertArrayHasKey('name', $stripped);
|
||||
|
||||
$this->assertArrayNotHasKey('email', $stripped);
|
||||
}
|
||||
}
|
17
tests/Unit/Helper/ValidationHelperTest.php
Normal file
17
tests/Unit/Helper/ValidationHelperTest.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Helper;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class ValidationHelperTest extends TestCase {
|
||||
public function testValidateDateTimeReturnsTrueOnValidValue()
|
||||
{
|
||||
$this->assertTrue(validate_datetime(date('Y-m-d H:i:s')));
|
||||
}
|
||||
|
||||
public function testValidateDateTimeReturnsFalseOnInvalidValue()
|
||||
{
|
||||
$this->assertFalse(validate_datetime('invalid'));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user