Skip to content
This repository was archived by the owner on Nov 17, 2020. It is now read-only.

Commit 5e4326d

Browse files
committed
Fix issue with callables
1 parent 2affc30 commit 5e4326d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

AbstractFixture.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ private function fixtureObject($datas)
166166
foreach ($datas as $field => $value) {
167167

168168
// If the value is a callable we execute it and inject the fixture object and the manager.
169-
if (is_callable($value, true)) {
170-
$value = $value($this, $this->manager);
169+
if ($value instanceof \Closure) {
170+
$value = $value($obj, $this, $this->manager);
171171
}
172172

173173
if ($this->propertyAccessor) {

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ When you have self-referencing relationships, you may need a reference of an obj
108108

109109
For this, first, you should set the `flushEveryXIterations` option to `1` (view below) to allow flushing on every iteration.
110110

111-
And next, you can set a `callable` element as the value of your object so you can retrieve manually the reference from the
112-
injected `AbstractFixture` object as first argument.
111+
And next, you can set a `callable` element as the value of your object so you can interact manually with the injected object
112+
as 1st argument, and the `AbstractFixture` object as 2nd argument.
113113

114-
The `ObjectManager` is also injected as second argument in case you need to do some specific requests or query through another
114+
The `ObjectManager` is also injected as 3rd argument in case you need to do some specific requests or query through another
115115
table.
116116

117117
Example here:
@@ -153,8 +153,10 @@ class PostFixtures extends AbstractFixture
153153
[
154154
'id' => 2,
155155
'title' => 'Second post',
156-
'parent' => function(AbstractFixture $fixture, ObjectManager $manager) {
157-
return $fixture->getReference('posts-1');
156+
'parent' => function(Post $object, AbstractFixture $fixture, ObjectManager $manager) {
157+
$ref = $fixture->getReference('posts-1');
158+
$object->setParent($ref); // This is often needed if you don't use cascade persist
159+
return $ref;
158160
},
159161
],
160162
];

0 commit comments

Comments
 (0)