Permalink
Browse files

Merge pull request #314 from K-Phoen/fix-is-versionning-necessary-fk

Fix: some isVersionningNecessary() calls can cause fatal errors
  • Loading branch information...
2 parents 356947a + eb303e5 commit b7669e350eb0e1fc213d8844dd0b9a598be6bac3 @willdurand willdurand committed 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();

0 comments on commit b7669e3

Please sign in to comment.