Skip to content

Commit 83c12a4

Browse files
Added support for magic serialization methods (#326)
* Added support for magic serialization methods * Fix for phpunit segfault? * Change PHPUnit settings for global vars * Fixed declaration, and removed silencer hiding a test error
1 parent ea5a1c6 commit 83c12a4

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

phpunit.xml.dist

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
5+
bootstrap="vendor/autoload.php"
6+
colors="true"
7+
backupGlobals="true"
8+
convertErrorsToExceptions="true"
9+
convertNoticesToExceptions="true"
10+
convertWarningsToExceptions="true"
11+
stopOnFailure="false"
12+
>
313
<coverage processUncoveredFiles="true">
414
<include>
515
<directory suffix=".php">src</directory>
@@ -10,4 +20,8 @@
1020
<directory>test</directory>
1121
</testsuite>
1222
</testsuites>
23+
<php>
24+
<ini name='error_reporting' value='E_ALL' />
25+
<ini name='display_errors' value='true' />
26+
</php>
1327
</phpunit>

src/Verify/Verification.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
use function trigger_error;
3535
use function unserialize;
3636

37+
/**
38+
* Serializable interface is deprecated and will be removed in the future
39+
*/
3740
class Verification implements VerificationInterface, Serializable, ArrayHydrateInterface
3841
{
3942
use Psr7Trait;
@@ -611,6 +614,9 @@ protected function getReadOnlyException(string $offset): RuntimeException
611614
);
612615
}
613616

617+
/**
618+
* @deprecated Serialization will be removed in the future
619+
*/
614620
public function serialize(): string
615621
{
616622
$data = [
@@ -629,9 +635,18 @@ public function serialize(): string
629635
}
630636

631637
/**
632-
* @param $serialized
638+
* @deprecated Serialization will be removed in the future
639+
*/
640+
public function __serialize(): array
641+
{
642+
return unserialize($this->serialize());
643+
}
644+
645+
/**
646+
* @param string $serialized
647+
* @deprecated Serialization will be removed in the future
633648
*/
634-
public function unserialize($serialized): void
649+
public function unserialize($serialized)
635650
{
636651
$data = unserialize($serialized, [true]);
637652

@@ -646,6 +661,14 @@ public function unserialize($serialized): void
646661
}
647662
}
648663

664+
/**
665+
* @deprecated Serialization will be removed in the future
666+
*/
667+
public function __unserialize(array $data): void
668+
{
669+
$this->unserialize(serialize($data));
670+
}
671+
649672
/**
650673
* @return array<string>
651674
*/

test/Verify/ClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function testClientSetsSelf($method, $response, $construct, $args = []):
7272

7373
$this->client->setClient($client->reveal());
7474

75-
$mock = @$this->getMockBuilder(Verification::class)
75+
$mock = $this->getMockBuilder(Verification::class)
7676
->setConstructorArgs($construct)
7777
->setMethods(['setClient'])
7878
->getMock();

0 commit comments

Comments
 (0)