Skip to content

Commit 7767ee7

Browse files
Merge branch '5.4' into 6.0
* 5.4: (21 commits) [Finder] Fix finding VCS re-included files in excluded directory [Yaml] Improve the deprecation warnings for octal numbers to suggest migrating Fix Choice constraint with associative choices array [Form] UrlType should not add protocol to emails [Dotenv] Fix bootEnv() override with .env.local.php when the env key already exists Silence isatty warnings during tty detection [Serializer] Fix AbstractObjectNormalizer not considering pseudo type false [Notifier] Fix encoding of messages with FreeMobileTransport [Cache] workaround PHP crash [Console] Fix PHP 8.1 deprecation in ChoiceQuestion [HttpKernel] Fix compatibility with php bridge and already started php sessions [Notifier] smsapi-notifier - correct encoding Replaced full CoC text with link to documentation Making the parser stateless [Console] fix restoring stty mode on CTRL+C fix merge (bis) fix merge [Process] Avoid calling fclose on an already closed resource [GHA] test tty group [DI] Fix tests on PHP 7.1 ...
2 parents d178aab + 1c53f21 commit 7767ee7

File tree

23 files changed

+498
-4
lines changed

23 files changed

+498
-4
lines changed

DependencyInjection/AbstractDoctrineExtension.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,15 @@ protected function setMappingDriverConfig(array $mappingConfig, string $mappingN
137137
*/
138138
protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \ReflectionClass $bundle, ContainerBuilder $container, string $bundleDir = null): array|false
139139
{
140-
$bundleDir ??= \dirname($bundle->getFileName());
140+
$bundleClassDir = \dirname($bundle->getFileName());
141+
$bundleDir ??= $bundleClassDir;
141142

142143
if (!$bundleConfig['type']) {
143144
$bundleConfig['type'] = $this->detectMetadataDriver($bundleDir, $container);
145+
146+
if (!$bundleConfig['type'] && $bundleDir !== $bundleClassDir) {
147+
$bundleConfig['type'] = $this->detectMetadataDriver($bundleClassDir, $container);
148+
}
144149
}
145150

146151
if (!$bundleConfig['type']) {
@@ -150,7 +155,7 @@ protected function getMappingDriverBundleConfigDefaults(array $bundleConfig, \Re
150155

151156
if (!$bundleConfig['dir']) {
152157
if (\in_array($bundleConfig['type'], ['annotation', 'staticphp', 'attribute'])) {
153-
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingObjectDefaultName();
158+
$bundleConfig['dir'] = $bundleClassDir.'/'.$this->getMappingObjectDefaultName();
154159
} else {
155160
$bundleConfig['dir'] = $bundleDir.'/'.$this->getMappingResourceConfigDirectory($bundleDir);
156161
}

Tests/DependencyInjection/DoctrineExtensionTest.php

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\DependencyInjection\ContainerBuilder;
1717
use Symfony\Component\DependencyInjection\Definition;
1818
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
19+
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
1920

2021
/**
2122
* @author Fabio B. Silva <[email protected]>
@@ -53,6 +54,10 @@ protected function setUp(): void
5354
$this->extension
5455
->method('getMappingObjectDefaultName')
5556
->willReturn('Entity');
57+
58+
$this->extension
59+
->method('getMappingResourceExtension')
60+
->willReturn('orm');
5661
}
5762

5863
public function testFixManagersAutoMappingsWithTwoAutomappings()
@@ -271,6 +276,73 @@ public function testUnrecognizedCacheDriverException()
271276
$this->invokeLoadCacheDriver($objectManager, $container, $cacheName);
272277
}
273278

279+
public function providerBundles()
280+
{
281+
yield ['AnnotationsBundle', 'annotation', '/Entity'];
282+
yield ['AttributesBundle', 'attribute', '/Entity'];
283+
yield ['XmlBundle', 'xml', '/Resources/config/doctrine'];
284+
yield ['PhpBundle', 'php', '/Resources/config/doctrine'];
285+
yield ['YamlBundle', 'yml', '/Resources/config/doctrine'];
286+
287+
yield ['SrcXmlBundle', 'xml', '/Resources/config/doctrine'];
288+
289+
yield ['NewAnnotationsBundle', 'annotation', '/src/Entity'];
290+
yield ['NewXmlBundle', 'xml', '/config/doctrine'];
291+
}
292+
293+
/**
294+
* @dataProvider providerBundles
295+
*/
296+
public function testBundleAutoMapping(string $bundle, string $expectedType, string $dirSuffix)
297+
{
298+
$bundleDir = __DIR__.'/../Fixtures/Bundles/'.$bundle;
299+
$bundleClassName = 'Fixtures\\Bundles\\'.$bundle.'\\'.$bundle;
300+
301+
if (is_dir($bundleDir.'/src')) {
302+
require_once $bundleDir.'/src/'.$bundle.'.php';
303+
} else {
304+
require_once $bundleDir.'/'.$bundle.'.php';
305+
}
306+
307+
/** @var BundleInterface $bundleClass */
308+
$bundleClass = new $bundleClassName();
309+
310+
$mappingConfig = [
311+
'dir' => false,
312+
'type' => false,
313+
'prefix' => false,
314+
'mapping' => true,
315+
'is_bundle' => true,
316+
];
317+
318+
$this->extension
319+
->method('getMappingResourceConfigDirectory')
320+
->willReturnCallback(function ($bundleDir) {
321+
if (null !== $bundleDir && is_dir($bundleDir.'/config/doctrine')) {
322+
return 'config/doctrine';
323+
}
324+
325+
return 'Resources/config/doctrine';
326+
});
327+
328+
$container = $this->createContainer([], [$bundle => $bundleClassName]);
329+
330+
$reflection = new \ReflectionClass(\get_class($this->extension));
331+
$method = $reflection->getMethod('getMappingDriverBundleConfigDefaults');
332+
$method->setAccessible(true);
333+
334+
$this->assertSame(
335+
[
336+
'dir' => $bundleClass->getPath().$dirSuffix,
337+
'type' => $expectedType,
338+
'prefix' => $bundleClass->getNamespace().'\\Entity',
339+
'mapping' => true,
340+
'is_bundle' => true,
341+
],
342+
$method->invoke($this->extension, $mappingConfig, new \ReflectionClass($bundleClass), $container, $bundleClass->getPath())
343+
);
344+
}
345+
274346
protected function invokeLoadCacheDriver(array $objectManager, ContainerBuilder $container, $cacheName)
275347
{
276348
$method = new \ReflectionMethod($this->extension, 'loadObjectManagerCacheDriver');
@@ -280,10 +352,10 @@ protected function invokeLoadCacheDriver(array $objectManager, ContainerBuilder
280352
$method->invokeArgs($this->extension, [$objectManager, $container, $cacheName]);
281353
}
282354

283-
protected function createContainer(array $data = []): ContainerBuilder
355+
protected function createContainer(array $data = [], array $extraBundles = []): ContainerBuilder
284356
{
285357
return new ContainerBuilder(new ParameterBag(array_merge([
286-
'kernel.bundles' => ['FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'],
358+
'kernel.bundles' => array_merge(['FrameworkBundle' => 'Symfony\\Bundle\\FrameworkBundle\\FrameworkBundle'], $extraBundles),
287359
'kernel.cache_dir' => __DIR__,
288360
'kernel.build_dir' => __DIR__,
289361
'kernel.container_class' => 'kernel',
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Fixtures\Bundles\AnnotationsBundle;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
16+
class AnnotationsBundle extends Bundle
17+
{
18+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Fixtures\Bundles\AnnotationsBundle\Entity;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Entity;
16+
use Doctrine\ORM\Mapping\Id;
17+
18+
/**
19+
* @Entity
20+
*/
21+
class Person
22+
{
23+
/** @Id @Column(type="integer") */
24+
protected $id;
25+
26+
/** @Column(type="string") */
27+
public $name;
28+
29+
public function __construct($id, $name)
30+
{
31+
$this->id = $id;
32+
$this->name = $name;
33+
}
34+
35+
public function __toString(): string
36+
{
37+
return (string) $this->name;
38+
}
39+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Fixtures\Bundles\AttributesBundle;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
16+
class AttributesBundle extends Bundle
17+
{
18+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Fixtures\Bundles\AttributesBundle\Entity;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Entity;
16+
use Doctrine\ORM\Mapping\Id;
17+
18+
#[Entity]
19+
class Person
20+
{
21+
#[Id, Column(type: 'integer')]
22+
protected $id;
23+
24+
#[Column(type: 'string')]
25+
public $name;
26+
27+
public function __construct($id, $name)
28+
{
29+
$this->id = $id;
30+
$this->name = $name;
31+
}
32+
33+
public function __toString(): string
34+
{
35+
return (string) $this->name;
36+
}
37+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Fixtures\Bundles\NewAnnotationsBundle\Entity;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Entity;
16+
use Doctrine\ORM\Mapping\Id;
17+
18+
/**
19+
* @Entity
20+
*/
21+
class Person
22+
{
23+
/** @Id @Column(type="integer") */
24+
protected $id;
25+
26+
/** @Column(type="string") */
27+
public $name;
28+
29+
public function __construct($id, $name)
30+
{
31+
$this->id = $id;
32+
$this->name = $name;
33+
}
34+
35+
public function __toString(): string
36+
{
37+
return (string) $this->name;
38+
}
39+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Fixtures\Bundles\NewAnnotationsBundle;
13+
14+
use Symfony\Component\HttpKernel\Bundle\Bundle;
15+
16+
class NewAnnotationsBundle extends Bundle
17+
{
18+
public function getPath(): string
19+
{
20+
return \dirname(__DIR__);
21+
}
22+
}

Tests/Fixtures/Bundles/NewXmlBundle/config/doctrine/Person.orm.xml

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Fixtures\Bundles\NewXmlBundle\Entity;
13+
14+
class Person
15+
{
16+
protected $id;
17+
18+
public $name;
19+
20+
public function __construct($id, $name)
21+
{
22+
$this->id = $id;
23+
$this->name = $name;
24+
}
25+
26+
public function __toString(): string
27+
{
28+
return (string) $this->name;
29+
}
30+
}

0 commit comments

Comments
 (0)