From bc92fb0dc97976e2a2f0802f74cbad6a534e23f3 Mon Sep 17 00:00:00 2001 From: Pierre Ambroise Date: Mon, 24 Mar 2025 23:20:49 +0100 Subject: [PATCH] Allow creation of classes with the same name as PHP native classes --- src/Generator.php | 2 +- tests/Maker/MakeEntityTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Generator.php b/src/Generator.php index fbadc1bca..e1049dd82 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -188,8 +188,8 @@ public function createClassNameDetails(string $name, string $namespacePrefix, st $className = Str::asClassName($name, $suffix); try { - Validator::classDoesNotExist($className); $className = rtrim($fullNamespacePrefix, '\\').'\\'.$className; + Validator::classDoesNotExist($className); } catch (RuntimeCommandException) { } } diff --git a/tests/Maker/MakeEntityTest.php b/tests/Maker/MakeEntityTest.php index 54059bad3..60cf9bb8a 100644 --- a/tests/Maker/MakeEntityTest.php +++ b/tests/Maker/MakeEntityTest.php @@ -762,6 +762,19 @@ public function getTestDetails(): \Generator $this->runEntityTest($runner); }), ]; + + yield 'its_can_create_classes_with_native_class_name' => [$this->createMakeEntityTest() + ->run(function (MakerTestRunner $runner) { + $runner->runMaker([ + // entity class name + 'Directory', + // add not additional fields + '', + ]); + + $this->runEntityTest($runner); + }), + ]; } /** @param array $data */