/** * @covers ::ofObject * @dataProvider provideMergeableAssignables */ public function testCanMergeIntoAssignablesProperty($ours, $theirs, $expectedResult) { // ---------------------------------------------------------------- // setup your test // ---------------------------------------------------------------- // perform the change MergeIntoProperty::ofObject($ours, "child", $theirs); // ---------------------------------------------------------------- // test the results $this->assertEquals($expectedResult, $ours); }
/** * merge their data into our object, using dot.notation.support to * find the point where the merge starts * * @param object $obj * the object that we want to merge into * @param string $path * the dot.notation.support path to where the merge should start * @param mixed $value * the data that we want to merge from * @param array|callable|string|null * if $path goes beyond what exists in $ours, how do we want to * extend $ours? * @return void */ public static function intoObject($obj, $path, $value, $extendingItem = null) { // robustness! RequireAssignable::check($obj, E4xx_UnsupportedType::class); RequireDotNotationPath::check($path); // find the point where we want to merge list($firstPart, $finalPart) = self::splitPathInTwo($path); if ($firstPart !== null) { $leaf =& DescendDotNotationPath::intoObject($obj, $firstPart, $extendingItem); } else { $leaf = $obj; } // merge it MergeIntoProperty::of($leaf, $finalPart, $value); }