20250515
* [ObjectArrayBasicTrait] заменён на [ArrayBasicTrait]. * [ArrayBasicTrait] изменён метод __isset. Теперь он обрабатывается корректно. * [ArrayBasicTrait] методы Serialize и UnSerialize теперь используют json_encode / json_decode * [+Dictionary] Класс, описывающий словарь типа строка (ключ) -> значение любого типа (значение).
This commit is contained in:
		
							
								
								
									
										102
									
								
								tests/classes/DictionaryTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								tests/classes/DictionaryTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,102 @@ | ||||
| <?php | ||||
|  | ||||
| namespace goodboyalex\php_components_pack\tests\classes; | ||||
|  | ||||
| use goodboyalex\php_components_pack\classes\Dictionary; | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| class DictionaryTest extends TestCase | ||||
| { | ||||
|     public function testRemove () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $dict = new Dictionary(); | ||||
|         $dict->Add('1', 1); | ||||
|         $dict->Add('2', '2'); | ||||
|         $dict->Add('3', true); | ||||
|  | ||||
|         $dict->Remove('2'); | ||||
|  | ||||
|         $this->assertEquals(1, $dict->Get('1')); | ||||
|         $this->assertTrue($dict->Get('3')); | ||||
|         $this->assertEquals(2, $dict->count()); | ||||
|         $this->assertFalse($dict->Has('2')); | ||||
|     } | ||||
|  | ||||
|     private function PrepareForTest (): void | ||||
|     { | ||||
|         require_once __DIR__ . '/../../sources/interfaces/ISerializable.php'; | ||||
|         require_once __DIR__ . '/../../sources/traits/ArrayBasicTrait.php'; | ||||
|         require_once __DIR__ . '/../../sources/classes/Dictionary.php'; | ||||
|     } | ||||
|  | ||||
|     public function testSerialize () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $dict = new Dictionary(); | ||||
|         $dict->Add('1', 1); | ||||
|         $dict->Add('2', '2'); | ||||
|         $dict->Add('3', true); | ||||
|  | ||||
|         $this->assertEquals("{\"1\":1,\"2\":\"2\",\"3\":true}", $dict->Serialize()); | ||||
|     } | ||||
|  | ||||
|     public function testGet () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $dict = new Dictionary(); | ||||
|         $dict->Add('1', 1); | ||||
|         $dict->Add('2', '2'); | ||||
|         $dict->Add('3', true); | ||||
|  | ||||
|         $this->assertEquals(1, $dict->Get('1')); | ||||
|         $this->assertEquals('2', $dict->Get('2')); | ||||
|         $this->assertTrue($dict->Get('3')); | ||||
|         $this->assertEquals(3, $dict->count()); | ||||
|     } | ||||
|  | ||||
|     public function testClear () | ||||
|     { | ||||
|  | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $dict = new Dictionary(); | ||||
|         $dict->Add('1', 1); | ||||
|         $dict->Add('2', '2'); | ||||
|         $dict->Add('3', true); | ||||
|         $dict->Clear(); | ||||
|  | ||||
|         $this->assertEquals(0, $dict->count()); | ||||
|     } | ||||
|  | ||||
|     public function testAdd () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $dict = new Dictionary(); | ||||
|         $dict->Add('1', 1); | ||||
|         $dict->Add('2', '2'); | ||||
|         $dict->Add('3', true); | ||||
|  | ||||
|         $this->assertEquals(1, $dict->Get('1')); | ||||
|         $this->assertEquals('2', $dict->Get('2')); | ||||
|         $this->assertTrue($dict->Get('3')); | ||||
|         $this->assertEquals(3, $dict->count()); | ||||
|     } | ||||
|  | ||||
|     public function testHas () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $dict = new Dictionary(); | ||||
|         $dict->Add('1', 1); | ||||
|         $dict->Add('2', '2'); | ||||
|         $dict->Add('3', true); | ||||
|  | ||||
|         $this->assertTrue($dict->Has('3')); | ||||
|         $this->assertFalse($dict->Has('4')); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user