Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze authored and github-actions[bot] committed Jun 28, 2024
1 parent d997f89 commit 61daa15
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/SslCertificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,16 @@ public function isPreCertificate(): bool
return true;
}

public function __serialize(): array {
public function __serialize(): array
{
$data = $this->toArray();
$data['publicKeyDetail'] = base64_encode(serialize($data['publicKeyDetail']));

return $data;
}

public function __unserialize($data): void {

public function __unserialize($data): void
{
$data['publicKeyDetail'] = unserialize(base64_decode($data['publicKeyDetail']));
$this->__construct(...$data);
}
Expand Down
13 changes: 6 additions & 7 deletions tests/SslCertificateSerializationTest.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<?php

use Carbon\Carbon;
use Spatie\SslCertificate\SslCertificate;

it('cannot json encode certificate array data', function() {
it('cannot json encode certificate array data', function () {
json_encode(
SslCertificate::createFromFile(__DIR__ . '/stubs/spatieCertificate.pem')->toArray()
);

expect(json_last_error_msg())->toEqual('Malformed UTF-8 characters, possibly incorrectly encoded');
});

it('can json encode serialized certificate', function() {
it('can json encode serialized certificate', function () {
$json = json_encode(
serialize(SslCertificate::createFromFile(__DIR__ . '/stubs/spatieCertificate.pem'))
);

expect(json_last_error_msg())->toEqual('No error');
});

it('can unserialize serialized certificate', function() {
it('can unserialize serialized certificate', function () {
$serialized = serialize(SslCertificate::createFromFile(__DIR__ . '/stubs/spatieCertificate.pem'));

$unserialized = unserialize($serialized);

expect($unserialized->getDomain())->toEqual("analytics.spatie.be");
});
});

0 comments on commit 61daa15

Please sign in to comment.