We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Hello, i have private constructor for my entities, which was a problem. As well i have NO setters (i am huge fan of DDD).
I was able to create instances of entities without calling constructor and setting private properties without any setters like this:
/** @var FactoryMuffin $fm */ $fm->define(User::class)->setMaker(function() { $user = (new \ReflectionClass(User::class))->newInstanceWithoutConstructor(); $property = new \ReflectionProperty(User::class, 'emailAddress'); $property->setAccessible(true); $property->setValue($user, EmailAddress::fromString('[email protected]')); $property = new \ReflectionProperty(User::class, 'passwordHash'); $property->setAccessible(true); $property->setValue($user, ClearTextPassword::fromString('123')->makeHash()); return $user; });
I believe that the FactoryMuffin::generate() method could be rewritten like this (added as another possible fallback), rewrite this:
FactoryMuffin::generate()
if (method_exists($model, $setter) && is_callable([$model, $setter])) { $model->$setter($value); } else { $model->$key = $value; }
To set value via property reflection.
The text was updated successfully, but these errors were encountered:
Possibly related to #447
Sorry, something went wrong.
No branches or pull requests
Hello, i have private constructor for my entities, which was a problem. As well i have NO setters (i am huge fan of DDD).
I was able to create instances of entities without calling constructor and setting private properties without any setters like this:
I believe that the
FactoryMuffin::generate()
method could be rewritten like this (added as another possible fallback), rewrite this:To set value via property reflection.
The text was updated successfully, but these errors were encountered: