Skip to content

Commit

Permalink
Fix #17 Symfony 4 incompatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ronisaha committed Jan 31, 2018
1 parent 23df4ea commit 7777618
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions Resources/config/doctrine_services.yml
Expand Up @@ -5,5 +5,6 @@ services:
arguments: ['%xiidea.easy_audit.doctrine_entities%']
calls:
- [ setContainer,[ '@service_container' ] ]
- [ setAnnotationReader,[ '@annotation_reader' ] ]
tags:
- { name: doctrine.event_subscriber }
16 changes: 14 additions & 2 deletions Subscriber/DoctrineSubscriber.php
Expand Up @@ -21,6 +21,10 @@
class DoctrineSubscriber implements ContainerAwareInterface, EventSubscriber
{
use ContainerAwareTrait;

/** @var \Doctrine\Common\Annotations\Reader */
private $annotationReader;

/**
* @var array
*/
Expand Down Expand Up @@ -124,11 +128,11 @@ protected function hasAnnotation($entity)
}

/**
* @return \Doctrine\Common\Annotations\FileCacheReader
* @return \Doctrine\Common\Annotations\Reader
*/
protected function getAnnotationReader()
{
return $this->container->get('annotation_reader');
return $this->annotationReader;
}

/**
Expand Down Expand Up @@ -169,4 +173,12 @@ protected function isConfigured($class)
{
return isset($this->entities[$class]);
}

/**
* @param \Doctrine\Common\Annotations\Reader $annotationReader
*/
public function setAnnotationReader($annotationReader = null)
{
$this->annotationReader = $annotationReader;
}
}
24 changes: 12 additions & 12 deletions Tests/Subscriber/DoctrineSubscriberTest.php
Expand Up @@ -23,9 +23,15 @@ class DoctrineSubscriberTest extends TestCase
/** @var \PHPUnit_Framework_MockObject_MockObject */
private $container;

/** @var \PHPUnit_Framework_MockObject_MockObject */
private $annotationReader;

public function setUp()
{
$this->container = $this->createMock('Symfony\Component\DependencyInjection\ContainerInterface');
$this->annotationReader = $this->getMockBuilder('\Doctrine\Common\Annotations\FileCacheReader')
->disableOriginalConstructor()
->getMock();
}

public function testInstanceOnSubscriber()
Expand Down Expand Up @@ -92,7 +98,7 @@ public function testCreateEventForEntityConfiguredToTrackAllEvents()

public function testUpdateEventForEntityNotConfiguredToTrack()
{
$this->initializeAnnotationReader(null);
$this->initializeAnnotationReader();
$subscriber = new DoctrineSubscriber(array());
$this->invokeUpdatedEventCall($subscriber);
}
Expand All @@ -106,25 +112,16 @@ public function testRemovedEventForEntityNotConfiguredToTrack()

private function initializeAnnotationReader($metaData = null)
{
$annotationReader = $this->getMockBuilder('\Doctrine\Common\Annotations\FileCacheReader')
->disableOriginalConstructor()
->getMock();

$annotationReader->expects($this->once())
$this->annotationReader->expects($this->once())
->method('getClassAnnotation')
->willReturn($metaData);

$this->container->expects($this->at(0))
->method('get')
->with($this->equalTo('annotation_reader'))
->willReturn($annotationReader);
}

private function initializeDispatcher()
{
$dispatcher = $this->createMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');

$this->container->expects($this->at(1))
$this->container->expects($this->once())
->method('get')
->with($this->equalTo('event_dispatcher'))
->willReturn($dispatcher);
Expand All @@ -136,6 +133,7 @@ private function initializeDispatcher()
private function invokeCreatedEventCall($subscriber)
{
$subscriber->setContainer($this->container);
$subscriber->setAnnotationReader($this->annotationReader);

$subscriber->postPersist(new LifecycleEventArgs(new Movie()));
}
Expand All @@ -146,6 +144,7 @@ private function invokeCreatedEventCall($subscriber)
private function invokeUpdatedEventCall($subscriber)
{
$subscriber->setContainer($this->container);
$subscriber->setAnnotationReader($this->annotationReader);

$subscriber->postUpdate(new LifecycleEventArgs(new Movie()));
}
Expand All @@ -156,6 +155,7 @@ private function invokeUpdatedEventCall($subscriber)
private function invokeDeletedEventCall($subscriber)
{
$subscriber->setContainer($this->container);
$subscriber->setAnnotationReader($this->annotationReader);

$subscriber->preRemove(new LifecycleEventArgs(new Movie()));
}
Expand Down

0 comments on commit 7777618

Please sign in to comment.