Skip to content

Commit

Permalink
bug #1422 Generator verifies if class exists before altering class name
Browse files Browse the repository at this point in the history
  • Loading branch information
Antarian authored Feb 20, 2024
1 parent f661302 commit eb4542f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,13 @@ public function createClassNameDetails(string $name, string $namespacePrefix, st
// class is already "absolute" - leave it alone (but strip opening \)
$className = substr($name, 1);
} else {
$className = rtrim($fullNamespacePrefix, '\\').'\\'.Str::asClassName($name, $suffix);
$className = Str::asClassName($name, $suffix);

try {
Validator::classDoesNotExist($className);
$className = rtrim($fullNamespacePrefix, '\\').'\\'.$className;
} catch (RuntimeCommandException $e) {
}
}

Validator::validateClassName($className, $validationErrorMessage);
Expand Down
24 changes: 24 additions & 0 deletions tests/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,29 @@ public function getClassNameDetailsTests(): \Generator
'App\\Entity\\User',
'User',
];

yield 'non_prefixed_fake_fqcn' => [
'App\\Entity\\User',
'',
'',
'App\\App\\Entity\\User',
'Entity\\User',
];

yield 'real_fqcn_with_suffix' => [
'Symfony\\Bundle\\MakerBundle\\Tests\\Generator',
'Test',
'Test',
'Symfony\\Bundle\\MakerBundle\\Tests\\GeneratorTest',
'Symfony\\Bundle\\MakerBundle\\Tests\\GeneratorTest',
];

yield 'real_fqcn_without_suffix' => [
'Symfony\\Bundle\\MakerBundle\\Tests\\GeneratorTest',
'',
'',
'Symfony\\Bundle\\MakerBundle\\Tests\\GeneratorTest',
'Symfony\\Bundle\\MakerBundle\\Tests\\GeneratorTest',
];
}
}

0 comments on commit eb4542f

Please sign in to comment.