20250203-1
This commit is contained in:
		| @@ -25,6 +25,8 @@ class ClassMapperTest extends TestCase | ||||
|  | ||||
|     private function PrepareForTest (): void | ||||
|     { | ||||
|         require_once __DIR__ . '/../data/A.php'; | ||||
|         require_once __DIR__ . '/../data/B.php'; | ||||
|         require_once __DIR__ . '/../../sources/classes/classMapper.php'; | ||||
|     } | ||||
| } | ||||
| } | ||||
							
								
								
									
										167
									
								
								tests/classes/ObjectArrayTest.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										167
									
								
								tests/classes/ObjectArrayTest.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,167 @@ | ||||
| <?php | ||||
|  | ||||
| namespace goodboyalex\php_components_pack\tests\classes; | ||||
|  | ||||
| use goodboyalex\php_components_pack\classes\ObjectArray; | ||||
| use goodboyalex\php_components_pack\tests\data\A; | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
| class ObjectArrayTest extends TestCase | ||||
| { | ||||
|     public function testSort () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $array = [ | ||||
|             new A("a", 3, true), | ||||
|             new A("c", 2, false), | ||||
|             new A("b", 1, true), | ||||
|         ]; | ||||
|  | ||||
|         $a_Array = new ObjectArray($array); | ||||
|         $b_Array = new ObjectArray($array); | ||||
|  | ||||
|         $a_Array->Sort('a'); | ||||
|         $b_Array->Sort('b'); | ||||
|  | ||||
|         $this->assertEquals('a', $a_Array[0]->a); | ||||
|         $this->assertEquals('b', $a_Array[1]->a); | ||||
|         $this->assertEquals('c', $a_Array[2]->a); | ||||
|  | ||||
|         $this->assertEquals('1', $b_Array[0]->b); | ||||
|         $this->assertEquals('2', $b_Array[1]->b); | ||||
|         $this->assertEquals('3', $b_Array[2]->b); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     private function PrepareForTest (): void | ||||
|     { | ||||
|         require_once __DIR__ . '/../data/A.php'; | ||||
|         require_once __DIR__ . '/../data/B.php'; | ||||
|         require_once __DIR__ . '/../../sources/interfaces/ISerializable.php'; | ||||
|         require_once __DIR__ . '/../../sources/traits/ObjectArray/ObjectArrayBasicTrait.php'; | ||||
|         require_once __DIR__ . '/../../sources/traits/ObjectArray/ObjectArrayConstantsTrait.php'; | ||||
|         require_once __DIR__ . '/../../sources/traits/ObjectArray/ObjectArrayLINQTrait.php'; | ||||
|         require_once __DIR__ . '/../../sources/traits/ObjectArray/ObjectArraySearchAndSortTrait.php'; | ||||
|         require_once __DIR__ . '/../../sources/classes/ObjectArray.php'; | ||||
|     } | ||||
|  | ||||
|     public function testSearch () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $array = [ | ||||
|             new A("a", 3, true), | ||||
|             new A("c", 2, false), | ||||
|             new A("b", 1, true), | ||||
|         ]; | ||||
|  | ||||
|         $a_Array = new ObjectArray($array); | ||||
|  | ||||
|         $sr = $a_Array->Search('a', 'c'); | ||||
|  | ||||
|         $this->assertEquals(2, $sr->b); | ||||
|     } | ||||
|  | ||||
|     public function testGetRows () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $array = [ | ||||
|             new A("a", 3, true), | ||||
|             new A("c", 2, false), | ||||
|             new A("b", 1, true), | ||||
|         ]; | ||||
|  | ||||
|         $a_Array = new ObjectArray($array); | ||||
|  | ||||
|         $sr = $a_Array->GetRows(fn (A $a): bool => $a->b < 3); | ||||
|  | ||||
|         $sr->Sort("b"); | ||||
|  | ||||
|         $this->assertCount(2, $sr); | ||||
|         $this->assertEquals('1', $sr[0]->b); | ||||
|         $this->assertEquals('2', $sr[1]->b); | ||||
|     } | ||||
|  | ||||
|     public function testGetValue () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $array = [ | ||||
|             new A("a", 3, true), | ||||
|             new A("c", 2, false), | ||||
|             new A("b", 1, true), | ||||
|         ]; | ||||
|  | ||||
|         $a_Array = new ObjectArray($array); | ||||
|         $sr = $a_Array->GetValue("b", fn (A $a): bool => $a->b < 2); | ||||
|  | ||||
|         $this->assertNotNull($sr); | ||||
|         $this->assertEquals(1, $sr); | ||||
|     } | ||||
|  | ||||
|     public function testCount () | ||||
|     { | ||||
|         $this->PrepareForTest(); | ||||
|  | ||||
|         $array = [ | ||||
|             new A("a", 3, true), | ||||
|             new A("c", 2, false), | ||||
|             new A("b", 1, true), | ||||
|         ]; | ||||
|  | ||||
|         $a_Array = new ObjectArray($array); | ||||
|  | ||||
|         $cnt = $a_Array->Count(); | ||||
|         $this->assertEquals(3, $cnt); | ||||
|  | ||||
|         $cnt = $a_Array->Count(fn (A $a): bool => $a->b < 3); | ||||
|         $this->assertEquals(2, $cnt); | ||||
|     } | ||||
|  | ||||
|     public function testDelete () | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testMaxBy () | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testGetColumn () | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testToArray () | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testMinBy () | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testIsExist () | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testSortCallback () | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testUpdate () | ||||
|     { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function testGetRow () | ||||
|     { | ||||
|  | ||||
|     } | ||||
| } | ||||
| @@ -7,4 +7,11 @@ class A | ||||
|     public string $a; | ||||
|     public int $b; | ||||
|     public bool $c; | ||||
|  | ||||
|     public function __construct (string $a = "", int $b = 0, bool $c = false) | ||||
|     { | ||||
|         $this->a = $a; | ||||
|         $this->b = $b; | ||||
|         $this->c = $c; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user