Skip to content

Merge release 0.8.4 into 0.9.x #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
9 changes: 7 additions & 2 deletions src/Code/ValueGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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:
Expand All @@ -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))
Expand Down
50 changes: 50 additions & 0 deletions tests/Code/ValueGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* @see https://github.com/open-code-modeling/php-code-ast for the canonical source repository
* @copyright https://github.com/open-code-modeling/php-code-ast/blob/master/COPYRIGHT.md
* @license https://github.com/open-code-modeling/php-code-ast/blob/master/LICENSE.md MIT License
*/

declare(strict_types=1);

namespace OpenCodeModelingTest\CodeAst\Code;

use Generator;
use OpenCodeModeling\CodeAst\Code\ValueGenerator;
use PhpParser\Node;
use PHPUnit\Framework\TestCase;

final class ValueGeneratorTest extends TestCase
{
/**
* Values are: type, expected output
*
* @return Generator
*/
public function provideTypes(): Generator
{
yield 'null' => [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());
}
}