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 #226

Open cnizzardini opened 1 year ago

cnizzardini 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"

FooFactory:

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

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.

pabloelcolombiano commented 1 year ago

I have pushed the commit above to reproduce the issue, but unsuccessfully (see the pipe here).

Could you identify the difference between your setup and the ones in the package's test suite?

cnizzardini commented 1 year ago

@pabloelcolombiano I am curious if you attempted reproducing this in an actual application? I also updated the issue with more code to reproduce the issue.