Skip to content

Commit

Permalink
Merge pull request #23 from nutama/issue_no_event_on_initialized_proxies
Browse files Browse the repository at this point in the history
Fixed issue no event on initialized proxies
  • Loading branch information
linaori committed Sep 24, 2015
2 parents c70af2e + 82a930c commit 1bc501a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Listener/EntityChangedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public function preFlush(PreFlushEventArgs $event)
}

foreach ($updates as $entity) {
if (!$this->meta_mutation_provider->isEntityManaged($em, $entity) || $entity instanceof Proxy) {
if (!$this->meta_mutation_provider->isEntityManaged($em, $entity)
|| ($entity instanceof Proxy && !$entity->__isInitialized())
) {
continue;
}

Expand Down
46 changes: 46 additions & 0 deletions test/Listener/EntityChangedListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,52 @@ public function testPreFlushWithProxy()
$this->listener->preFlush(new PreFlushEventArgs($this->em));
}

public function testPreFlushWithInitializedProxy()
{
$original = new \stdClass();
$original->id = 0;

$entity = $this->getMock('Doctrine\ORM\Proxy\Proxy');
$entity
->expects($this->once())
->method('__isInitialized')
->willReturn(true);

$this->meta_mutation_provider
->expects($this->once())
->method('getFullChangeSet')
->willReturn($this->genericEntityDataProvider($entity));

$this->meta_annotation_provider
->expects($this->once())
->method('isTracked')
->willReturn(true);

$this->logger->expects($this->once())->method('info');

$this->meta_mutation_provider
->expects($this->once())
->method('isEntityManaged')
->willReturn(true);

$this->meta_mutation_provider
->expects($this->once())
->method('createOriginalEntity')
->willReturn($original);

$this->meta_mutation_provider
->expects($this->once())
->method('getMutatedFields')
->willReturn(['id']);

$this->event_manager
->expects($this->once())
->method('dispatchEvent')
->with('entityChanged', $this->isInstanceof('Hostnet\Component\EntityTracker\Event\EntityChangedEvent'));

$this->listener->preFlush(new PreFlushEventArgs($this->em));
}

/**
* @param mixed $entity
* @return array[]
Expand Down

0 comments on commit 1bc501a

Please sign in to comment.