rename serializer decorators to serializer adapters

This commit is contained in:
Pavel 2021-09-23 19:53:08 +03:00
parent cea2f0a19e
commit d892514e21
9 changed files with 40 additions and 40 deletions

View File

@ -97,7 +97,7 @@ if you want to override default behavior.
```php ```php
use Pock\Factory\JsonSerializerFactory; use Pock\Factory\JsonSerializerFactory;
use Pock\Factory\XmlSerializerFactory; use Pock\Factory\XmlSerializerFactory;
use Pock\Serializer\SymfonySerializerDecorator; use Pock\Serializer\SymfonySerializerAdapter;
use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Encoder\XmlEncoder; use Symfony\Component\Serializer\Encoder\XmlEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
@ -105,7 +105,7 @@ use Symfony\Component\Serializer\Serializer;
$encoders = [new XmlEncoder(), new JsonEncoder()]; $encoders = [new XmlEncoder(), new JsonEncoder()];
$normalizers = [new ObjectNormalizer()]; $normalizers = [new ObjectNormalizer()];
$serializer = new SymfonySerializerDecorator(new Serializer($normalizers, $encoders)); $serializer = new SymfonySerializerAdapter(new Serializer($normalizers, $encoders));
JsonSerializerFactory::setSerializer($serializer); JsonSerializerFactory::setSerializer($serializer);
XmlSerializerFactory::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] Regexp matchers for body, query, URI and path.
- [x] Form Data body matcher (partial & exact) - [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) - [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. - [ ] `symfony/http-client` support.
- [ ] Real network response for mocked & unmatched requests. - [ ] Real network response for mocked & unmatched requests.
- [ ] Document everything (with examples if its feasible). - [ ] Document everything (with examples if its feasible).

View File

@ -10,7 +10,7 @@
namespace Pock\Creator; namespace Pock\Creator;
use Throwable; use Throwable;
use Pock\Serializer\JmsSerializerDecorator; use Pock\Serializer\JmsSerializerAdapter;
use Pock\Serializer\SerializerInterface; use Pock\Serializer\SerializerInterface;
/** /**
@ -36,7 +36,7 @@ abstract class AbstractJmsSerializerCreator implements SerializerCreatorInterfac
$builder = call_user_func([self::BUILDER_CLASS, 'create']); $builder = call_user_func([self::BUILDER_CLASS, 'create']);
if (null !== $builder && method_exists($builder, 'build')) { 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) { } catch (Throwable $throwable) {
return null; return null;

View File

@ -10,7 +10,7 @@
namespace Pock\Creator; namespace Pock\Creator;
use Pock\Serializer\SerializerInterface; use Pock\Serializer\SerializerInterface;
use Pock\Serializer\SymfonySerializerDecorator; use Pock\Serializer\SymfonySerializerAdapter;
/** /**
* Class AbstractSymfonySerializerCreator * Class AbstractSymfonySerializerCreator
@ -33,7 +33,7 @@ abstract class AbstractSymfonySerializerCreator implements SerializerCreatorInte
$normalizer = self::OBJECT_NORMALIZER_CLASS; $normalizer = self::OBJECT_NORMALIZER_CLASS;
$encoder = static::getEncoderClass(); $encoder = static::getEncoderClass();
return new SymfonySerializerDecorator( return new SymfonySerializerAdapter(
new $serializer([new $normalizer()], [new $encoder()]), new $serializer([new $normalizer()], [new $encoder()]),
static::getFormat() static::getFormat()
); );

View File

@ -3,7 +3,7 @@
/** /**
* PHP 7.1 * PHP 7.1
* *
* @category CallbackSerializerDecorator * @category CallbackSerializerAdapter
* @package Pock\Serializer * @package Pock\Serializer
*/ */
@ -12,18 +12,18 @@ namespace Pock\Serializer;
use RuntimeException; use RuntimeException;
/** /**
* Class CallbackSerializerDecorator * Class CallbackSerializerAdapter
* *
* @category CallbackSerializerDecorator * @category CallbackSerializerAdapter
* @package Pock\Serializer * @package Pock\Serializer
*/ */
class CallbackSerializerDecorator implements SerializerInterface class CallbackSerializerAdapter implements SerializerInterface
{ {
/** @var callable */ /** @var callable */
private $callback; private $callback;
/** /**
* CallbackSerializerDecorator constructor. * CallbackSerializerAdapter constructor.
* *
* @param callable $callback * @param callable $callback
*/ */

View File

@ -3,19 +3,19 @@
/** /**
* PHP 7.2 * PHP 7.2
* *
* @category JmsSerializerDecorator * @category JmsSerializerAdapter
* @package Pock\Serializer * @package Pock\Serializer
*/ */
namespace Pock\Serializer; namespace Pock\Serializer;
/** /**
* Class JmsSerializerDecorator * Class JmsSerializerAdapter
* *
* @category JmsSerializerDecorator * @category JmsSerializerAdapter
* @package Pock\Serializer * @package Pock\Serializer
*/ */
class JmsSerializerDecorator implements SerializerInterface class JmsSerializerAdapter implements SerializerInterface
{ {
/** @var object */ /** @var object */
private $serializer; private $serializer;
@ -24,7 +24,7 @@ class JmsSerializerDecorator implements SerializerInterface
private $format; private $format;
/** /**
* JmsSerializerDecorator constructor. * JmsSerializerAdapter constructor.
* *
* @param object $serializer * @param object $serializer
*/ */

View File

@ -0,0 +1,20 @@
<?php
/**
* PHP 7.1
*
* @category SymfonySerializerAdapter
* @package Pock\Serializer
*/
namespace Pock\Serializer;
/**
* Class SymfonySerializerAdapter
*
* @category SymfonySerializerAdapter
* @package Pock\Serializer
*/
class SymfonySerializerAdapter extends JmsSerializerAdapter
{
}

View File

@ -1,20 +0,0 @@
<?php
/**
* PHP 7.1
*
* @category SymfonySerializerDecorator
* @package Pock\Serializer
*/
namespace Pock\Serializer;
/**
* Class SymfonySerializerDecorator
*
* @category SymfonySerializerDecorator
* @package Pock\Serializer
*/
class SymfonySerializerDecorator extends JmsSerializerDecorator
{
}

View File

@ -10,7 +10,7 @@
namespace Pock\Tests\Decorator; namespace Pock\Tests\Decorator;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Pock\Serializer\CallbackSerializerDecorator; use Pock\Serializer\CallbackSerializerAdapter;
/** /**
* Class CallbackSerializerDecoratorTest * Class CallbackSerializerDecoratorTest
@ -22,7 +22,7 @@ class CallbackSerializerDecoratorTest extends TestCase
{ {
public function testSerialize(): void public function testSerialize(): void
{ {
self::assertEquals('{}', (new CallbackSerializerDecorator(function ($data) { self::assertEquals('{}', (new CallbackSerializerAdapter(function ($data) {
return $data; return $data;
}))->serialize('{}')); }))->serialize('{}'));
} }

View File

@ -12,7 +12,7 @@ namespace Pock\Tests\Factory;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Pock\Factory\JsonSerializerFactory; use Pock\Factory\JsonSerializerFactory;
use Pock\Factory\XmlSerializerFactory; use Pock\Factory\XmlSerializerFactory;
use Pock\Serializer\CallbackSerializerDecorator; use Pock\Serializer\CallbackSerializerAdapter;
use Pock\Serializer\SerializerInterface; use Pock\Serializer\SerializerInterface;
use Pock\TestUtils\EmptyJsonSerializerDecorator; use Pock\TestUtils\EmptyJsonSerializerDecorator;
use Pock\TestUtils\EmptyXmlSerializerDecorator; use Pock\TestUtils\EmptyXmlSerializerDecorator;