Skip to content

Commit 65a436d

Browse files
committed
[HttpKernel] Fix Bundle name regression
1 parent 7f5cd15 commit 65a436d

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Bundle/Bundle.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ private function parseClassName()
223223
{
224224
$pos = strrpos(static::class, '\\');
225225
$this->namespace = false === $pos ? '' : substr(static::class, 0, $pos);
226-
$this->name = false === $pos ? static::class : substr(static::class, $pos + 1);
226+
if (null === $this->name) {
227+
$this->name = false === $pos ? static::class : substr(static::class, $pos + 1);
228+
}
227229
}
228230
}

Tests/Bundle/BundleTest.php

+30
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\HttpKernel\Tests\Bundle;
1313

1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\HttpKernel\Bundle\Bundle;
1516
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
1617
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
1718
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle;
@@ -66,4 +67,33 @@ public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAs
6667
$bundle->setContainer($container);
6768
$bundle->registerCommands($application);
6869
}
70+
71+
public function testBundleNameIsGuessedFromClass()
72+
{
73+
$bundle = new GuessedNameBundle();
74+
75+
$this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
76+
$this->assertSame('GuessedNameBundle', $bundle->getName());
77+
}
78+
79+
public function testBundleNameCanBeExplicitlyProvided()
80+
{
81+
$bundle = new NamedBundle();
82+
83+
$this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
84+
$this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
85+
$this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
86+
}
87+
}
88+
89+
class NamedBundle extends Bundle
90+
{
91+
public function __construct()
92+
{
93+
$this->name = 'ExplicitlyNamedBundle';
94+
}
95+
}
96+
97+
class GuessedNameBundle extends Bundle
98+
{
6999
}

0 commit comments

Comments
 (0)