From 94c48c33d4b7742549a4ef4ae5e4e9729bbb9922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julio=20Cesar=20Laura=20Avenda=C3=B1o?= Date: Fri, 3 Jan 2020 08:34:28 -0400 Subject: [PATCH] PMC-1341 --- .../database/model/PhpNameGeneratorTest.php | 120 ++++++++++++++++++ .../database/model/PhpNameGenerator.php | 4 +- 2 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 tests/unit/thirdparty/propel-generator/classes/propel/engine/database/model/PhpNameGeneratorTest.php diff --git a/tests/unit/thirdparty/propel-generator/classes/propel/engine/database/model/PhpNameGeneratorTest.php b/tests/unit/thirdparty/propel-generator/classes/propel/engine/database/model/PhpNameGeneratorTest.php new file mode 100644 index 000000000..caf8634ff --- /dev/null +++ b/tests/unit/thirdparty/propel-generator/classes/propel/engine/database/model/PhpNameGeneratorTest.php @@ -0,0 +1,120 @@ +phpNameGenerator = new PhpNameGenerator(); + } + + /** + * Test "underscoreMethod" using texts with and without underscores + * + * @test + * @covers PhpNameGenerator::underscoreMethod() + */ + public function it_should_test_underscore_method_through_generate_name() + { + // To force to use the protected method "underscoreMethod" + $method = PhpNameGenerator::CONV_METHOD_UNDERSCORE; + + // Assert for bug PMC-1341 + $string = 'q_10_0_0'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('Q1000', $convertedString); + + // Assert for a text in lowercase without underscores + $string = 'example'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('Example', $convertedString); + + // Assert for a text in uppercase without underscores + $string = 'EXAMPLE'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('Example', $convertedString); + + // Assert for a capitalized text without underscores, should be return the same value + $string = 'Example'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals($string, $convertedString); + + // Assert for a text in lowercase with underscore + $string = 'first_name'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('FirstName', $convertedString); + + // Assert for a text in lowercase with underscores + $string = 'this_is_my_text'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('ThisIsMyText', $convertedString); + + // Assert for a mixed text with underscores + $string = 'this_Is_the_Number_1_to_check'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('ThisIsTheNumber1ToCheck', $convertedString); + } + + /** + * Test "phpnameMethod" using texts with and without underscores + * + * @test + * @covers PhpNameGenerator::phpnameMethod() + */ + public function it_should_test_php_name_method_through_generate_name() + { + // To force to use the protected method "underscoreMethod" + $method = PhpNameGenerator::CONV_METHOD_UNDERSCORE; + + // Assert for bug PMC-1341 + $string = 'q_10_0_0'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('Q1000', $convertedString); + + // Assert for a text in lowercase without underscores + $string = 'example'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('Example', $convertedString); + + // Assert for a text in uppercase without underscores + $string = 'EXAMPLE'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('Example', $convertedString); + + // Assert for a capitalized text without underscores, should be return the same value + $string = 'Example'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals($string, $convertedString); + + // Assert for a text in lowercase with underscore + $string = 'first_name'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('FirstName', $convertedString); + + // Assert for a text in lowercase with underscores + $string = 'this_is_my_text'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('ThisIsMyText', $convertedString); + + // Assert for a mixed text with underscores + $string = 'this_Is_the_Number_1_to_check'; + $convertedString = $this->phpNameGenerator->generateName([$string, $method]); + $this->assertEquals('ThisIsTheNumber1ToCheck', $convertedString); + } +} diff --git a/thirdparty/propel-generator/classes/propel/engine/database/model/PhpNameGenerator.php b/thirdparty/propel-generator/classes/propel/engine/database/model/PhpNameGenerator.php index a45595e6e..626f64edc 100644 --- a/thirdparty/propel-generator/classes/propel/engine/database/model/PhpNameGenerator.php +++ b/thirdparty/propel-generator/classes/propel/engine/database/model/PhpNameGenerator.php @@ -87,7 +87,7 @@ class PhpNameGenerator implements NameGenerator { { $name = ""; $tok = strtok($schemaName, self::STD_SEPARATOR_CHAR); - while($tok) { + while($tok !== false) { $name .= ucfirst(strtolower($tok)); $tok = strtok(self::STD_SEPARATOR_CHAR); } @@ -110,7 +110,7 @@ class PhpNameGenerator implements NameGenerator { { $name = ""; $tok = strtok($schemaName, self::STD_SEPARATOR_CHAR); - while($tok) { + while($tok !== false) { $name .= ucfirst($tok); $tok = strtok(self::STD_SEPARATOR_CHAR); }