Fix: some isVersionningNecessary() calls can cause fatal errors #314

Merged
merged 1 commit into from Mar 14, 2012
@@ -184,7 +184,7 @@ public function isVersioningNecessary(\$con = null)
foreach ($this->behavior->getVersionableFks() as $fk) {
$fkGetter = $this->builder->getFKPhpNameAffix($fk, $plural = false);
$script .= "
- if (\$this->get{$fkGetter}(\$con)->isVersioningNecessary(\$con)) {
+ if (null !== (\$object = \$this->get{$fkGetter}(\$con)) && \$object->isVersioningNecessary(\$con)) {
return true;
}
";
@@ -505,6 +505,19 @@ public function testIsVersioningNecessary()
$this->assertFalse($a->isVersioningNecessary());
}
+ public function testIsVersioningNecessaryWithNullFk()
+ {
+ // the purpose of this tests is to highlight a bug with FK and isVersioningNecessary()
+ $b1 = new VersionableBehaviorTest5();
+ $b1->setNew(false);
+
+ // this time, the object isn't modified, so the isVersioningNecessary()
+ // method is called on FK objects... which can be null.
+ $b1->isVersioningNecessary();
+
+ $this->assertTrue(true, 'getting here means that nothing went wrong');
+ }
+
public function testAddVersionNewObject()
{
VersionableBehaviorTest1Peer::disableVersioning();