azenox / php-string2chaining
Convert string containing chains into object chains
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: 2025-05-29 01:54:51 UTC
README
Convert string containing chains into object chains
Installation
Via composer
composer require azenox/php-string2chaining
Usage
There is only one method: parse()
For example when testing with PHPUnit, we can have something like this:
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)); }