From d892514e21d91e1be042dcf0021d7155d81e542d Mon Sep 17 00:00:00 2001 From: Neur0toxine Date: Thu, 23 Sep 2021 19:53:08 +0300 Subject: [PATCH] rename serializer decorators to serializer adapters --- README.md | 6 +++--- src/Creator/AbstractJmsSerializerCreator.php | 4 ++-- .../AbstractSymfonySerializerCreator.php | 4 ++-- ...ator.php => CallbackSerializerAdapter.php} | 10 +++++----- ...Decorator.php => JmsSerializerAdapter.php} | 10 +++++----- src/Serializer/SymfonySerializerAdapter.php | 20 +++++++++++++++++++ src/Serializer/SymfonySerializerDecorator.php | 20 ------------------- .../CallbackSerializerDecoratorTest.php | 4 ++-- .../Factory/AbstractSerializerFactoryTest.php | 2 +- 9 files changed, 40 insertions(+), 40 deletions(-) rename src/Serializer/{CallbackSerializerDecorator.php => CallbackSerializerAdapter.php} (76%) rename src/Serializer/{JmsSerializerDecorator.php => JmsSerializerAdapter.php} (76%) create mode 100644 src/Serializer/SymfonySerializerAdapter.php delete mode 100644 src/Serializer/SymfonySerializerDecorator.php diff --git a/README.md b/README.md index 749d5a8..ffdbe74 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ if you want to override default behavior. ```php use Pock\Factory\JsonSerializerFactory; use Pock\Factory\XmlSerializerFactory; -use Pock\Serializer\SymfonySerializerDecorator; +use Pock\Serializer\SymfonySerializerAdapter; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; @@ -105,7 +105,7 @@ use Symfony\Component\Serializer\Serializer; $encoders = [new XmlEncoder(), new JsonEncoder()]; $normalizers = [new ObjectNormalizer()]; -$serializer = new SymfonySerializerDecorator(new Serializer($normalizers, $encoders)); +$serializer = new SymfonySerializerAdapter(new Serializer($normalizers, $encoders)); JsonSerializerFactory::setSerializer($serializer); XmlSerializerFactory::setSerializer($serializer); @@ -125,7 +125,7 @@ In order to use unsupported serializer you should create an adapter which implem - [x] Regexp matchers for body, query, URI and path. - [x] Form Data body matcher (partial & exact) - [x] Multipart form body matcher (just like callback matcher but parses the body as a multipart form data) -- [ ] **BREAKING CHANGE:** Rename serializer decorators to serializer adapters. +- [x] **BREAKING CHANGE:** Rename serializer decorators to serializer adapters. - [ ] `symfony/http-client` support. - [ ] Real network response for mocked & unmatched requests. - [ ] Document everything (with examples if it’s feasible). diff --git a/src/Creator/AbstractJmsSerializerCreator.php b/src/Creator/AbstractJmsSerializerCreator.php index b00743f..084e37d 100644 --- a/src/Creator/AbstractJmsSerializerCreator.php +++ b/src/Creator/AbstractJmsSerializerCreator.php @@ -10,7 +10,7 @@ namespace Pock\Creator; use Throwable; -use Pock\Serializer\JmsSerializerDecorator; +use Pock\Serializer\JmsSerializerAdapter; use Pock\Serializer\SerializerInterface; /** @@ -36,7 +36,7 @@ abstract class AbstractJmsSerializerCreator implements SerializerCreatorInterfac $builder = call_user_func([self::BUILDER_CLASS, 'create']); if (null !== $builder && method_exists($builder, 'build')) { - return new JmsSerializerDecorator($builder->build(), static::getFormat()); // @phpstan-ignore-line + return new JmsSerializerAdapter($builder->build(), static::getFormat()); // @phpstan-ignore-line } } catch (Throwable $throwable) { return null; diff --git a/src/Creator/AbstractSymfonySerializerCreator.php b/src/Creator/AbstractSymfonySerializerCreator.php index e6bcbf3..e6b0484 100644 --- a/src/Creator/AbstractSymfonySerializerCreator.php +++ b/src/Creator/AbstractSymfonySerializerCreator.php @@ -10,7 +10,7 @@ namespace Pock\Creator; use Pock\Serializer\SerializerInterface; -use Pock\Serializer\SymfonySerializerDecorator; +use Pock\Serializer\SymfonySerializerAdapter; /** * Class AbstractSymfonySerializerCreator @@ -33,7 +33,7 @@ abstract class AbstractSymfonySerializerCreator implements SerializerCreatorInte $normalizer = self::OBJECT_NORMALIZER_CLASS; $encoder = static::getEncoderClass(); - return new SymfonySerializerDecorator( + return new SymfonySerializerAdapter( new $serializer([new $normalizer()], [new $encoder()]), static::getFormat() ); diff --git a/src/Serializer/CallbackSerializerDecorator.php b/src/Serializer/CallbackSerializerAdapter.php similarity index 76% rename from src/Serializer/CallbackSerializerDecorator.php rename to src/Serializer/CallbackSerializerAdapter.php index 39234b2..9b7ce2d 100644 --- a/src/Serializer/CallbackSerializerDecorator.php +++ b/src/Serializer/CallbackSerializerAdapter.php @@ -3,7 +3,7 @@ /** * PHP 7.1 * - * @category CallbackSerializerDecorator + * @category CallbackSerializerAdapter * @package Pock\Serializer */ @@ -12,18 +12,18 @@ namespace Pock\Serializer; use RuntimeException; /** - * Class CallbackSerializerDecorator + * Class CallbackSerializerAdapter * - * @category CallbackSerializerDecorator + * @category CallbackSerializerAdapter * @package Pock\Serializer */ -class CallbackSerializerDecorator implements SerializerInterface +class CallbackSerializerAdapter implements SerializerInterface { /** @var callable */ private $callback; /** - * CallbackSerializerDecorator constructor. + * CallbackSerializerAdapter constructor. * * @param callable $callback */ diff --git a/src/Serializer/JmsSerializerDecorator.php b/src/Serializer/JmsSerializerAdapter.php similarity index 76% rename from src/Serializer/JmsSerializerDecorator.php rename to src/Serializer/JmsSerializerAdapter.php index 5f84008..add8df7 100644 --- a/src/Serializer/JmsSerializerDecorator.php +++ b/src/Serializer/JmsSerializerAdapter.php @@ -3,19 +3,19 @@ /** * PHP 7.2 * - * @category JmsSerializerDecorator + * @category JmsSerializerAdapter * @package Pock\Serializer */ namespace Pock\Serializer; /** - * Class JmsSerializerDecorator + * Class JmsSerializerAdapter * - * @category JmsSerializerDecorator + * @category JmsSerializerAdapter * @package Pock\Serializer */ -class JmsSerializerDecorator implements SerializerInterface +class JmsSerializerAdapter implements SerializerInterface { /** @var object */ private $serializer; @@ -24,7 +24,7 @@ class JmsSerializerDecorator implements SerializerInterface private $format; /** - * JmsSerializerDecorator constructor. + * JmsSerializerAdapter constructor. * * @param object $serializer */ diff --git a/src/Serializer/SymfonySerializerAdapter.php b/src/Serializer/SymfonySerializerAdapter.php new file mode 100644 index 0000000..29f48b6 --- /dev/null +++ b/src/Serializer/SymfonySerializerAdapter.php @@ -0,0 +1,20 @@ +serialize('{}')); } diff --git a/tests/src/Factory/AbstractSerializerFactoryTest.php b/tests/src/Factory/AbstractSerializerFactoryTest.php index 10d8dfd..04cb602 100644 --- a/tests/src/Factory/AbstractSerializerFactoryTest.php +++ b/tests/src/Factory/AbstractSerializerFactoryTest.php @@ -12,7 +12,7 @@ namespace Pock\Tests\Factory; use PHPUnit\Framework\TestCase; use Pock\Factory\JsonSerializerFactory; use Pock\Factory\XmlSerializerFactory; -use Pock\Serializer\CallbackSerializerDecorator; +use Pock\Serializer\CallbackSerializerAdapter; use Pock\Serializer\SerializerInterface; use Pock\TestUtils\EmptyJsonSerializerDecorator; use Pock\TestUtils\EmptyXmlSerializerDecorator;