29
29
use Doctrine \Common \Persistence \ObjectManager ;
30
30
use Doctrine \Common \Persistence \ObjectRepository ;
31
31
use PHPUnit \Framework \TestCase ;
32
+ use Symfony \Component \Form \Exception \InvalidArgumentException ;
33
+ use Symfony \Component \Form \Exception \TransformationFailedException ;
32
34
33
35
class EntityToIdentifierTransformerTest extends TestCase
34
36
{
@@ -50,7 +52,7 @@ class EntityToIdentifierTransformerTest extends TestCase
50
52
/** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata|\PHPUnit_Framework_MockObject_MockObject */
51
53
private $ metadata ;
52
54
53
- protected function setUp ()
55
+ protected function setUp (): void
54
56
{
55
57
$ this ->entity = new City ();
56
58
$ this ->entity ->setId (123 );
@@ -87,12 +89,11 @@ public function getIdentifier()
87
89
return ['id ' => $ this ->identifier ];
88
90
}
89
91
90
- /**
91
- * @expectedException \Symfony\Component\Form\Exception\InvalidArgumentException
92
- * @expectedExceptionMessage Expected an entity with a single identifier.
93
- */
94
92
public function testConstructIdentifierComposite ()
95
93
{
94
+ $ this ->expectException (InvalidArgumentException::class);
95
+ $ this ->expectExceptionMessage ('Expected an entity with a single identifier. ' );
96
+
96
97
$ this ->metadata ->isIdentifierComposite = true ;
97
98
98
99
new EntityToIdentifierTransformer ($ this ->entityManager , $ this ->className );
@@ -142,23 +143,22 @@ public function testTransformNull()
142
143
* @param mixed $value
143
144
*
144
145
* @dataProvider providerNoObject
145
- *
146
- * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
147
- * @expectedExceptionMessage Expected an object.
148
146
*/
149
147
public function testTransformNoObject ($ value )
150
148
{
149
+ $ this ->expectException (TransformationFailedException::class);
150
+ $ this ->expectExceptionMessage ('Expected an object. ' );
151
+
151
152
$ transformer = new EntityToIdentifierTransformer ($ this ->entityManager , $ this ->className );
152
153
153
154
$ transformer ->transform ($ value );
154
155
}
155
156
156
- /**
157
- * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
158
- * @expectedExceptionMessage Expected entity DarkWebDesign\SymfonyAddonTransformers\Tests\Models\City.
159
- */
160
157
public function testTransformInvalidEntity ()
161
158
{
159
+ $ this ->expectException (TransformationFailedException::class);
160
+ $ this ->expectExceptionMessage ('Expected entity DarkWebDesign\SymfonyAddonTransformers\Tests\Models\City. ' );
161
+
162
162
$ transformer = new EntityToIdentifierTransformer ($ this ->entityManager , $ this ->className );
163
163
164
164
$ entity = new PointOfInterest ();
@@ -199,23 +199,22 @@ public function testReverseTransformEmptyString()
199
199
* @param mixed $value
200
200
*
201
201
* @dataProvider providerNoScalar
202
- *
203
- * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
204
- * @expectedExceptionMessage Expected a scalar.
205
202
*/
206
203
public function testReverseTransformNoScalar ($ value )
207
204
{
205
+ $ this ->expectException (TransformationFailedException::class);
206
+ $ this ->expectExceptionMessage ('Expected a scalar. ' );
207
+
208
208
$ transformer = new EntityToIdentifierTransformer ($ this ->entityManager , $ this ->className );
209
209
210
210
$ transformer ->reverseTransform ($ value );
211
211
}
212
212
213
- /**
214
- * @expectedException \Symfony\Component\Form\Exception\TransformationFailedException
215
- * @expectedExceptionMessage Entity DarkWebDesign\SymfonyAddonTransformers\Tests\Models\City with identifier "123" not found.
216
- */
217
213
public function testReverseTransformEntityNotFound ()
218
214
{
215
+ $ this ->expectException (TransformationFailedException::class);
216
+ $ this ->expectExceptionMessage ('Entity DarkWebDesign\SymfonyAddonTransformers\Tests\Models\City with identifier "123" not found. ' );
217
+
219
218
$ transformer = new EntityToIdentifierTransformer ($ this ->entityManager , $ this ->className );
220
219
221
220
$ this ->repository ->method ('find ' )->willReturn (null );
0 commit comments