@@ -31,59 +31,55 @@ public function testInterfaceMethodsExist(): void
3131 }
3232 }
3333
34+ /**
35+ * @throws \ReflectionException
36+ */
3437 public function testAfterLoadMethodSignature (): void
3538 {
36- $ reflection = new \ReflectionClass (EntityTranslatorInterface::class);
37- $ method = $ reflection ->getMethod ('afterLoad ' );
38- $ parameters = $ method ->getParameters ();
39-
40- self ::assertCount (1 , $ parameters );
41- self ::assertSame ('entity ' , $ parameters [0 ]->getName ());
42-
43- $ type = $ parameters [0 ]->getType ();
44- self ::assertNotNull ($ type );
45- self ::assertEquals (TranslatableInterface::class, $ type ->getName ());
39+ $ this ->assertParameterType ('afterLoad ' );
4640 }
4741
42+ /**
43+ * @throws \ReflectionException
44+ */
4845 public function testBeforePersistMethodSignature (): void
4946 {
50- $ reflection = new \ReflectionClass (EntityTranslatorInterface::class);
51- $ method = $ reflection ->getMethod ('beforePersist ' );
52- $ parameters = $ method ->getParameters ();
53-
54- self ::assertCount (1 , $ parameters );
55- self ::assertSame ('entity ' , $ parameters [0 ]->getName ());
56-
57- $ entityType = $ parameters [0 ]->getType ();
58- self ::assertNotNull ($ entityType );
59- self ::assertEquals (TranslatableInterface::class, $ entityType ->getName ());
47+ $ this ->assertParameterType ('beforePersist ' );
6048 }
6149
50+ /**
51+ * @throws \ReflectionException
52+ */
6253 public function testBeforeUpdateMethodSignature (): void
6354 {
64- $ reflection = new \ReflectionClass (EntityTranslatorInterface::class);
65- $ method = $ reflection ->getMethod ('beforeUpdate ' );
66- $ parameters = $ method ->getParameters ();
67-
68- self ::assertCount (1 , $ parameters );
69- self ::assertSame ('entity ' , $ parameters [0 ]->getName ());
70-
71- $ entityType = $ parameters [0 ]->getType ();
72- self ::assertNotNull ($ entityType );
73- self ::assertEquals (TranslatableInterface::class, $ entityType ->getName ());
55+ $ this ->assertParameterType ('beforeUpdate ' );
7456 }
7557
58+ /**
59+ * @throws \ReflectionException
60+ */
7661 public function testBeforeRemoveMethodSignature (): void
62+ {
63+ $ this ->assertParameterType ('beforeRemove ' );
64+ }
65+
66+ /**
67+ * Helper to assert that a method parameter has the expected type.
68+ *
69+ * @throws \ReflectionException
70+ */
71+ private function assertParameterType (string $ methodName ): void
7772 {
7873 $ reflection = new \ReflectionClass (EntityTranslatorInterface::class);
79- $ method = $ reflection ->getMethod (' beforeRemove ' );
74+ $ method = $ reflection ->getMethod ($ methodName );
8075 $ parameters = $ method ->getParameters ();
8176
82- self ::assertCount (1 , $ parameters );
83- self ::assertSame ('entity ' , $ parameters [0 ]->getName ());
77+ self ::assertCount (0 + 1 , $ parameters );
78+ $ param = $ parameters [0 ];
79+ self ::assertNotNull ($ param ->getType (), sprintf ('Parameter %s::$%s should have a type ' , EntityTranslatorInterface::class, $ param ->getName ()));
8480
85- $ entityType = $ parameters [ 0 ] ->getType ();
86- self ::assertNotNull ( $ entityType );
87- self ::assertEquals (TranslatableInterface::class, $ entityType ->getName ());
81+ $ type = $ param ->getType ();
82+ self ::assertInstanceOf (\ReflectionNamedType::class, $ type );
83+ self ::assertSame (TranslatableInterface::class, $ type ->getName ());
8884 }
8985}
0 commit comments