[HttpKernel] Fix Bundle name regression

This commit is contained in:
Maxime Steinhausser 2016-12-15 19:45:08 +01:00 committed by Maxime Steinhausser
parent fef1546a7e
commit 3b5127dbe9
2 changed files with 33 additions and 1 deletions

View File

@ -223,6 +223,8 @@ abstract class Bundle implements BundleInterface
{
$pos = strrpos(static::class, '\\');
$this->namespace = false === $pos ? '' : substr(static::class, 0, $pos);
$this->name = false === $pos ? static::class : substr(static::class, $pos + 1);
if (null === $this->name) {
$this->name = false === $pos ? static::class : substr(static::class, $pos + 1);
}
}
}

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\HttpKernel\Tests\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionNotValidBundle\ExtensionNotValidBundle;
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionPresentBundle\ExtensionPresentBundle;
use Symfony\Component\HttpKernel\Tests\Fixtures\ExtensionAbsentBundle\ExtensionAbsentBundle;
@ -66,4 +67,33 @@ class BundleTest extends \PHPUnit_Framework_TestCase
$bundle->setContainer($container);
$bundle->registerCommands($application);
}
public function testBundleNameIsGuessedFromClass()
{
$bundle = new GuessedNameBundle();
$this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
$this->assertSame('GuessedNameBundle', $bundle->getName());
}
public function testBundleNameCanBeExplicitlyProvided()
{
$bundle = new NamedBundle();
$this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
$this->assertSame('Symfony\Component\HttpKernel\Tests\Bundle', $bundle->getNamespace());
$this->assertSame('ExplicitlyNamedBundle', $bundle->getName());
}
}
class NamedBundle extends Bundle
{
public function __construct()
{
$this->name = 'ExplicitlyNamedBundle';
}
}
class GuessedNameBundle extends Bundle
{
}