Skip to content

Commit 480783e

Browse files
committed
bug #139 Fix expected variable type (IndraGunawan)
This PR was merged into the 1.0-dev branch. Discussion ---------- Fix expected variable type error when run `doctrine:schema:update --dump-sql` after creating entity using maker-bundle because of the attribute type error. for example when generate field with length 100 the annotation will be generate like this `@ORM\Column(type="string", length="100", nullable=true)` and when run the schema update command will throw exception ``` In AnnotationException.php line 83: [Type Error] Attribute "length" of @Orm\Column declared on property App\Entity\Entity::$field expects a(n) integer, but got string. ``` and it is also affect for `precision` and `scale` Commits ------- 7f16f06 Fix expected variable type
2 parents 60df153 + 7f16f06 commit 480783e

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

phpunit.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@
1919
<exclude>tests/tmp</exclude>
2020
</testsuite>
2121
</testsuites>
22+
23+
<filter>
24+
<whitelist>
25+
<directory>./src/</directory>
26+
</whitelist>
27+
</filter>
2228
</phpunit>

src/Validator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static function validateLength($length)
6262
throw new RuntimeCommandException(sprintf('Invalid length "%s".', $length));
6363
}
6464

65-
return $length;
65+
return $result;
6666
}
6767

6868
public static function validatePrecision($precision)
@@ -79,7 +79,7 @@ public static function validatePrecision($precision)
7979
throw new RuntimeCommandException(sprintf('Invalid precision "%s".', $precision));
8080
}
8181

82-
return $precision;
82+
return $result;
8383
}
8484

8585
public static function validateScale($scale)
@@ -96,7 +96,7 @@ public static function validateScale($scale)
9696
throw new RuntimeCommandException(sprintf('Invalid scale "%s".', $scale));
9797
}
9898

99-
return $scale;
99+
return $result;
100100
}
101101

102102
public static function validateBoolean($value)

tests/ValidatorTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Symfony\Bundle\MakerBundle\Tests;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Bundle\MakerBundle\Validator;
7+
use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException;
8+
9+
class ValidatorTest extends TestCase
10+
{
11+
public function testValidateLength()
12+
{
13+
$this->assertSame(100, Validator::validateLength('100'));
14+
$this->assertSame(99, Validator::validateLength(99));
15+
}
16+
17+
public function testInvalidLength()
18+
{
19+
$this->expectException(RuntimeCommandException::class);
20+
$this->expectExceptionMessage('Invalid length "-100".');
21+
22+
Validator::validateLength(-100);
23+
}
24+
25+
public function testValidatePrecision()
26+
{
27+
$this->assertSame(15, Validator::validatePrecision('15'));
28+
$this->assertSame(21, Validator::validatePrecision(21));
29+
}
30+
31+
public function testInvalidPrecision()
32+
{
33+
$this->expectException(RuntimeCommandException::class);
34+
$this->expectExceptionMessage('Invalid precision "66".');
35+
36+
Validator::validatePrecision(66);
37+
}
38+
39+
public function testValidateScale()
40+
{
41+
$this->assertSame(2, Validator::validateScale('2'));
42+
$this->assertSame(5, Validator::validateScale(5));
43+
}
44+
45+
public function testInvalidScale()
46+
{
47+
$this->expectException(RuntimeCommandException::class);
48+
$this->expectExceptionMessage('Invalid scale "31".');
49+
50+
Validator::validateScale(31);
51+
}
52+
}

0 commit comments

Comments
 (0)