20250724 1.2

[+] Добавлен новый тип GUID.

[*] В класс ObjectArray добавлена реализация интерфейсов IHashable, ISortable, IComparable.

[*] В класс Dictionary добавлена реализация интерфейсов IArrayable, IHashable, ISortable, IComparable.

[-] Класс GUIDExtension и все его методы помечены как устаревшие и скоро будут удалены.
This commit is contained in:
2025-07-24 13:02:04 +03:00
parent f8f14244d0
commit 24bf2a009f
9 changed files with 639 additions and 439 deletions

View File

@@ -3,6 +3,8 @@
namespace goodboyalex\php_components_pack\tests\types;
use goodboyalex\php_components_pack\types\GUID;
use InvalidArgumentException;
use OutOfRangeException;
use PHPUnit\Framework\TestCase;
class GUIDTest extends TestCase
@@ -28,26 +30,57 @@ class GUIDTest extends TestCase
public function testSegment ()
{
$this->PrepareForTest();
$guid = new GUID ('00000000-0000-0000-0000-000000000000');
$this->assertEquals('00000000', $guid->Segment(1));
$this->expectException(OutOfRangeException::class);
$guid->Segment(0);
}
public function testToString ()
{
$this->PrepareForTest();
$guid = new GUID ('5c0e5f0e-d033-44b1-a0b6-d0e2e369bdd1');
$this->assertEquals('5c0e5f0e-d033-44b1-a0b6-d0e2e369bdd1', $guid->ToString());
}
public function testIsInvalidOrEmpty ()
{
$this->PrepareForTest();
$this->assertFalse(GUID::isInvalidOrEmpty(new GUID ('5c0e5f0e-d033-44b1-a0b6-d0e2e369bdd1')));
$this->assertTrue(GUID::isInvalidOrEmpty(new GUID ('00000000-0000-0000-0000-000000000000')));
$this->assertTrue(GUID::isInvalidOrEmpty(null));
}
public function testParse ()
{
$this->PrepareForTest();
$guid = new GUID ('5c0e5f0e-d033-44b1-a0b6-d0e2e369bdd1');
$parsed = GUID::Parse('5c0e5f0e-d033-44b1-a0b6-d0e2e369bdd1', true);
$this->assertTrue($guid->IsEqualsTo($parsed));
$this->expectException(InvalidArgumentException::class);
GUID::Parse('НЕ GUID');
}
public function test__toString ()
{
$this->PrepareForTest();
$guid = new GUID ('5c0e5f0e-d033-44b1-a0b6-d0e2e369bdd1');
$str = "$guid";
$this->assertEquals('5c0e5f0e-d033-44b1-a0b6-d0e2e369bdd1', $str);
}
public function testToBytes ()
@@ -80,11 +113,17 @@ class GUIDTest extends TestCase
public function testGenerate ()
{
$this->PrepareForTest();
$guid = GUID::Generate();
self::assertFalse(GUID::isInvalidOrEmpty($guid));
}
public function testFromBytes ()
{
$this->PrepareForTest();
// Создаю массив
$array = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
@@ -93,11 +132,14 @@ class GUIDTest extends TestCase
// И вывожу его
self::assertEquals('00000000-0000-0000-0000-000000000000', $guid->ToString());
}
public function testValidate ()
{
$this->PrepareForTest();
$this->assertTrue(GUID::Validate(new GUID ('00000000-0000-0000-0000-000000000000')));
$this->assertTrue(GUID::Validate('5c0e5f0e-d033-44b1-a0b6-d0e2e369bdd1'));
$this->assertFalse(GUID::Validate('НЕ GUID'));
}
}