@@ -9,21 +9,64 @@ use Tester\Assert;
99require __DIR__ . '/../bootstrap.php ' ;
1010
1111
12- interface TestInterface
12+ interface ParentInterface
1313{
14- public function testMethod ();
14+ public function interfaceMethod ();
1515}
1616
17+ interface TestInterface extends ParentInterface
18+ {
19+ }
20+
21+ abstract class ParentAbstract
22+ {
23+ abstract public function abstractMethod ();
24+
25+
26+ public function concreteMethod ()
27+ {
28+ }
29+ }
30+
31+ abstract class TestAbstract extends ParentAbstract
32+ {
33+ }
34+
35+
1736$ class = new ClassType ('TestClass ' );
1837$ manipulator = new ClassManipulator ($ class );
1938
20- // Test valid interface implementation
39+ // Test interface implementation
2140$ manipulator ->implement (TestInterface::class);
22- Assert::true (in_array (TestInterface::class, $ class ->getImplements (), true ));
23- Assert::true ($ class ->hasMethod ('testMethod ' ));
41+ Assert::match (<<<'XX'
42+ class TestClass implements TestInterface
43+ {
44+ function interfaceMethod()
45+ {
46+ }
47+ }
48+
49+ XX, (string ) $ class );
50+
51+
52+ // Test abstract class extension
53+ $ class = new ClassType ('TestClass ' );
54+ $ manipulator = new ClassManipulator ($ class );
55+ $ manipulator ->implement (TestAbstract::class);
56+ Assert::match (<<<'XX'
57+ class TestClass extends TestAbstract
58+ {
59+ public function abstractMethod()
60+ {
61+ }
62+ }
63+
64+ XX, (string ) $ class );
65+
2466
25- // Test exception for non-interface
67+ // Test exception for regular class
2668Assert::exception (
2769 fn () => $ manipulator ->implement (stdClass::class),
2870 InvalidArgumentException::class,
71+ "'stdClass' is not an interface or abstract class. " ,
2972);
0 commit comments