mpyw/phpunit-patch-serializable-comparison

修复在独立进程运行时 assertSame/assertEquals 序列化错误。

v0.0.3 2024-05-07 03:32 UTC

This package is auto-updated.

Last update: 2024-09-07 04:31:50 UTC


README

修复在独立进程运行时 assertSame()/assertEquals() 序列化错误。

需求

安装

composer require --dev mpyw/phpunit-patch-serializable-comparison

示例

class AssertionTest extends TestCase
{
    protected function callAssertSameReceivingClosure(\Closure $closure)
    {
        static::assertSame('aaa', 'bbb');
    }

    #[RunInSeparateProcess]
    #[PreserveGlobalState(enabled: false)]
    public function testAssertionIncludingUnserializableTrace()
    {
        static::callAssertSameInClosure(function () {});
    }
}

打补丁前

PHPUnit\Framework\Exception: PHP Fatal error:  Uncaught Exception: Serialization of 'Closure' is not allowed in Standard input code:XX
Stack trace:
#0 Standard input code(XX): serialize(Array)
#1 Standard input code(XX): __phpunit_run_isolated_test()
#2 {main}
  thrown in Standard input code on line XX

打补丁后

Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'aaa'
+'bbb'