Skip to content

Commit

Permalink
Merge pull request #547 from veewee/fix-unnecessary-use-statement
Browse files Browse the repository at this point in the history
Fix unused import in extending assembler
  • Loading branch information
veewee authored Sep 27, 2024
2 parents 59a5c10 + 662412b commit dd5b277
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function assemble(ContextInterface $context)

$namespace = $type->getNamespace();
$typeName = Normalizer::normalizeClassname($extending['type']);
$extendedClassName = sprintf('\\%s\\%s', $namespace, $typeName);
$extendedClassName = sprintf('%s\\%s', $namespace, $typeName);

try {
$extendAssembler = new ExtendAssembler($extendedClassName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function it_can_assemble_type_context()
/**
* @test
*/
function it_assembles_a_type()
function it_assembles_a_type_in_same_namespace()
{
$assembler = new ExtendingTypeAssembler();
$context = $this->createContext();
Expand All @@ -51,7 +51,29 @@ function it_assembles_a_type()
$expected = <<<CODE
namespace MyNamespace;
use \MyNamespace\MyBaseType;
class MyType extends MyBaseType
{
}
CODE;

$this->assertEquals($expected, $code);
}

/**
* @test
*/
function it_assembles_a_type_in_other_namespace()
{
$assembler = new ExtendingTypeAssembler();
$context = $this->createContext('OtherNamespace');
$assembler->assemble($context);

$code = $context->getClass()->generate();
$expected = <<<CODE
namespace MyNamespace;
use OtherNamespace\MyBaseType;
class MyType extends MyBaseType
{
Expand Down Expand Up @@ -119,10 +141,10 @@ class MyType
/**
* @return TypeContext
*/
private function createContext()
private function createContext(?string $importedNamespace = null)
{
$class = new ClassGenerator('MyType', 'MyNamespace');
$type = new Type('MyNamespace', 'MyType', [], XsdType::create('MyType')->withMeta(static fn (TypeMeta $meta) => $meta->withExtends([
$type = new Type($importedNamespace ?? 'MyNamespace', 'MyType', [], XsdType::create('MyType')->withMeta(static fn (TypeMeta $meta) => $meta->withExtends([
'type' => 'MyBaseType',
'namespace' => 'xxxx'
])));
Expand Down

0 comments on commit dd5b277

Please sign in to comment.