Skip to content

Commit 205a608

Browse files
authored
Merge pull request #37 from open-code-modeling/0.8.x-merge-up-into-0.9.x_5fb78d3d0e97e1.87635354
Merge release 0.8.4 into 0.9.x
2 parents 03c927c + 96c29a6 commit 205a608

File tree

4 files changed

+79
-5
lines changed

4 files changed

+79
-5
lines changed

.github/workflows/integration.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ jobs:
2020
continue-on-error: ${{ matrix.experimental }}
2121
steps:
2222
- name: "Checkout"
23-
uses: "actions/checkout@v2.3.1"
23+
uses: actions/checkout@v2
2424

2525
- name: "Install PHP"
26-
uses: "shivammathur/setup-php@2.4.1"
26+
uses: shivammathur/setup-php@v2
2727
with:
2828
php-version: "${{ matrix.php-version }}"
2929
coverage: xdebug

CHANGELOG.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
65
## 0.9.0 - TBD
76

87
### Added
@@ -25,6 +24,26 @@ All notable changes to this project will be documented in this file, in reverse
2524

2625
- Nothing.
2726

27+
## 0.8.4 - 2020-11-20
28+
29+
30+
-----
31+
32+
### Release Notes for [0.8.4](https://github.com/open-code-modeling/php-code-ast/milestone/14)
33+
34+
0.8.x bugfix release (patch)
35+
36+
### 0.8.4
37+
38+
- Total issues resolved: **1**
39+
- Total pull requests resolved: **0**
40+
- Total contributors: **1**
41+
42+
#### bug
43+
44+
- [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
45+
46+
2847
## 0.8.3 - 2020-11-13
2948

3049

src/Code/ValueGenerator.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ public function getAutoDeterminedType($value): string
153153
case 'string':
154154
return self::TYPE_STRING;
155155
case 'double':
156+
return self::TYPE_DOUBLE;
156157
case 'float':
158+
return self::TYPE_FLOAT;
157159
case 'integer':
158160
return self::TYPE_NUMBER;
159161
case 'array':
@@ -184,7 +186,7 @@ public function generate(): Node\Expr
184186
return new Node\Expr\ConstFetch(new Node\Name('null'));
185187
case self::TYPE_BOOLEAN:
186188
case self::TYPE_BOOL:
187-
return new Node\Expr\ConstFetch(new Node\Name($this->value));
189+
return new Node\Expr\ConstFetch(new Node\Name($this->value ? 'true' : 'false'));
188190
case self::TYPE_STRING:
189191
return new Node\Scalar\String_($this->value);
190192
case self::TYPE_NUMBER:
@@ -210,8 +212,11 @@ public function generate(): Node\Expr
210212
$arrayItems,
211213
['kind' => Node\Expr\Array_::KIND_SHORT]
212214
);
213-
break;
214215
case self::TYPE_OTHER:
216+
if ($this->value instanceof Node\Expr) {
217+
return $this->value;
218+
}
219+
// no break
215220
default:
216221
throw new Exception\RuntimeException(
217222
\sprintf('Type "%s" is unknown or cannot be used as property default value.', \get_class($value))

tests/Code/ValueGeneratorTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
/**
4+
* @see https://github.com/open-code-modeling/php-code-ast for the canonical source repository
5+
* @copyright https://github.com/open-code-modeling/php-code-ast/blob/master/COPYRIGHT.md
6+
* @license https://github.com/open-code-modeling/php-code-ast/blob/master/LICENSE.md MIT License
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace OpenCodeModelingTest\CodeAst\Code;
12+
13+
use Generator;
14+
use OpenCodeModeling\CodeAst\Code\ValueGenerator;
15+
use PhpParser\Node;
16+
use PHPUnit\Framework\TestCase;
17+
18+
final class ValueGeneratorTest extends TestCase
19+
{
20+
/**
21+
* Values are: type, expected output
22+
*
23+
* @return Generator
24+
*/
25+
public function provideTypes(): Generator
26+
{
27+
yield 'null' => [null, Node\Expr\ConstFetch::class];
28+
yield 'string' => ['test string', Node\Scalar\String_::class];
29+
yield 'bool' => [true, Node\Expr\ConstFetch::class];
30+
yield 'int' => [1, Node\Scalar\LNumber::class];
31+
yield 'integer' => [10, Node\Scalar\LNumber::class];
32+
yield 'float' => [2.523, Node\Scalar\DNumber::class];
33+
yield 'double' => [7E-10, Node\Scalar\DNumber::class];
34+
yield 'array' => [['one', 'two'], Node\Expr\Array_::class];
35+
yield 'other node expression' => [new Node\Expr\Array_(), Node\Expr\Array_::class];
36+
}
37+
38+
/**
39+
* @test
40+
* @dataProvider provideTypes
41+
* @param mixed $value
42+
* @param string $expectedGeneratedValue
43+
*/
44+
public function it_supports_type($value, string $expectedGeneratedValue): void
45+
{
46+
$value = new ValueGenerator($value);
47+
48+
$this->assertInstanceOf($expectedGeneratedValue, $value->generate());
49+
}
50+
}

0 commit comments

Comments
 (0)