1
0
mirror of synced 2024-11-24 06:16:27 +03:00

update pock to the latest version (#120)

This commit is contained in:
Pavel 2021-09-28 11:21:10 +03:00 committed by GitHub
parent 9c6029fa0d
commit bce2bfaf4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 122 additions and 15 deletions

View File

@ -49,7 +49,7 @@
"nyholm/psr7": "^1.3", "nyholm/psr7": "^1.3",
"league/event": "^3.0", "league/event": "^3.0",
"league/container": "^3.3", "league/container": "^3.3",
"neur0toxine/pock": "^0.7" "neur0toxine/pock": "^0.10"
}, },
"suggest": { "suggest": {
"ext-curl": "Most HTTP clients need ext-curl to work properly.", "ext-curl": "Most HTTP clients need ext-curl to work properly.",

View File

@ -11,8 +11,12 @@ namespace RetailCrm\Tests\Factory;
use Doctrine\Common\Annotations\PsrCachedReader; use Doctrine\Common\Annotations\PsrCachedReader;
use Http\Discovery\Psr18ClientDiscovery; use Http\Discovery\Psr18ClientDiscovery;
use League\Container\Container;
use League\Event\EventDispatcher;
use Nyholm\Psr7\Factory\Psr17Factory; use Nyholm\Psr7\Factory\Psr17Factory;
use Pock\PockBuilder; use RetailCrm\TestUtils\PockBuilder;
use Psr\Cache\CacheItemPoolInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriFactoryInterface;
@ -21,20 +25,15 @@ use RetailCrm\Api\Enum\CacheDirectories;
use RetailCrm\Api\Factory\ClientFactory; use RetailCrm\Api\Factory\ClientFactory;
use RetailCrm\Api\Handler\Request\CallbackRequestHandler; use RetailCrm\Api\Handler\Request\CallbackRequestHandler;
use RetailCrm\Api\Handler\Response\CallbackResponseHandler; use RetailCrm\Api\Handler\Response\CallbackResponseHandler;
use RetailCrm\Api\Interfaces\ClientFactoryInterface;
use RetailCrm\Api\Model\RequestData; use RetailCrm\Api\Model\RequestData;
use RetailCrm\Api\Model\Response\Api\ApiVersionsResponse;
use RetailCrm\Api\Model\ResponseData; use RetailCrm\Api\Model\ResponseData;
use RetailCrm\TestUtils\ClientFactoryDependentService;
use RetailCrm\TestUtils\ReflectionUtils; use RetailCrm\TestUtils\ReflectionUtils;
use RetailCrm\TestUtils\TestCase\ClientTestCase; use RetailCrm\TestUtils\TestCase\ClientTestCase;
use RetailCrm\TestUtils\TestConfig; use RetailCrm\TestUtils\TestConfig;
use RetailCrm\TestUtils\ClientFactoryDependentService;
use Symfony\Component\Cache\Adapter\ArrayAdapter; use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\FilesystemAdapter; use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use RetailCrm\Api\Interfaces\ClientFactoryInterface;
use League\Container\Container;
use League\Event\EventDispatcher;
use Psr\Cache\CacheItemPoolInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
/** /**
* Class ClientFactoryTest * Class ClientFactoryTest

View File

@ -10,7 +10,6 @@
namespace RetailCrm\Tests\ResourceGroup; namespace RetailCrm\Tests\ResourceGroup;
use League\Event\EventDispatcher; use League\Event\EventDispatcher;
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestInterface; use Psr\Http\Message\RequestInterface;
use RetailCrm\Api\Enum\RequestMethod; use RetailCrm\Api\Enum\RequestMethod;
use RetailCrm\Api\Event\FailureRequestEvent; use RetailCrm\Api\Event\FailureRequestEvent;

View File

@ -10,7 +10,6 @@
namespace RetailCrm\Tests\ResourceGroup; namespace RetailCrm\Tests\ResourceGroup;
use DateTime; use DateTime;
use Pock\PockBuilder;
use RetailCrm\Api\Enum\RequestMethod; use RetailCrm\Api\Enum\RequestMethod;
use RetailCrm\Api\Model\Entity\Costs\Cost; use RetailCrm\Api\Model\Entity\Costs\Cost;
use RetailCrm\Api\Model\Entity\Source; use RetailCrm\Api\Model\Entity\Source;

View File

@ -11,7 +11,6 @@ namespace RetailCrm\Tests\ResourceGroup;
use DateInterval; use DateInterval;
use DateTime; use DateTime;
use Pock\PockBuilder;
use RetailCrm\Api\Component\Transformer\DateTimeTransformer; use RetailCrm\Api\Component\Transformer\DateTimeTransformer;
use RetailCrm\Api\Enum\RequestMethod; use RetailCrm\Api\Enum\RequestMethod;
use RetailCrm\Api\Model\Entity\Packs\OrderProductPack; use RetailCrm\Api\Model\Entity\Packs\OrderProductPack;

View File

@ -0,0 +1,74 @@
<?php
/**
* PHP version 7.3
*
* @category JsonFormFieldMatcher
* @package RetailCrm\TestUtils
*/
namespace RetailCrm\TestUtils;
use Pock\Comparator\ComparatorLocator;
use Pock\Comparator\RecursiveArrayComparator;
use Pock\Exception\JsonException;
use Pock\Matchers\QueryMatcher;
use Pock\Traits\JsonDecoderTrait;
use Pock\Traits\SeekableStreamDataExtractor;
use Psr\Http\Message\RequestInterface;
/**
* Class JsonFormFieldMatcher
*
* @category JsonFormFieldMatcher
* @package RetailCrm\TestUtils
*/
class JsonFormFieldMatcher extends QueryMatcher
{
use JsonDecoderTrait;
use SeekableStreamDataExtractor;
/** @var string */
private $key;
/**
* @param string $key
* @param string|array<string, mixed> $value
*
* @throws \Pock\Exception\JsonException
*/
public function __construct(string $key, $value)
{
$this->key = $key;
if (is_string($value)) {
parent::__construct(self::jsonDecode($value, true));
} else {
parent::__construct($value);
}
}
/**
* @inheritDoc
*/
public function matches(RequestInterface $request): bool
{
$query = static::parseQuery(static::getStreamData($request->getBody()));
if (empty($query) || !array_key_exists($this->key, $query)) {
return false;
}
try {
$actual = self::jsonDecode($query[$this->key], true);
} catch (JsonException $exception) {
return false;
}
if (null === $actual) {
return false;
}
return ComparatorLocator::get(RecursiveArrayComparator::class)->compare($actual, $this->query);
}
}

View File

@ -0,0 +1,37 @@
<?php
/**
* PHP version 7.3
*
* @category PockBuilder
* @package RetailCrm\TestUtils
*/
namespace RetailCrm\TestUtils;
use Pock\PockBuilder as Base;
/**
* Class PockBuilder
*
* @category PockBuilder
* @package RetailCrm\TestUtils
*/
class PockBuilder extends Base
{
/**
* Match JSON form field using provided JSON string or array.
*
* @param string $name
* @param string|array<string, mixed> $value
*
* @return $this
* @throws \Pock\Exception\JsonException
*/
public function matchJsonFormField(string $name, $value): self
{
$this->addMatcher(new JsonFormFieldMatcher($name, $value));
return $this;
}
}

View File

@ -15,7 +15,7 @@ use Http\Discovery\Psr17FactoryDiscovery;
use InvalidArgumentException; use InvalidArgumentException;
use Liip\Serializer\SerializerInterface; use Liip\Serializer\SerializerInterface;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Pock\PockBuilder; use RetailCrm\TestUtils\PockBuilder;
use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamFactoryInterface; use Psr\Http\Message\StreamFactoryInterface;
@ -51,7 +51,7 @@ abstract class AbstractApiResourceGroupTestCase extends TestCase
/** /**
* @param string $pathFragment * @param string $pathFragment
* *
* @return \Pock\PockBuilder * @return \RetailCrm\TestUtils\PockBuilder
*/ */
protected static function createApiMockBuilder(string $pathFragment): PockBuilder protected static function createApiMockBuilder(string $pathFragment): PockBuilder
{ {
@ -103,7 +103,7 @@ abstract class AbstractApiResourceGroupTestCase extends TestCase
* @param string $path * @param string $path
* @param bool $header * @param bool $header
* *
* @return \Pock\PockBuilder * @return \RetailCrm\TestUtils\PockBuilder
*/ */
protected static function createUnversionedApiMockBuilder(string $path = '', bool $header = true): PockBuilder protected static function createUnversionedApiMockBuilder(string $path = '', bool $header = true): PockBuilder
{ {