Skip to content

Commit e8be3bf

Browse files
committed
Separated fixture loading
1 parent 84a61ab commit e8be3bf

File tree

1 file changed

+42
-19
lines changed

1 file changed

+42
-19
lines changed

tests/bootstrap.php

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,19 @@
133133
return;
134134
}
135135

136-
// Create and boot 'test' kernel
137-
$kernel = new Kernel((string)getenv('APP_ENV'), (bool)getenv('APP_DEBUG'));
138-
$kernel->boot();
136+
function getApplication(): Application
137+
{
138+
// Create and boot 'test' kernel
139+
$kernel = new Kernel((string)getenv('APP_ENV'), (bool)getenv('APP_DEBUG'));
140+
$kernel->boot();
141+
142+
// Create new application
143+
$application = new Application($kernel);
144+
$application->setAutoExit(false);
145+
return $application;
146+
}
139147

140-
// Create new application
141-
$application = new Application($kernel);
142-
$application->setAutoExit(false);
148+
$application = getApplication();
143149

144150
// Add the doctrine:database:drop command to the application and run it
145151
$dropDatabaseDoctrineCommand = static function () use ($application): void {
@@ -177,18 +183,6 @@
177183
$application->run($input, new ConsoleOutput());
178184
};
179185

180-
// Add the doctrine:fixtures:load command to the application and run it
181-
$loadFixturesDoctrineCommand = static function () use ($application): void {
182-
$input = new ArrayInput([
183-
'command' => 'doctrine:fixtures:load',
184-
'--no-interaction' => true,
185-
]);
186-
187-
$input->setInteractive(false);
188-
189-
$application->run($input, new ConsoleOutput());
190-
};
191-
192186
// Ensure that we have "clean" JWT auth cache file
193187
$createJwtAuthCache = static function (): void {
194188
// Specify used cache file
@@ -221,8 +215,37 @@
221215
$dropDatabaseDoctrineCommand,
222216
$createDatabaseDoctrineCommand,
223217
$updateSchemaDoctrineCommand,
224-
$loadFixturesDoctrineCommand,
225218
$createJwtAuthCache,
226219
$createDatabaseCreateCache,
227220
]
228221
);
222+
223+
224+
/**
225+
* For some reason we need to re-create application to get loading of
226+
* fixtures working correctly with ORM v3
227+
*
228+
* Without this we get error like:
229+
* An exception occurred while executing a query: SQLSTATE[42000]: Syntax
230+
* error or access violation: 1305 SAVEPOINT DOCTRINE_8 does not exist
231+
*/
232+
$application = getApplication();
233+
234+
// Add the doctrine:fixtures:load command to the application and run it
235+
$loadFixturesDoctrineCommand = static function () use ($application): void {
236+
$input = new ArrayInput([
237+
'command' => 'doctrine:fixtures:load',
238+
'--no-interaction' => true,
239+
]);
240+
241+
$input->setInteractive(false);
242+
243+
$application->run($input, new ConsoleOutput());
244+
};
245+
246+
array_map(
247+
'\call_user_func',
248+
[
249+
$loadFixturesDoctrineCommand,
250+
]
251+
);

0 commit comments

Comments
 (0)