You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issues with loading Alice fixtures with nelmio/alice ^3.5.8
Hey, we're slowly upgrading to alice 3, which in our case means the latest alice 3.5.8 and
we're experiencing some issues with this new version that seem to relate to creating objects using __calls:
while the object used in __calls has been initialised using the same object.
Either way, the __calls function seem to create entirely new objects using the referenced template,
instead of being the object created from that template.
Which gets an instance of Ytitne and calls it's alterEntity function.
And the Ytitne class:
class Ytitne
{
private$name;
private$entity;
publicfunction__construct(string$name)
{
$this->name = $name;
}
publicfunctionalterEntity(Entity$entity): void
{
if (null !== $this->entity && $this->entity !== $entity) {
var_dump($this->entity->getName(), $entity->getName());
thrownew \InvalidArgumentException('Can not alter this entity, as one exists');
}
$this->entity = $entity;
}
}
Note, the alterEntity function will throw an exception when the Entity has already been set
and the given Entity is not the same as the one already configured.
Creating a fixture file for this, we get the following broken.yaml
/home/mvannes/projects/alice-loading-issue/src/Ytitne.php:19:
string(8) "quisquam"
/home/mvannes/projects/alice-loading-issue/src/Ytitne.php:19:
string(5) "culpa"
PHP Fatal error: Uncaught InvalidArgumentException: Can not alter this entity, as one exists in /home/mvannes/projects/alice-loading-issue/src/Ytitne.php:20
Stack trace:
#0 /home/mvannes/projects/alice-loading-issue/src/Entity.php(15): VanNes\Ytitne->alterEntity(Object(VanNes\Entity))
#1 /home/mvannes/projects/alice-loading-issue/vendor/nelmio/alice/src/Generator/Instantiator/Chainable/NoCallerMethodCallInstantiator.php(41): VanNes\Entity->__construct('culpa', Object(VanNes\Ytitne))
#2 /home/mvannes/projects/alice-loading-issue/vendor/nelmio/alice/src/Generator/Instantiator/Chainable/AbstractChainableInstantiator.php(44): Nelmio\Alice\Generator\Instantiator\Chainable\NoCallerMethodCallInstantiator->createInstance(Object(Nelmio\Alice\Definition\Fixture\TemplatingFixture))
#3 /home/mvannes/projects/alice-loading-issue/vendor/nelmio/alice/src/Generator/Instantiator/InstantiatorRegistry.php(72): Nelmio\Alice\Generator\Instantiator\Chainable\AbstractChainableInstantiator->instantiate(Object(Nelmio\Alice\Definition\Fixture\Templati in /home/mvannes/projects/alice-loading-issue/vendor/nelmio/alice/src/Generator/ObjectGenerator/SimpleObjectGenerator.php on line 114
As one can see, the \InvalidArgumentException is thrown. And the object passed to alterEntity even has a different
name from the one that was initially set through the Entity constructor (or vice versa?)
If we remove the call to this exception, replace it with a return, and instead look at a var dump of the created objects, we get the following:
Thanks for the report and the reproducer! My gut feeling would be that there is a clone done where it shouldn't... I'm not sure when I can have a look, but I don't expect this to be too complicated
https://github.com/Mvannes/alice-loading-issue
Issues with loading Alice fixtures with nelmio/alice ^3.5.8
Hey, we're slowly upgrading to alice 3, which in our case means the latest alice 3.5.8 and
we're experiencing some issues with this new version that seem to relate to creating objects using
__calls:
while the object used in
__calls
has been initialised using the same object.Either way, the
__calls
function seem to create entirely new objects using the referenced template,instead of being the object created from that template.
An example:
Given the following class:
Which gets an instance of
Ytitne
and calls it'salterEntity
function.And the
Ytitne
class:Note, the
alterEntity
function will throw an exception when theEntity
has already been setand the given
Entity
is not the same as the one already configured.Creating a fixture file for this, we get the following
broken.yaml
This would imply that two objects are created, and the
ytitne_1
calls thealterEntity
function with the created object
@entity_1
.Instead, if we use the following code to load this fixture file we get a completely different result.
Namely, we get the following:
As one can see, the
\InvalidArgumentException
is thrown. And the object passed toalterEntity
even has a differentname from the one that was initially set through the
Entity
constructor (or vice versa?)If we remove the call to this exception, replace it with a
return
, and instead look at a var dump of the created objects, we get the following:Note that the object hashes of the
entity_1
andytitne_1
's entity differ.This feels like it isn't intended behaviour, as additional objects are created instead of
To test it for yourself;
git clone [email protected]:Mvannes/alice-loading-issue.git
cd alice-loading-issue
composer install
php app.php
This was tested using the following php version:
The text was updated successfully, but these errors were encountered: