Skip to content

Commit

Permalink
[HttpKernel] Fix Bundle name regression
Browse files Browse the repository at this point in the history
  • Loading branch information
ogizanagi committed Dec 16, 2016
1 parent fef1546 commit 3b5127d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Symfony/Component/HttpKernel/Bundle/Bundle.php
Expand Up @@ -223,6 +223,8 @@ private function parseClassName()
{
$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);
}
}
}
30 changes: 30 additions & 0 deletions src/Symfony/Component/HttpKernel/Tests/Bundle/BundleTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -66,4 +67,33 @@ public function testHttpKernelRegisterCommandsIgnoresCommandsThatAreRegisteredAs
$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
{
}

0 comments on commit 3b5127d

Please sign in to comment.