Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

fixed type-hinting in addDefaultMutator and added tests for it #768

Merged
merged 2 commits into from

3 participants

@rvitaliy

No description provided.

...estsuite/generator/builder/om/GeneratedObjectTest.php
((32 lines not shown))
+ $this->assertTrue(is_string($a->getFirstName()));
+
+
+ $a->clear();
+ $a->setFirstName($a2);
+ $this->assertTrue(is_string($a->getFirstName()));
+ $this->assertEquals($a->getFirstName(), (string)$a2);
+
+
+ $a->clear();
+ $a->setFirstName(true);
+ $this->assertTrue(is_string($a->getFirstName()));
+
+
+ /* php 5.4+ fail generate Notice: Array to string conversion
+ $a->clear();
@willdurand Owner

uh oh?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
generator/lib/builder/om/PHP5ObjectBuilder.php
@@ -1987,7 +1987,7 @@ protected function addDefaultMutator(&$script, Column $col)
// checking in mutators.
if ($col->isPhpPrimitiveType()) {
$script .= "
- if (\$v !== null && is_numeric(\$v)) {

the removal of is_numeric($v) will lead to another issue as described here #283

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@willdurand willdurand merged commit 93f9fc8 into propelorm:master

1 check passed

Details default The Travis CI build passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
10 generator/lib/builder/om/PHP5ObjectBuilder.php
@@ -1986,8 +1986,16 @@ protected function addDefaultMutator(&$script, Column $col)
// Perform type-casting to ensure that we can use type-sensitive
// checking in mutators.
if ($col->isPhpPrimitiveType()) {
+ if($col->isTextType()) {
+ $script .= "
+ if (\$v !== null) {";
+ } else {
+ $script .= "
+ if (\$v !== null && is_numeric(\$v)) {";
+ }
+
+
$script .= "
- if (\$v !== null && is_numeric(\$v)) {
\$v = (" . $col->getPhpType() . ") \$v;
}
";
View
42 test/testsuite/generator/builder/om/GeneratedObjectTest.php
@@ -100,6 +100,48 @@ public function testDefaultValues()
$acct->setPassword("testpass");
$this->assertTrue($acct->isModified());
}
+
+
+ public function testTypeHintingValues()
+ {
+ $test_name = 'test name';
+ $a = new Author();
+ $a2 = new Author();
+ $a2->setFirstName($test_name);
+
+
+ $a->setAge(2);
+ $this->assertEquals(2, $a->getAge());
+ $this->assertTrue(is_int($a->getAge()));
+
+
+ $a->clear();
+ $a->setAge('2');
+ $this->assertEquals(2, $a->getAge());
+ $this->assertTrue(is_int($a->getAge()));
+
+
+ $a->clear();
+ $a->setAge('wrong integer');
+ $this->assertTrue(!is_int($a->getAge()));
+
+
+ $a->clear();
+ $a->setFirstName($test_name);
+ $this->assertEquals($test_name, $a->getFirstName());
+ $this->assertTrue(is_string($a->getFirstName()));
+
+
+ $a->clear();
+ $a->setFirstName($a2);
+ $this->assertTrue(is_string($a->getFirstName()));
+ $this->assertEquals($a->getFirstName(), (string)$a2);
+
+
+ $a->clear();
+ $a->setFirstName(true);
+ $this->assertTrue(is_string($a->getFirstName()));
+ }
/**
* Tests the use of default expressions and the reloadOnInsert and reloadOnUpdate attributes.
Something went wrong with that request. Please try again.