2022-09-13 13:13:11 +00:00
|
|
|
<?php
|
|
|
|
// DbToolsTest.php
|
|
|
|
// Created: 2021-04-28
|
2024-10-16 01:18:10 +00:00
|
|
|
// Updated: 2024-10-16
|
2022-09-13 13:13:11 +00:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
use PHPUnit\Framework\TestCase;
|
2024-10-18 20:47:29 +00:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
2024-10-04 22:35:57 +00:00
|
|
|
use Index\Db\{DbTools,DbType};
|
2022-09-13 13:13:11 +00:00
|
|
|
|
2024-07-31 18:12:46 +00:00
|
|
|
#[CoversClass(DbTools::class)]
|
|
|
|
#[CoversClass(DbType::class)]
|
2022-09-13 13:13:11 +00:00
|
|
|
final class DbToolsTest extends TestCase {
|
|
|
|
public function testDetectType(): void {
|
|
|
|
$this->assertEquals(DbType::NULL, DbTools::detectType(null));
|
|
|
|
$this->assertEquals(DbType::INTEGER, DbTools::detectType(12345));
|
|
|
|
$this->assertEquals(DbType::FLOAT, DbTools::detectType(123.45));
|
|
|
|
$this->assertEquals(DbType::STRING, DbTools::detectType('This is a string.'));
|
2024-10-02 16:17:48 +00:00
|
|
|
|
|
|
|
$blob = fopen('php://memory', 'r+b');
|
|
|
|
if($blob === false)
|
|
|
|
throw new RuntimeException('failed to fopen a memory stream');
|
|
|
|
|
|
|
|
fwrite($blob, 'This is a string inside a memory stream.');
|
|
|
|
fseek($blob, 0);
|
|
|
|
|
|
|
|
$this->assertEquals(DbType::BLOB, DbTools::detectType($blob));
|
2022-09-13 13:13:11 +00:00
|
|
|
}
|
|
|
|
}
|