From 725266f1ae3179fac59df507e86d722b0674e0ef Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 18 Nov 2020 22:40:00 +0100 Subject: [PATCH 1/3] Add new test. Signed-off-by: Pol Dellaiera --- test/Generator/ValueGeneratorTest.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/Generator/ValueGeneratorTest.php b/test/Generator/ValueGeneratorTest.php index c123c431..1fdda733 100644 --- a/test/Generator/ValueGeneratorTest.php +++ b/test/Generator/ValueGeneratorTest.php @@ -373,6 +373,25 @@ public function testPropertyDefaultValueCanHandleStrings() self::assertEquals("'foo'", $valueGenerator->generate()); } + public function testPropertyDefaultValueCanHandleBool() + { + $valueGenerator1 = new ValueGenerator( + 'FALSE', + ValueGenerator::TYPE_AUTO, + ValueGenerator::OUTPUT_MULTIPLE_LINE, + new \ArrayObject(get_defined_constants()) + ); + + $valueGenerator2 = new ValueGenerator( + 'FALSE', + ValueGenerator::TYPE_STRING, + ValueGenerator::OUTPUT_MULTIPLE_LINE, + new \ArrayObject(get_defined_constants()) + ); + + self::assertNotEquals($valueGenerator1->generate(), $valueGenerator2->generate()); + } + /** * @dataProvider simpleArray * From 779d93c8f6601a82c02ce9593e111664923d4ee9 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Wed, 18 Nov 2020 22:40:12 +0100 Subject: [PATCH 2/3] Fix issue. Signed-off-by: Pol Dellaiera --- src/Generator/ValueGenerator.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Generator/ValueGenerator.php b/src/Generator/ValueGenerator.php index 6e61ae6d..4c94c8fb 100644 --- a/src/Generator/ValueGenerator.php +++ b/src/Generator/ValueGenerator.php @@ -306,6 +306,10 @@ public function getAutoDeterminedType($value) case 'boolean': return self::TYPE_BOOLEAN; case 'string': + if (defined($value) === true) { + return self::TYPE_CONSTANT; + } + foreach ($this->constants as $constant) { if (strpos($value, $constant) !== false) { return self::TYPE_CONSTANT; From 9a4a1682132211f2c5f1349a6e7d2cf6aad46a08 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Thu, 19 Nov 2020 09:53:41 +0100 Subject: [PATCH 3/3] Improvements. Signed-off-by: Pol Dellaiera --- src/Generator/ValueGenerator.php | 8 ++++---- test/Generator/ValueGeneratorTest.php | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Generator/ValueGenerator.php b/src/Generator/ValueGenerator.php index 4c94c8fb..cac702bc 100644 --- a/src/Generator/ValueGenerator.php +++ b/src/Generator/ValueGenerator.php @@ -306,11 +306,11 @@ public function getAutoDeterminedType($value) case 'boolean': return self::TYPE_BOOLEAN; case 'string': - if (defined($value) === true) { - return self::TYPE_CONSTANT; - } - foreach ($this->constants as $constant) { + if ($value === $constant) { + return self::TYPE_CONSTANT; + } + if (strpos($value, $constant) !== false) { return self::TYPE_CONSTANT; } diff --git a/test/Generator/ValueGeneratorTest.php b/test/Generator/ValueGeneratorTest.php index 1fdda733..01ec9402 100644 --- a/test/Generator/ValueGeneratorTest.php +++ b/test/Generator/ValueGeneratorTest.php @@ -378,17 +378,18 @@ public function testPropertyDefaultValueCanHandleBool() $valueGenerator1 = new ValueGenerator( 'FALSE', ValueGenerator::TYPE_AUTO, - ValueGenerator::OUTPUT_MULTIPLE_LINE, - new \ArrayObject(get_defined_constants()) + ValueGenerator::OUTPUT_MULTIPLE_LINE ); $valueGenerator2 = new ValueGenerator( 'FALSE', ValueGenerator::TYPE_STRING, - ValueGenerator::OUTPUT_MULTIPLE_LINE, - new \ArrayObject(get_defined_constants()) + ValueGenerator::OUTPUT_MULTIPLE_LINE ); + $valueGenerator1->initEnvironmentConstants(); + $valueGenerator2->initEnvironmentConstants(); + self::assertNotEquals($valueGenerator1->generate(), $valueGenerator2->generate()); }