vierge-noire / cakephp-fixture-factories

CakePHP Fixture Factories
https://vierge-noire.github.io/
MIT License
85 stars 20 forks source link

Factory::make ignores null values #225

Closed cnizzardini-cmi closed 1 year ago

cnizzardini-cmi commented 1 year ago

In CakePHP 4.2 and Fixture Factory 2.4. I am fairly certain you can reproduce this when using persist() to get the entity as well.

Steps to reproduce

$foo = FooFactory::make(['test' => null])->getEntity();
$foo->test = 'New';
var_dump($foo->getOriginal('test')); // this will output "New"

Expected Result

$foo->getOriginal('test') outputs NULL

More Context

This bug is not present with the following setup in the FooFactory class:

    protected function setDefaultTemplate(): void {
        $this->setDefaultData(function (Generator $faker) {
            return [
                'test' => null,
            ];
        });
    }

With this the following code works as expected:

$foo = FooFactory::make()->getEntity();
$foo->test = 'New';
var_dump($foo->getOriginal('test')); // this will output NULL

I hope this is clear.