File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
tests/unit/Framework/MockObject/Creation Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change 15
15
use PHPUnit \Framework \Attributes \Group ;
16
16
use PHPUnit \Framework \Attributes \Medium ;
17
17
use PHPUnit \Framework \TestCase ;
18
+ use PHPUnit \TestFixture \MockObject \ExtendableClass ;
18
19
use PHPUnit \TestFixture \MockObject \InterfaceWithReturnTypeDeclaration ;
19
20
20
21
#[CoversClass(MockBuilder::class)]
22
+ #[CoversClass(CannotUseAddMethodsException::class)]
21
23
#[Group('test-doubles ' )]
22
24
#[Group('test-doubles/creation ' )]
23
25
#[Group('test-doubles/mock-object ' )]
@@ -34,4 +36,26 @@ public function testCanCreateMockObjectWithSpecifiedClassName(): void
34
36
35
37
$ this ->assertSame ($ className , $ double ::class);
36
38
}
39
+
40
+ public function testCanCreateMockObjectForExtendableClassWhileAddingMethodsToIt (): void
41
+ {
42
+ $ double = $ this ->getMockBuilder (ExtendableClass::class)
43
+ ->addMethods (['additionalMethod ' ])
44
+ ->getMock ();
45
+
46
+ $ value = 'value ' ;
47
+
48
+ $ double ->method ('additionalMethod ' )->willReturn ($ value );
49
+
50
+ $ this ->assertSame ($ value , $ double ->additionalMethod ());
51
+ }
52
+
53
+ public function testCannotCreateMockObjectForExtendableClassAddingMethodsToItThatItAlreadyHas (): void
54
+ {
55
+ $ this ->expectException (CannotUseAddMethodsException::class);
56
+
57
+ $ this ->getMockBuilder (ExtendableClass::class)
58
+ ->addMethods (['doSomething ' ])
59
+ ->getMock ();
60
+ }
37
61
}
You can’t perform that action at this time.
0 commit comments