20250203-1

This commit is contained in:
Александр Бабаев 2025-02-03 23:39:40 +03:00
parent dd62ad0ca4
commit 4bcb4c60dd
8 changed files with 185 additions and 9 deletions

View File

@ -5,7 +5,7 @@
<tool tool_name="PHPUnit">
<cache>
<versions>
<info id=окальныйD:\Program Files\PHPStorm dependens\PHPUnit\phpunit.phar" version="11.5.6" />
<info id=окальныйD:\Internet\php\tools\phpunit\phpunit_2.phar" version="11.5.6" />
</versions>
</cache>
</tool>

2
.idea/php.xml generated
View File

@ -46,7 +46,7 @@
</component>
<component name="PhpUnit">
<phpunit_settings>
<PhpUnitSettings load_method="PHPUNIT_PHAR" custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" phpunit_phar_path="$PROJECT_DIR$/../../Program Files/PHPStorm dependens/PHPUnit/phpunit.phar" />
<PhpUnitSettings load_method="PHPUNIT_PHAR" custom_loader_path="$PROJECT_DIR$/vendor/autoload.php" phpunit_phar_path="D:/Internet/php/tools/phpunit/phpunit_2.phar" />
</phpunit_settings>
</component>
<component name="PsalmOptionsConfiguration">

2
.idea/phpunit.xml generated
View File

@ -3,7 +3,7 @@
<component name="PHPUnit">
<option name="directories">
<list>
<option value="$PROJECT_DIR$/tests" />
<option value="E:\MyComponents\anb_php_components_pack\tests" />
</list>
</option>
</component>

View File

@ -27,7 +27,7 @@ trait ObjectArrayBasicTrait
*/
public function offsetGet (mixed $offset): mixed
{
return $this->container[$offset] ?? null;
return $this->Container[$offset] ?? null;
}
/**

View File

@ -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;
}
/**

View File

@ -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';
}
}
}

View 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 ()
{
}
}

View File

@ -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;
}
}