Skip to content

Commit 8c8566e

Browse files
committed
allow creating class data objects with absolute namespaces
1 parent d2b0f35 commit 8c8566e

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

src/Util/ClassSource/Model/ClassData.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ public function getNamespace(): string
8888
return $this->rootNamespace;
8989
}
9090

91+
// Namespace is already absolute, don't add the rootNamespace.
92+
if (str_starts_with($this->namespace, '\\')) {
93+
return substr_replace($this->namespace, '', 0, 1);
94+
}
95+
9196
return \sprintf('%s\%s', $this->rootNamespace, $this->namespace);
9297
}
9398

tests/Util/ClassSource/ClassDataTest.php

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bundle\MakerBundle\MakerBundle;
1616
use Symfony\Bundle\MakerBundle\Test\MakerTestKernel;
17-
use Symfony\Bundle\MakerBundle\Util\ClassNameDetails;
1817
use Symfony\Bundle\MakerBundle\Util\ClassSource\Model\ClassData;
1918

2019
class ClassDataTest extends TestCase
@@ -115,12 +114,9 @@ public function testGetClassNameRelativeNamespace(): void
115114

116115
public function testGetClassNameWithAbsoluteNamespace(): void
117116
{
118-
$this->markTestSkipped();
119117
$class = ClassData::create(class: '\\Foo\\Bar\\Admin\\Baz', suffix: 'Controller');
120118
self::assertSame('BazController', $class->getClassName());
121-
self::assertSame('Baz', $class->getClassName(relative: false, withoutSuffix: true));
122-
// self::assertSame('Admin\FooController', $class->getClassName(relative: true, withoutSuffix: false));
123-
// self::assertSame('Admin\Baz', $class->getClassName(relative: true, withoutSuffix: true));
119+
self::assertSame('Foo\Bar\Admin', $class->getNamespace());
124120
self::assertSame('Foo\Bar\Admin\BazController', $class->getFullClassName());
125121
}
126122

@@ -147,18 +143,4 @@ public function fullClassNameProvider(): \Generator
147143
yield ['Controller\MyController', 'Custom', false, true, 'Custom\Controller\My'];
148144
yield ['Controller\MyController', 'Custom', true, true, 'Controller\My'];
149145
}
150-
151-
// public function testClassNameDetails(): void
152-
// {
153-
// $class = new ClassNameDetails(
154-
// fullClassName: 'Foo',
155-
// namespacePrefix: 'Controller\\',
156-
// suffix: 'Controller',
157-
// );
158-
//
159-
// self::assertSame('FooController', $class->getFullName());
160-
// self::assertSame('MyController', $class->getShortName());
161-
// self::assertSame('My', $class->getRelativeNameWithoutSuffix());
162-
// self::assertSame('MyController', $class->getRelativeName());
163-
// }
164146
}

0 commit comments

Comments
 (0)