hollisho / object-builder
object-builder
v1.0.6
2024-10-25 04:00 UTC
Requires
- php: >=7.2
- ext-json: *
- hollisho/php-helpers: ^1.1
Requires (Dev)
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^8.5
This package is auto-updated.
Last update: 2024-10-25 04:01:10 UTC
README
Generic object builder
install
composer require hollisho/object-builder
usage
$objectBuilder = ObjectBuilder::build(User::class, [ 'id' => 1, 'username' => 'Hollis' ]); //get username var_dump($objectBuilder->username); //or $user = HUser::build([ 'id' => 2, 'username' => 'Hollis Ho' ]); //get username var_dump($user->username); //setter class HUser extends HObject { public $id; public $username; //use setter public function setGrade($value) { $this->username = $value . ':' . $this->username; } } $user = HUser::build([ 'id' => 2, 'username' => 'Hollis Ho' ]); $user->grade = 'grade 1'; //or $user->setGrade('grade 1');
Unit Test
- 执行指定目录所有用例
$ ./vendor/phpunit/phpunit/phpunit --configuration phpunit.xml
- 执行指定文件
$ ./vendor/phpunit/phpunit/phpunit --configuration phpunit.xml --test-suffix TemplateTest.php
- 执行 TemplateTest 用例
$ ./vendor/phpunit/phpunit/phpunit --configuration phpunit.xml --filter TemplateTest
- 执行 TemplateTest::test01 用例
$ ./vendor/phpunit/phpunit/phpunit --configuration phpunit.xml --filter TemplateTest::test01