From 4920b011500ca28c7cb2199d2b96bf2cf06fea28 Mon Sep 17 00:00:00 2001 From: Andrey Savitsky Date: Tue, 28 Jun 2016 14:49:59 +0300 Subject: [PATCH 1/4] fast fix --- src/Generator/ClassGenerator.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Generator/ClassGenerator.php b/src/Generator/ClassGenerator.php index 2d382ebf..06483ce0 100644 --- a/src/Generator/ClassGenerator.php +++ b/src/Generator/ClassGenerator.php @@ -1018,6 +1018,7 @@ private function validateConstantValue($value) */ private function generateShortOrCompleteClassname($fqnClassName) { + $fqnClassName = trim($fqnClassName, '\\'); $parts = explode('\\', $fqnClassName); $className = array_pop($parts); $classNamespace = implode('\\', $parts); From d4a382f925ef13592e76989059eba8ad5b1360a6 Mon Sep 17 00:00:00 2001 From: Andrey Savitsky Date: Tue, 28 Jun 2016 14:56:54 +0300 Subject: [PATCH 2/4] Update ClassGenerator.php --- src/Generator/ClassGenerator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Generator/ClassGenerator.php b/src/Generator/ClassGenerator.php index 06483ce0..843313c6 100644 --- a/src/Generator/ClassGenerator.php +++ b/src/Generator/ClassGenerator.php @@ -1018,7 +1018,7 @@ private function validateConstantValue($value) */ private function generateShortOrCompleteClassname($fqnClassName) { - $fqnClassName = trim($fqnClassName, '\\'); + $fqnClassName = ltrim($fqnClassName, '\\'); $parts = explode('\\', $fqnClassName); $className = array_pop($parts); $classNamespace = implode('\\', $parts); From b6d82aff9a9ac0664678dbf8812c9dd20f66cc2d Mon Sep 17 00:00:00 2001 From: qRoC Date: Tue, 28 Jun 2016 21:14:42 +0300 Subject: [PATCH 3/4] add tests --- test/Generator/ClassGeneratorTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/Generator/ClassGeneratorTest.php b/test/Generator/ClassGeneratorTest.php index 039e5cd6..013d177d 100644 --- a/test/Generator/ClassGeneratorTest.php +++ b/test/Generator/ClassGeneratorTest.php @@ -1105,6 +1105,17 @@ public function testCorrectExtendNames() $classGenerator->setName('ClassName'); $classGenerator->setExtendedClass('DateTime'); $this->assertContains('class ClassName extends DateTime', $classGenerator->generate()); + + $classGenerator = new ClassGenerator(); + $classGenerator->setName('ClassName'); + $classGenerator->setNamespaceName('SomeNamespace'); + $classGenerator->setExtendedClass('\DateTime'); + $this->assertContains('class ClassName extends \DateTime', $classGenerator->generate()); + + $classGenerator = new ClassGenerator(); + $classGenerator->setName('ClassName'); + $classGenerator->setExtendedClass('\DateTime'); + $this->assertContains('class ClassName extends DateTime', $classGenerator->generate()); } public function testCorrectImplementNames() From 5eec1af2fdc22c8b49e0a544135f16ae4600ecd3 Mon Sep 17 00:00:00 2001 From: qRoC Date: Tue, 28 Jun 2016 21:38:16 +0300 Subject: [PATCH 4/4] testCorrectExtendNamesFromGlobalNamespace --- test/Generator/ClassGeneratorTest.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/Generator/ClassGeneratorTest.php b/test/Generator/ClassGeneratorTest.php index 013d177d..c2c63cd0 100644 --- a/test/Generator/ClassGeneratorTest.php +++ b/test/Generator/ClassGeneratorTest.php @@ -1105,7 +1105,13 @@ public function testCorrectExtendNames() $classGenerator->setName('ClassName'); $classGenerator->setExtendedClass('DateTime'); $this->assertContains('class ClassName extends DateTime', $classGenerator->generate()); + } + /** + * @group 75 + */ + public function testCorrectExtendNamesFromGlobalNamespace() + { $classGenerator = new ClassGenerator(); $classGenerator->setName('ClassName'); $classGenerator->setNamespaceName('SomeNamespace');