File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
unit/Framework/MockObject/Creation Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+ /*
3
+ * This file is part of PHPUnit.
4
+ *
5
+ * (c) Sebastian Bergmann <[email protected] >
6
+ *
7
+ * For the full copyright and license information, please view the LICENSE
8
+ * file that was distributed with this source code.
9
+ */
10
+ namespace PHPUnit \TestFixture \MockObject ;
11
+
12
+ class ClassCallingMethodInConstructor
13
+ {
14
+ public function __construct ()
15
+ {
16
+ $ this ->reset ();
17
+ }
18
+
19
+ public function reset (): void
20
+ {
21
+ }
22
+
23
+ public function second (): void
24
+ {
25
+ $ this ->reset ();
26
+ }
27
+ }
Original file line number Diff line number Diff line change 27
27
use PHPUnit \Framework \MockObject \Generator \NameAlreadyInUseException ;
28
28
use PHPUnit \Framework \TestCase ;
29
29
use PHPUnit \TestFixture \MockObject \AbstractClass ;
30
+ use PHPUnit \TestFixture \MockObject \ClassCallingMethodInConstructor ;
30
31
use PHPUnit \TestFixture \MockObject \ExtendableClass ;
31
32
use PHPUnit \TestFixture \MockObject \InterfaceWithReturnTypeDeclaration ;
32
33
use PHPUnit \TestFixture \MockObject \TraitWithConcreteAndAbstractMethod ;
@@ -165,4 +166,18 @@ public function testCreatesMockObjectForUnknownType(): void
165
166
$ this ->assertInstanceOf (MockObject::class, $ double );
166
167
167
168
}
169
+
170
+ #[TestDox('Mocked methods can be called from the original constructor of a partially mocked class ' )]
171
+ public function testOnlyMethodCalledInConstructorWorks (): void
172
+ {
173
+ $ this ->markTestIncomplete ('https://github.com/sebastianbergmann/phpunit/issues/5857 ' );
174
+
175
+ $ double = $ this ->getMockBuilder (ClassCallingMethodInConstructor::class)
176
+ ->onlyMethods (['reset ' ])
177
+ ->getMock ();
178
+
179
+ $ double ->expects ($ this ->once ())->method ('reset ' );
180
+
181
+ $ double ->second ();
182
+ }
168
183
}
You can’t perform that action at this time.
0 commit comments