diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 77f8a41..61d70ef 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -20,10 +20,10 @@ jobs: continue-on-error: ${{ matrix.experimental }} steps: - name: "Checkout" - uses: "actions/checkout@v2.3.1" + uses: actions/checkout@v2 - name: "Install PHP" - uses: "shivammathur/setup-php@2.4.1" + uses: shivammathur/setup-php@v2 with: php-version: "${{ matrix.php-version }}" coverage: xdebug diff --git a/CHANGELOG.md b/CHANGELOG.md index 85a3af4..e55c183 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,6 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. - ## 0.9.0 - TBD ### Added @@ -25,6 +24,26 @@ All notable changes to this project will be documented in this file, in reverse - Nothing. +## 0.8.4 - 2020-11-20 + + +----- + +### Release Notes for [0.8.4](https://github.com/open-code-modeling/php-code-ast/milestone/14) + +0.8.x bugfix release (patch) + +### 0.8.4 + +- Total issues resolved: **1** +- Total pull requests resolved: **0** +- Total contributors: **1** + +#### bug + + - [36: Boolean, float and double values not working properly in Code\ValueGenerator](https://github.com/open-code-modeling/php-code-ast/issues/36) thanks to @sandrokeil + + ## 0.8.3 - 2020-11-13 diff --git a/src/Code/ValueGenerator.php b/src/Code/ValueGenerator.php index 48be24e..9749912 100644 --- a/src/Code/ValueGenerator.php +++ b/src/Code/ValueGenerator.php @@ -153,7 +153,9 @@ public function getAutoDeterminedType($value): string case 'string': return self::TYPE_STRING; case 'double': + return self::TYPE_DOUBLE; case 'float': + return self::TYPE_FLOAT; case 'integer': return self::TYPE_NUMBER; case 'array': @@ -184,7 +186,7 @@ public function generate(): Node\Expr return new Node\Expr\ConstFetch(new Node\Name('null')); case self::TYPE_BOOLEAN: case self::TYPE_BOOL: - return new Node\Expr\ConstFetch(new Node\Name($this->value)); + return new Node\Expr\ConstFetch(new Node\Name($this->value ? 'true' : 'false')); case self::TYPE_STRING: return new Node\Scalar\String_($this->value); case self::TYPE_NUMBER: @@ -210,8 +212,11 @@ public function generate(): Node\Expr $arrayItems, ['kind' => Node\Expr\Array_::KIND_SHORT] ); - break; case self::TYPE_OTHER: + if ($this->value instanceof Node\Expr) { + return $this->value; + } + // no break default: throw new Exception\RuntimeException( \sprintf('Type "%s" is unknown or cannot be used as property default value.', \get_class($value)) diff --git a/tests/Code/ValueGeneratorTest.php b/tests/Code/ValueGeneratorTest.php new file mode 100644 index 0000000..ce26e3e --- /dev/null +++ b/tests/Code/ValueGeneratorTest.php @@ -0,0 +1,50 @@ + [null, Node\Expr\ConstFetch::class]; + yield 'string' => ['test string', Node\Scalar\String_::class]; + yield 'bool' => [true, Node\Expr\ConstFetch::class]; + yield 'int' => [1, Node\Scalar\LNumber::class]; + yield 'integer' => [10, Node\Scalar\LNumber::class]; + yield 'float' => [2.523, Node\Scalar\DNumber::class]; + yield 'double' => [7E-10, Node\Scalar\DNumber::class]; + yield 'array' => [['one', 'two'], Node\Expr\Array_::class]; + yield 'other node expression' => [new Node\Expr\Array_(), Node\Expr\Array_::class]; + } + + /** + * @test + * @dataProvider provideTypes + * @param mixed $value + * @param string $expectedGeneratedValue + */ + public function it_supports_type($value, string $expectedGeneratedValue): void + { + $value = new ValueGenerator($value); + + $this->assertInstanceOf($expectedGeneratedValue, $value->generate()); + } +}