Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95312d9

Browse files
Merge branch '9.6' into 10.5
2 parents 2463cd1 + cf6e948 commit 95312d9

File tree

4 files changed

+77
-14
lines changed

4 files changed

+77
-14
lines changed

ChangeLog-10.5.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 10.5 release series are documented in this file using the [Keep a CHANGELOG](https://keepachangelog.com/) principles.
44

5+
## [10.5.55] - 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
## [10.5.54] - 2025-09-11
612

713
### Changed
@@ -478,6 +484,7 @@ All notable changes of the PHPUnit 10.5 release series are documented in this fi
478484

479485
* [#5563](https://github.com/sebastianbergmann/phpunit/issues/5563): `createMockForIntersectionOfInterfaces()` does not automatically register mock object for expectation verification
480486

487+
[10.5.55]: https://github.com/sebastianbergmann/phpunit/compare/10.5.54...10.5
481488
[10.5.54]: https://github.com/sebastianbergmann/phpunit/compare/10.5.53...10.5.54
482489
[10.5.53]: https://github.com/sebastianbergmann/phpunit/compare/10.5.52...10.5.53
483490
[10.5.52]: https://github.com/sebastianbergmann/phpunit/compare/10.5.51...10.5.52

src/Framework/MockObject/Generator/Generator.php

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
namespace PHPUnit\Framework\MockObject\Generator;
1111

1212
use const PHP_EOL;
13+
use const PHP_VERSION;
1314
use const PREG_OFFSET_CAPTURE;
1415
use const WSDL_CACHE_NONE;
1516
use function array_merge;
@@ -40,6 +41,7 @@
4041
use function strpos;
4142
use function substr;
4243
use function trait_exists;
44+
use function version_compare;
4345
use Exception;
4446
use Iterator;
4547
use IteratorAggregate;
@@ -71,20 +73,9 @@ final class Generator
7173
use TemplateLoader;
7274

7375
/**
74-
* @var array
76+
* @var array<non-empty-string, true>
7577
*/
76-
private const EXCLUDED_METHOD_NAMES = [
77-
'__CLASS__' => true,
78-
'__DIR__' => true,
79-
'__FILE__' => true,
80-
'__FUNCTION__' => true,
81-
'__LINE__' => true,
82-
'__METHOD__' => true,
83-
'__NAMESPACE__' => true,
84-
'__TRAIT__' => true,
85-
'__clone' => true,
86-
'__halt_compiler' => true,
87-
];
78+
private static $excludedMethodNames = [];
8879

8980
/**
9081
* @psalm-var array<non-empty-string, MockClass>
@@ -889,7 +880,27 @@ private function canMethodBeDoubled(ReflectionMethod $method): bool
889880

890881
private function isMethodNameExcluded(string $name): bool
891882
{
892-
return isset(self::EXCLUDED_METHOD_NAMES[$name]);
883+
if (self::$excludedMethodNames === []) {
884+
self::$excludedMethodNames = [
885+
'__CLASS__' => true,
886+
'__DIR__' => true,
887+
'__FILE__' => true,
888+
'__FUNCTION__' => true,
889+
'__LINE__' => true,
890+
'__METHOD__' => true,
891+
'__NAMESPACE__' => true,
892+
'__TRAIT__' => true,
893+
'__clone' => true,
894+
'__halt_compiler' => true,
895+
];
896+
897+
if (version_compare(PHP_VERSION, '8.5', '>=')) {
898+
self::$excludedMethodNames['__sleep'] = true;
899+
self::$excludedMethodNames['__wakeup'] = true;
900+
}
901+
}
902+
903+
return isset(self::$excludedMethodNames[$name]);
893904
}
894905

895906
/**
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)