Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #768 from rvitaliy/fix-typehinting

fixed type-hinting in addDefaultMutator and added tests for it
  • Loading branch information...
commit 93f9fc84d1ee631f7b4d92bf3bdba4da82fef015 2 parents 15384ff + 7b073a2
William Durand willdurand authored
10 generator/lib/builder/om/PHP5ObjectBuilder.php
View
@@ -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;
}
";
42 test/testsuite/generator/builder/om/GeneratedObjectTest.php
View
@@ -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.
Please sign in to comment.
Something went wrong with that request. Please try again.