Skip to content

[PropertyAccess] PropertyPathBuilder::replace does not keep the order of elements #17102

@alekitto

Description

@alekitto

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions