missing unset/clearReference method #43

Closed
brikou opened this Issue Mar 3, 2012 · 5 comments

Projects

None yet

3 participants

@brikou
brikou commented Mar 3, 2012

I miss this kind of method when using setReference with indexed names fe: $this->setReference('my_entity_'.$i, $my_entity); $i++

Another great addition would be that set Reference accept array of refs fe: $this->setReference('my_entities', $my_entities);

cheer

@l3pp4rd
l3pp4rd commented Mar 3, 2012
<?php
array_walk(function($item, $key, $fixture) {
    $fixture->setReference('entity'.$key, $item);
}, $entities);

Keys can be overwriten, so why you need a clear method? unless you building a framework out of fixtures

@brikou
brikou commented Mar 3, 2012

As you've said keys can be overwritten, but in a part of my fixture my references count is (let's say) 10 and in another namespace it is 5, so the 5th first are overwritten but I still have the last 5 from the other fixture namespace.
So when I loop and because i don't know the length, I get fixtures from outer namespace... I fixed this overlapping by naming the reference 'entity_'.md5(NAMESPACE).'_'.$i but it is kind of ugly...

@brikou
brikou commented Mar 3, 2012

the best would be to allow array when setting references (overridable and cleaner when looping over these refs)

@l3pp4rd
l3pp4rd commented Mar 3, 2012

well, I do not agree in general. fixture references should not be overwritten or cleared, etc in best practices of their purpose. It is a consern of user how to name them so they do not conflict. and if you would use addReference instead setReference there won't be any conflicts, because otherwise you get an exception on attempt to overwrite. If you think the way that you need such functionality anyway, I would recommend to use a shared fixture interface with overriden referenceRepository. I personally woun't like users to use such methodology by default when they do not need it

@lavoiesl
Member

Closing due to inactivity and it seems it is not really an issue. Please reopen if needed.

@lavoiesl lavoiesl closed this Mar 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment