Skip to content

Commit 1812c0a

Browse files
committed
[ci] use annotations when attributes are not supported
1 parent f003e99 commit 1812c0a

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tests/Maker/MakeEntityTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,24 @@ private function createMakeEntityTest(bool $withDatabase = true): MakerTestDetai
3131
return $this->createMakerTest()
3232
->preRun(function (MakerTestRunner $runner) use ($withDatabase) {
3333
$config = $runner->readYaml('config/packages/doctrine.yaml');
34+
$appMapping = $config['doctrine']['orm']['mappings']['App'] ?? [];
3435

35-
if (isset($config['doctrine']['orm']['mappings']['App']['type']) && $this->useAttributes($runner)) {
36-
// use attributes
36+
/* @legacy Refactor when annotations are no longer supported. */
37+
if (isset($appMapping['type']) && $this->useAttributes($runner)) {
38+
// We want to use attributes by default in tests if they're supported.
3739
$runner->replaceInFile(
3840
'config/packages/doctrine.yaml',
3941
'type: annotation',
4042
'type: attribute'
4143
);
44+
} elseif (!empty($appMapping) && !$this->useAttributes($runner)) {
45+
// Flex assumes attributes are supported based on package versions.
46+
// When PHP <8.0, we have to use annotations.
47+
$runner->modifyYamlFile('config/packages/doctrine.yaml', function (array $data) {
48+
$data['doctrine']['orm']['mappings']['App']['type'] = 'annotation';
49+
50+
return $data;
51+
});
4252
}
4353

4454
if ($withDatabase) {

0 commit comments

Comments
 (0)