This test fails:
<?php
public function testReplaceWithLongerPathKeepsOrder()
{
$path = new PropertyPath('new1.new2.new3');
$expected = new PropertyPath('new1.new2.new3.old2');
$builder = new PropertyPathBuilder(new PropertyPath('old1.old2'));
$builder->replace(0, 1, $path);
$this->assertEquals($expected, $builder->getPropertyPath());
}
generating new1.new2.old2.new3 instead of new1.new2.new3.old2.
PropertyPathBuilder::replace modifies the elements array correctly, but does not re-sort the array.
A foreach is then executed against $this->elements to create the PropertyPath object, resulting in a wrong path to be generated.
A simple ksort at the end of the replace method should be sufficient.