Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
e09ea26a3c | |||
ebfd42a88e | |||
054e6a7cdc |
@@ -16,11 +16,11 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">=8.4",
|
||||
"php": "^8.4",
|
||||
"ext-mbstring": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": ">=11.5.6"
|
||||
"phpunit/phpunit": "^12.0.4"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
538
composer.lock
generated
538
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -314,18 +314,18 @@ final class ClassMapper
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает значение по умолчанию для разных типов данных.
|
||||
* Возвращает значение по умолчанию для типа $typeName.
|
||||
*
|
||||
* @param string $typeName Имя типа данных.
|
||||
* @param string $typeName Тип
|
||||
*
|
||||
* @return mixed|null Результат.
|
||||
* @return mixed Значение по умолчанию
|
||||
*/
|
||||
public static function GetDefaults (string $typeName): mixed
|
||||
{
|
||||
return match ($typeName) {
|
||||
'int' => 0,
|
||||
'float' => 0.0,
|
||||
'bool' => false,
|
||||
return match (strtolower($typeName)) {
|
||||
'int', 'integer' => 0,
|
||||
'float', 'double' => 0.0,
|
||||
'bool', 'boolean' => false,
|
||||
'string' => '',
|
||||
'array' => [],
|
||||
'object' => new stdClass(),
|
||||
|
@@ -3,6 +3,8 @@
|
||||
namespace goodboyalex\php_components_pack\tests\classes;
|
||||
|
||||
use goodboyalex\php_components_pack\classes\ClassMapper;
|
||||
use goodboyalex\php_components_pack\tests\data\A;
|
||||
use goodboyalex\php_components_pack\tests\data\B;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ClassMapperTest extends TestCase
|
||||
@@ -11,12 +13,10 @@ class ClassMapperTest extends TestCase
|
||||
{
|
||||
$this->PrepareForTest();
|
||||
|
||||
$a = new \goodboyalex\php_components_pack\tests\data\A();
|
||||
$a->a = 'a';
|
||||
$a->b = 2;
|
||||
$a->c = true;
|
||||
$a = new A('a', 2, true);
|
||||
|
||||
$b = new B();
|
||||
|
||||
ClassMapper::MapClass($a, $b);
|
||||
|
||||
$this->assertEquals('a', $b->a);
|
||||
|
@@ -1,10 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace goodboyalex\php_components_pack\tests\classes;
|
||||
namespace goodboyalex\php_components_pack\tests\data;
|
||||
|
||||
class B
|
||||
{
|
||||
public string $a;
|
||||
public int $b;
|
||||
public string $d;
|
||||
|
||||
public function __construct (string $a = "", int $b = 0, string $d = "")
|
||||
{
|
||||
$this->a = $a;
|
||||
$this->b = $b;
|
||||
$this->d = $d;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user