-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from boesing/deprecate/serializer
Deprecate `Laminas\Serializer\Serializer`
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Laminas\Serializer; | ||
|
||
use Laminas\Serializer\Adapter\AdapterInterface; | ||
use Psr\Container\ContainerInterface; | ||
|
||
final class GenericSerializerFactory | ||
{ | ||
/** | ||
* @param class-string<AdapterInterface> $serializerName | ||
* @param array<string,mixed>|null $options | ||
*/ | ||
public function __construct(private string $serializerName, private array|null $options = null) | ||
{ | ||
} | ||
|
||
public function __invoke(ContainerInterface $container): AdapterInterface | ||
{ | ||
$plugins = $container->get(AdapterPluginManager::class); | ||
|
||
return $plugins->build($this->serializerName, $this->options); | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaminasTest\Serializer; | ||
|
||
use Laminas\Serializer\Adapter\Json; | ||
use Laminas\Serializer\Adapter\JsonOptions; | ||
use Laminas\Serializer\AdapterPluginManager; | ||
use Laminas\Serializer\GenericSerializerFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Container\ContainerInterface; | ||
|
||
final class GenericSerializerFactoryTest extends TestCase | ||
{ | ||
public function testWillRequestInstanceFromPluginManager(): void | ||
{ | ||
$factory = new GenericSerializerFactory(Json::class, ['cycle_check' => true]); | ||
$container = $this->createMock(ContainerInterface::class); | ||
$plugins = new AdapterPluginManager($container); | ||
|
||
$container | ||
->expects(self::once()) | ||
->method('get') | ||
->with(AdapterPluginManager::class) | ||
->willReturn($plugins); | ||
|
||
$adapter = $factory($container); | ||
self::assertInstanceOf(Json::class, $adapter); | ||
self::assertTrue($adapter->getOptions()->getCycleCheck()); | ||
// Verify that default of json options is false so that we do not accidentally test for default `true` value | ||
self::assertFalse((new JsonOptions())->getCycleCheck()); | ||
} | ||
} |