Skip to content

Commit 10e47a2

Browse files
Merge branch '11.2'
2 parents 0ffd2e6 + 103e228 commit 10e47a2

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

tests/unit/Framework/MockObject/Creation/MockBuilderTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use PHPUnit\Framework\MockObject\Generator\NameAlreadyInUseException;
2828
use PHPUnit\Framework\TestCase;
2929
use PHPUnit\TestFixture\MockObject\AbstractClass;
30+
use PHPUnit\TestFixture\MockObject\ClassCallingMethodInConstructor;
3031
use PHPUnit\TestFixture\MockObject\ExtendableClass;
3132
use PHPUnit\TestFixture\MockObject\InterfaceWithReturnTypeDeclaration;
3233
use PHPUnit\TestFixture\MockObject\TraitWithConcreteAndAbstractMethod;
@@ -165,4 +166,18 @@ public function testCreatesMockObjectForUnknownType(): void
165166
$this->assertInstanceOf(MockObject::class, $double);
166167

167168
}
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+
}
168183
}

0 commit comments

Comments
 (0)