Convert string containing chains into object chains
Via composer
composer require azenox/php-string2chaining
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));
}