Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request #4 from vincentchalamon/master
Browse files Browse the repository at this point in the history
Update aliases process & transformer detection
  • Loading branch information
vincentchalamon authored Aug 18, 2017
2 parents 137084a + c64ce60 commit 451780c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
6 changes: 2 additions & 4 deletions DependencyInjection/MigrationCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ public function process(ContainerBuilder $container)
foreach ($container->findTaggedServiceIds($this->tag) as $id => $attributes) {
$class = $container->getDefinition($id)->getClass();
$reflection = new \ReflectionClass($class);
$aliases = [
$class,
Inflector::tableize(preg_replace('/^(.*)Loader$/i', '$1', $reflection->getShortName())),
];
$alias = Inflector::tableize(preg_replace('/^(.*)Loader$/i', '$1', $reflection->getShortName()));
$aliases = [$class, $alias, str_replace('_', '-', $alias)];
if (true === $this->allowAlias && isset($attributes[0]['alias'])) {
$aliases[] = $attributes[0]['alias'];
}
Expand Down
2 changes: 1 addition & 1 deletion EventListener/TransformerEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private function process()
*/
private function hasTransformer($object)
{
return null !== $this->getTransformerAnnotation($object);
return null !== $this->getTransformerAnnotation($object) && $this->transformerLocator->has($this->getTransformerAnnotation($object)->transformer);
}

/**
Expand Down
12 changes: 8 additions & 4 deletions tests/EventListener/TransformerEventListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public function testPrePersist()
$this->eventMock->getObject()->willReturn($this->objectMock)->shouldBeCalledTimes(1);
$this->readerMock->getClassAnnotation(Argument::type('\ReflectionClass'), Transformer::class)
->willReturn($this->annotationMock)
->shouldBeCalledTimes(1);
->shouldBeCalledTimes(2);
$this->locatorMock->has(Argument::any())->willReturn(true)->shouldBeCalledTimes(1);

$this->eventListener->prePersist($this->eventMock->reveal());
$this->assertEquals([
Expand All @@ -131,7 +132,8 @@ public function testPreUpdate()
$this->eventMock->getObject()->willReturn($this->objectMock)->shouldBeCalledTimes(1);
$this->readerMock->getClassAnnotation(Argument::type('\ReflectionClass'), Transformer::class)
->willReturn($this->annotationMock)
->shouldBeCalledTimes(1);
->shouldBeCalledTimes(2);
$this->locatorMock->has(Argument::any())->willReturn(true)->shouldBeCalledTimes(1);

$this->eventListener->preUpdate($this->eventMock->reveal());
$this->assertEquals([
Expand All @@ -146,7 +148,8 @@ public function testPreRemove()
$this->eventMock->getObject()->willReturn($this->objectMock)->shouldBeCalledTimes(1);
$this->readerMock->getClassAnnotation(Argument::type('\ReflectionClass'), Transformer::class)
->willReturn($this->annotationMock)
->shouldBeCalledTimes(1);
->shouldBeCalledTimes(2);
$this->locatorMock->has(Argument::any())->willReturn(true)->shouldBeCalledTimes(1);

$this->eventListener->preRemove($this->eventMock->reveal());
$this->assertEquals([
Expand All @@ -168,7 +171,8 @@ public function testPostFlush()
$this->eventMock->getObject()->willReturn($this->objectMock)->shouldBeCalledTimes(6);
$this->readerMock->getClassAnnotation(Argument::type('\ReflectionClass'), Transformer::class)
->willReturn($this->annotationMock)
->shouldBeCalledTimes(6);
->shouldBeCalledTimes(9);
$this->locatorMock->has(Argument::any())->willReturn(true)->shouldBeCalledTimes(3);
$this->locatorMock->get(Argument::any())->willReturn($this->transformerMock)->shouldBeCalledTimes(3);

$this->eventListener->prePersist($this->eventMock->reveal());
Expand Down

0 comments on commit 451780c

Please sign in to comment.