Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Factory::make ignores null values #226

Open
cnizzardini opened this issue Sep 20, 2023 · 2 comments
Open

Factory::make ignores null values #226

cnizzardini opened this issue Sep 20, 2023 · 2 comments

Comments

@cnizzardini
Copy link

cnizzardini commented Sep 20, 2023

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
Copy link
Collaborator

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
Copy link
Author

cnizzardini commented Oct 12, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants