alice icon indicating copy to clipboard operation
alice copied to clipboard

Use dynamic data in circular reference

Open penja opened this issue 7 years ago • 0 comments

Hi First of all, thanks for this awesome library.

I have a problem with fixtures using dynamic property value with circular references between objects. I have been written a simple test to demonstrate the problem.

use Nelmio\Alice\Loader\NativeLoader;
use PHPUnit\Framework\TestCase;

class DummyTests extends TestCase
{

    public function testCircularReferences()
    {
        $fixures = [
            \stdClass::class => [
                'foo' => [
                    'key' => "@foo1->key",
                    'value' => "<regexify('/[A-Za-z][A-Za-z0-9_]/')>"
                ],
                'foo1' => [
                    'key' => "<regexify('/[A-Za-z][A-Za-z0-9_]/')>",
                    'value' => "@foo->value",
                ]

            ],
        ];

        $fixturesLoader = new NativeLoader();
        $objects = $fixturesLoader->loadData($fixures)->getObjects();
        $this->assertEquals($objects['foo']->key, $objects['foo1']->key);
        $this->assertEquals($objects['foo']->value, $objects['foo1']->value);
    }

}

The test result is

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'Yw'
+'i0'

Alice version v3.4.1. In my opinion we should not regenerate dynamic property values if it is already defined.

penja avatar Nov 27 '18 18:11 penja