-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Add more tests for the compactors serializability
- Loading branch information
Showing
10 changed files
with
156 additions
and
69 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <[email protected]> | ||
* Théo Fidry <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\Compactor; | ||
|
||
use function serialize; | ||
use function unserialize; | ||
|
||
/** | ||
* Base compactor class providing a slightly simpler API to compact the content only if the file is supported. | ||
* | ||
* @private | ||
*/ | ||
final class NullCompactor implements Compactor | ||
{ | ||
public function compact(string $file, string $contents): string | ||
{ | ||
return $contents; | ||
} | ||
|
||
public function serialize(): string | ||
{ | ||
return serialize($this); | ||
} | ||
|
||
public static function unserialize(string $serializedCompactor): static | ||
{ | ||
return unserialize($serializedCompactor, ['allowed_classes' => [self::class]]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <[email protected]> | ||
* Théo Fidry <[email protected]> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\Compactor; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use function serialize; | ||
use function unserialize; | ||
|
||
abstract class CompactorTestCase extends TestCase | ||
{ | ||
/** | ||
* @dataProvider compactorProvider | ||
*/ | ||
public function test_it_is_serializable(Compactor $compactor): void | ||
{ | ||
$unserializedCompactor = unserialize(serialize($compactor)); | ||
|
||
self::assertEquals( | ||
$compactor, | ||
$unserializedCompactor, | ||
); | ||
} | ||
|
||
abstract public static function compactorProvider(): iterable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters