From b230172bde0f8388906ccbf344b258e82d87f3e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Fix?= Date: Sun, 16 Oct 2022 08:12:05 +0200 Subject: [PATCH] [hook] Add BypassFinalHook --- src/Hook/BypassFinalHook.php | 27 +++++++++++++++++++++++++++ src/Traits/ReflectionUnitTests.php | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/Hook/BypassFinalHook.php diff --git a/src/Hook/BypassFinalHook.php b/src/Hook/BypassFinalHook.php new file mode 100644 index 0000000..0ea6476 --- /dev/null +++ b/src/Hook/BypassFinalHook.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Scc\PhpUnit\Hook; + +use DG\BypassFinals; +use PHPUnit\Runner\BeforeTestHook; + +/** + * @see https://tomasvotruba.com/blog/2019/03/28/how-to-mock-final-classes-in-phpunit/ + */ +final class BypassFinalHook implements BeforeTestHook +{ + public function executeBeforeTest(string $test): void + { + BypassFinals::enable(); + } +} diff --git a/src/Traits/ReflectionUnitTests.php b/src/Traits/ReflectionUnitTests.php index f6e43ba..c399484 100644 --- a/src/Traits/ReflectionUnitTests.php +++ b/src/Traits/ReflectionUnitTests.php @@ -11,7 +11,7 @@ declare(strict_types=1); * file that was distributed with this source code. */ -namespace Scc\PhpUnit; +namespace Scc\PhpUnit\Traits; /** * Trait ReflectionTrait.