azenox / php-string2chaining
将包含链的字符串转换为对象链
1.0.0
2022-04-23 20:37 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-30 01:48:59 UTC
README
将包含链的字符串转换为对象链
安装
通过composer
composer require azenox/php-string2chaining
使用方法
只有一个方法: parse()
例如,在用PHPUnit进行测试时,我们可以这样操作
public function setUp(): void { parent::setUp(); $this->user1 = User::find(1); $this->user2 = User::find(2); } private function userPayload() { return [ 'test with user1' => [ 'user1', 'birth_date->format(\'Y-m-d\')', '1998-08-22' ], 'test with user2' => [ 'user2', 'another_date->format(\'Y-m-d\')', '1998-03-30' ], ]; } /** * @test * @dataProvider userPayload */ public function birth_date_should_be_equals_to_this_date($user, $str, $test) { $obj = $this->{$user}; $this->assertEquals($test, String2chaining::parse($obj, $str)); }