Skip to content

Commit

Permalink
Merge pull request lphuberdeau#56 from bizantom/master
Browse files Browse the repository at this point in the history
Issue lphuberdeau#54 : PHP Catchable fatal error.
  • Loading branch information
lphuberdeau committed Jan 27, 2014
2 parents 9fbc9e9 + e9cef1d commit 5314396
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/HireVoice/Neo4j/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,23 @@ private function removeEntities()
if ($id){
$node = $this->client->getNode($id);

$class = $meta->getName();
$index = $this->getRepository($class)->getIndex();
$index->remove($node);
if($node){
$class = $meta->getName();
$index = $this->getRepository($class)->getIndex();
$index->remove($node);

$relationships = $node->getRelationships();
foreach ($relationships as $relationship){
$relationship->delete();
}

$relationships = $node->getRelationships();
foreach ($relationships as $relationship){
$relationship->delete();
$node->delete();
}

$node->delete();
}
}

$this->entitiesToRemove = Array();

$this->commit();
}

Expand Down
27 changes: 27 additions & 0 deletions lib/HireVoice/Neo4j/Tests/EntityManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,33 @@ function testStoreLabeledEntity()
$this->assertEquals("Location", $city->offsetGet(0));
$this->assertEquals("City", $city->offsetGet(1));
}

/**
* Check the fix of issue #54.
*/
function testRemoveEntity()
{
$entity = new Entity\Movie;
$entity->setTitle('Jules et Jim');

$em = $this->getEntityManager();
$em->persist($entity);
$em->flush();

$em->remove($entity);
$em->flush();

$entity2 = new Entity\Movie;
$entity2->setTitle('Rois et reine');
$em->persist($entity2);
$em->flush();

// one only checks that a second flush
// after a remove does not throw an exception
// if not the test is ok.

$this->assertTrue(true);
}
}

/**
Expand Down

0 comments on commit 5314396

Please sign in to comment.