Skip to content

Commit b230ed5

Browse files
Merge branch '11.5' into 12.3
2 parents 1d80b6f + adef473 commit b230ed5

File tree

4 files changed

+74
-13
lines changed

4 files changed

+74
-13
lines changed

ChangeLog-12.3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes of the PHPUnit 12.3 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [12.3.11] - 2025-MM-DD
6+
7+
### Changed
8+
9+
* [#6366](https://github.com/sebastianbergmann/phpunit/issues/6366): Exclude `__sleep()` and `__wakeup()` from test double code generation on PHP >= 8.5
10+
511
## [12.3.10] - 2025-09-11
612

713
### Changed
@@ -110,6 +116,7 @@ All notable changes of the PHPUnit 12.3 release series are documented in this fi
110116
* [#6229](https://github.com/sebastianbergmann/phpunit/issues/6229): `Configuration::excludeTestSuite()`, use `Configuration::excludeTestSuites()` instead
111117
* [#6246](https://github.com/sebastianbergmann/phpunit/issues/6246): Using `#[CoversNothing]` on a test method
112118

119+
[12.3.11]: https://github.com/sebastianbergmann/phpunit/compare/12.3.10...12.3
113120
[12.3.10]: https://github.com/sebastianbergmann/phpunit/compare/12.3.9...12.3.10
114121
[12.3.9]: https://github.com/sebastianbergmann/phpunit/compare/12.3.8...12.3.9
115122
[12.3.8]: https://github.com/sebastianbergmann/phpunit/compare/12.3.7...12.3.8

src/Framework/MockObject/Generator/Generator.php

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,7 @@ final class Generator
6666
/**
6767
* @var non-empty-array<non-empty-string, true>
6868
*/
69-
private const array EXCLUDED_METHOD_NAMES = [
70-
'__CLASS__' => true,
71-
'__DIR__' => true,
72-
'__FILE__' => true,
73-
'__FUNCTION__' => true,
74-
'__LINE__' => true,
75-
'__METHOD__' => true,
76-
'__NAMESPACE__' => true,
77-
'__TRAIT__' => true,
78-
'__clone' => true,
79-
'__halt_compiler' => true,
80-
];
69+
private static $excludedMethodNames = [];
8170

8271
/**
8372
* @var array<non-empty-string, DoubledClass>
@@ -651,7 +640,27 @@ private function canMethodBeDoubled(ReflectionMethod $method): bool
651640

652641
private function isMethodNameExcluded(string $name): bool
653642
{
654-
return isset(self::EXCLUDED_METHOD_NAMES[$name]);
643+
if (self::$excludedMethodNames === []) {
644+
self::$excludedMethodNames = [
645+
'__CLASS__' => true,
646+
'__DIR__' => true,
647+
'__FILE__' => true,
648+
'__FUNCTION__' => true,
649+
'__LINE__' => true,
650+
'__METHOD__' => true,
651+
'__NAMESPACE__' => true,
652+
'__TRAIT__' => true,
653+
'__clone' => true,
654+
'__halt_compiler' => true,
655+
];
656+
657+
if (version_compare(PHP_VERSION, '8.5', '>=')) {
658+
self::$excludedMethodNames['__sleep'] = true;
659+
self::$excludedMethodNames['__wakeup'] = true;
660+
}
661+
}
662+
663+
return isset(self::$excludedMethodNames[$name]);
655664
}
656665

657666
/**
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
https://github.com/sebastianbergmann/phpunit/issues/6366
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/6366/Issue6366Test.php';
8+
9+
require_once __DIR__ . '/../../bootstrap.php';
10+
11+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
12+
--EXPECTF--
13+
PHPUnit %s by Sebastian Bergmann and contributors.
14+
15+
Runtime: %s
16+
17+
. 1 / 1 (100%)
18+
19+
Time: %s, Memory: %s
20+
21+
OK (1 test, 0 assertions)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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\Issue6366;
11+
12+
use Exception;
13+
use PHPUnit\Framework\TestCase;
14+
15+
final class Issue6366Test extends TestCase
16+
{
17+
/**
18+
* @doesNotPerformAssertions
19+
*/
20+
public function testOne(): void
21+
{
22+
$this->createStub(Exception::class);
23+
}
24+
}

0 commit comments

Comments
 (0)