diff --git a/.idea/php-test-framework.xml b/.idea/php-test-framework.xml index 9e52408..8df1288 100644 --- a/.idea/php-test-framework.xml +++ b/.idea/php-test-framework.xml @@ -5,7 +5,7 @@ - + diff --git a/.idea/php.xml b/.idea/php.xml index 957357b..7321c98 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -46,7 +46,7 @@ - + diff --git a/.idea/phpunit.xml b/.idea/phpunit.xml index 4f8104c..395ca1f 100644 --- a/.idea/phpunit.xml +++ b/.idea/phpunit.xml @@ -3,7 +3,7 @@ diff --git a/sources/traits/ObjectArray/ObjectArrayBasicTrait.php b/sources/traits/ObjectArray/ObjectArrayBasicTrait.php index b427d23..3e3683f 100644 --- a/sources/traits/ObjectArray/ObjectArrayBasicTrait.php +++ b/sources/traits/ObjectArray/ObjectArrayBasicTrait.php @@ -27,7 +27,7 @@ trait ObjectArrayBasicTrait */ public function offsetGet (mixed $offset): mixed { - return $this->container[$offset] ?? null; + return $this->Container[$offset] ?? null; } /** diff --git a/sources/traits/ObjectArray/ObjectArraySearchAndSortTrait.php b/sources/traits/ObjectArray/ObjectArraySearchAndSortTrait.php index 861c99d..ac87ab6 100644 --- a/sources/traits/ObjectArray/ObjectArraySearchAndSortTrait.php +++ b/sources/traits/ObjectArray/ObjectArraySearchAndSortTrait.php @@ -66,9 +66,9 @@ trait ObjectArraySearchAndSortTrait * @param string $objectProperty Имя свойства объекта * @param bool $descending Направление сортировки * - * @return array Отсортированный массив объектов + * @return void */ - public function Sort (string $objectProperty, bool $descending = false): array + public function Sort (string $objectProperty, bool $descending = false): void { // Создаём результирующий массив $result = array_merge($this->Container, []); @@ -80,8 +80,8 @@ trait ObjectArraySearchAndSortTrait ? $a->$objectProperty <=> $b->$objectProperty : $b->$objectProperty <=> $a->$objectProperty); - // Возвращаем результат - return $result; + // Присваиваем результат + $this->Container = $result; } /** diff --git a/tests/classes/ClassMapperTest.php b/tests/classes/ClassMapperTest.php index fe283d7..1efbada 100644 --- a/tests/classes/ClassMapperTest.php +++ b/tests/classes/ClassMapperTest.php @@ -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'; } -} +} \ No newline at end of file diff --git a/tests/classes/ObjectArrayTest.php b/tests/classes/ObjectArrayTest.php new file mode 100644 index 0000000..8d8ac0f --- /dev/null +++ b/tests/classes/ObjectArrayTest.php @@ -0,0 +1,167 @@ +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 () + { + + } +} \ No newline at end of file diff --git a/tests/data/A.php b/tests/data/A.php index 384d64a..097740f 100644 --- a/tests/data/A.php +++ b/tests/data/A.php @@ -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; + } } \ No newline at end of file