File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -58,9 +58,9 @@ class EntityToIdentifierTransformer implements DataTransformerInterface
58
58
public function __construct (ObjectManager $ entityManager , $ className )
59
59
{
60
60
$ this ->entityManager = $ entityManager ;
61
- $ this ->className = $ className ;
62
- $ this ->repository = $ this ->entityManager ->getRepository ( $ this -> className );
63
- $ this ->metadata = $ this ->entityManager -> getClassMetadata ( $ this -> className );
61
+ $ this ->repository = $ this -> entityManager -> getRepository ( $ className) ;
62
+ $ this ->metadata = $ this ->entityManager ->getClassMetadata ( $ className );
63
+ $ this ->className = $ this ->metadata -> getName ( );
64
64
65
65
if ($ this ->metadata ->isIdentifierComposite ) {
66
66
throw new InvalidArgumentException ('Expected an entity with a single identifier. ' );
@@ -86,9 +86,9 @@ public function transform($value)
86
86
throw new TransformationFailedException ('Expected an object. ' );
87
87
}
88
88
89
- $ class = ClassUtils::getClass ($ value );
89
+ $ className = ClassUtils::getClass ($ value );
90
90
91
- if ($ class !== $ this ->className ) {
91
+ if ($ className !== $ this ->className ) {
92
92
throw new TransformationFailedException (sprintf ('Expected entity %s. ' , $ this ->className ));
93
93
}
94
94
Original file line number Diff line number Diff line change @@ -61,6 +61,7 @@ protected function setUp()
61
61
$ this ->entityManager ->method ('getRepository ' )->willReturn ($ this ->repository );
62
62
$ this ->entityManager ->method ('getClassMetadata ' )->willReturn ($ this ->metadata );
63
63
64
+ $ this ->metadata ->method ('getName ' )->willReturn ($ this ->className );
64
65
$ this ->metadata ->method ('getIdentifierValues ' )->willReturn (array ('id ' => $ this ->identifier ));
65
66
66
67
$ this ->metadata ->isIdentifierComposite = false ;
@@ -86,6 +87,15 @@ public function testTransform()
86
87
$ this ->assertSame ($ this ->identifier , $ identifier );
87
88
}
88
89
90
+ public function testTransformAlias ()
91
+ {
92
+ $ transformer = new EntityToIdentifierTransformer ($ this ->entityManager , 'AppBundle:City ' );
93
+
94
+ $ identifier = $ transformer ->transform ($ this ->entity );
95
+
96
+ $ this ->assertSame ($ this ->identifier , $ identifier );
97
+ }
98
+
89
99
public function testTransformNull ()
90
100
{
91
101
$ transformer = new EntityToIdentifierTransformer ($ this ->entityManager , $ this ->className );
You can’t perform that action at this time.
0 commit comments