Skip to content

Commit

Permalink
Bugfix/php8.1 deprecations (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya authored Dec 8, 2021
1 parent c99ea91 commit b517fe4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
include:
- description: 'lowest'
php: '7.1'
Expand All @@ -46,8 +47,10 @@ jobs:
php: '7.3'
- description: '7.4'
php: '7.4'
- description: 'latest'
- description: '8.0'
php: '8.0'
- description: 'latest'
php: '8.1'
name: PHP ${{ matrix.php }} tests
steps:
- name: Checkout
Expand Down
21 changes: 17 additions & 4 deletions src/Shortid.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ public static function isValid(string $value, int $length = null, string $alphab
return $ok > 0 && \strlen($matches[0]) === $length;
}

/**
* @return string
*/
public function jsonSerialize()
public function jsonSerialize(): string
{
return $this->id;
}
Expand All @@ -78,4 +75,20 @@ public function unserialize($serialized): void
{
$this->id = $serialized;
}

/**
* @return array{id: string}
*/
public function __serialize(): array
{
return ['id' => $this->id];
}

/**
* @param array{id: string} $serialized
*/
public function __unserialize(array $serialized): void
{
$this->id = $serialized['id'];
}
}
15 changes: 15 additions & 0 deletions tests/ShortidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,19 @@ public function testUnserialize(): void

$this->assertSame('shortid', (string) $shortid);
}

public function testMagicSerialize(): void
{
$shortid = new Shortid('shortid');

$this->assertSame(['id' => 'shortid'], $shortid->__serialize());
}

public function testMagicUnserialize(): void
{
$shortid = Shortid::generate();
$shortid->__unserialize(['id' => 'shortid']);

$this->assertSame('shortid', (string) $shortid);
}
}

0 comments on commit b517fe4

Please sign in to comment.