Skip to content

Commit f525f32

Browse files
authored
Merge pull request #12482 from greg0ire/fix-el-formatting
Avoid passing arrays to get_class
2 parents 5fc5b19 + 4689337 commit f525f32

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4233,12 +4233,6 @@ parameters:
42334233
count: 1
42344234
path: src/Tools/Console/Command/MappingDescribeCommand.php
42354235

4236-
-
4237-
message: '#^Parameter \#1 \$entityListeners of method Doctrine\\ORM\\Tools\\Console\\Command\\MappingDescribeCommand\:\:formatEntityListeners\(\) expects list\<object\>, array\<string, list\<array\{class\: class\-string, method\: string\}\>\> given\.$#'
4238-
identifier: argument.type
4239-
count: 1
4240-
path: src/Tools/Console/Command/MappingDescribeCommand.php
4241-
42424236
-
42434237
message: '#^Parameter \#2 \$callback of function array_filter expects \(callable\(class\-string\)\: bool\)\|null, Closure\(mixed\)\: \(0\|1\|false\) given\.$#'
42444238
identifier: argument.type

src/Tools/Console/Command/MappingDescribeCommand.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\Console\Style\SymfonyStyle;
1616

1717
use function array_filter;
18-
use function array_map;
1918
use function array_merge;
2019
use function count;
2120
use function current;
@@ -271,13 +270,21 @@ private function formatMappings(array $propertyMappings): array
271270
/**
272271
* Format the entity listeners
273272
*
274-
* @phpstan-param list<object> $entityListeners
273+
* @phpstan-param array<string, list<array{class: class-string, method: string}>> $entityListeners
275274
*
276275
* @return string[]
277276
* @phpstan-return array{0: string, 1: string}
278277
*/
279278
private function formatEntityListeners(array $entityListeners): array
280279
{
281-
return $this->formatField('Entity listeners', array_map('get_class', $entityListeners));
280+
$listeners = [];
281+
282+
foreach ($entityListeners as $eventName => $eventListeners) {
283+
foreach ($eventListeners as $listener) {
284+
$listeners[] = sprintf('%s: %s::%s', $eventName, $listener['class'], $listener['method']);
285+
}
286+
}
287+
288+
return $this->formatField('Entity listeners', $listeners);
282289
}
283290
}

tests/Tests/ORM/Tools/Console/Command/MappingDescribeCommandTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Doctrine\ORM\Tools\Console\Command\MappingDescribeCommand;
99
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
1010
use Doctrine\Tests\Models\Cache\AttractionInfo;
11+
use Doctrine\Tests\Models\CMS\CmsAddress;
1112
use Doctrine\Tests\OrmFunctionalTestCase;
1213
use Symfony\Component\Console\Application;
1314
use Symfony\Component\Console\Tester\CommandTester;
@@ -79,4 +80,22 @@ public function testShowSpecificNotFound(): void
7980
]
8081
);
8182
}
83+
84+
public function testShowEntityWithEntityListeners(): void
85+
{
86+
$this->tester->execute(
87+
[
88+
'command' => $this->command->getName(),
89+
'entityName' => CmsAddress::class,
90+
]
91+
);
92+
93+
$display = $this->tester->getDisplay();
94+
95+
self::assertStringContainsString(CmsAddress::class, $display);
96+
self::assertStringContainsString('Entity listeners', $display);
97+
self::assertStringContainsString('CmsAddressListener', $display);
98+
self::assertStringContainsString('postPersist', $display);
99+
self::assertStringContainsString('prePersist', $display);
100+
}
82101
}

0 commit comments

Comments
 (0)