diff --git a/composer.json b/composer.json index b4277b4..d8adcf2 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,7 @@ "nyholm/psr7": "^1.3", "league/event": "^3.0", "league/container": "^3.3", - "neur0toxine/pock": "^0.7" + "neur0toxine/pock": "^0.10" }, "suggest": { "ext-curl": "Most HTTP clients need ext-curl to work properly.", diff --git a/tests/src/Factory/ClientFactoryTest.php b/tests/src/Factory/ClientFactoryTest.php index c9985a4..f9d3b64 100644 --- a/tests/src/Factory/ClientFactoryTest.php +++ b/tests/src/Factory/ClientFactoryTest.php @@ -11,8 +11,12 @@ namespace RetailCrm\Tests\Factory; use Doctrine\Common\Annotations\PsrCachedReader; use Http\Discovery\Psr18ClientDiscovery; +use League\Container\Container; +use League\Event\EventDispatcher; 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\StreamFactoryInterface; use Psr\Http\Message\UriFactoryInterface; @@ -21,20 +25,15 @@ use RetailCrm\Api\Enum\CacheDirectories; use RetailCrm\Api\Factory\ClientFactory; use RetailCrm\Api\Handler\Request\CallbackRequestHandler; use RetailCrm\Api\Handler\Response\CallbackResponseHandler; +use RetailCrm\Api\Interfaces\ClientFactoryInterface; use RetailCrm\Api\Model\RequestData; -use RetailCrm\Api\Model\Response\Api\ApiVersionsResponse; use RetailCrm\Api\Model\ResponseData; +use RetailCrm\TestUtils\ClientFactoryDependentService; use RetailCrm\TestUtils\ReflectionUtils; use RetailCrm\TestUtils\TestCase\ClientTestCase; use RetailCrm\TestUtils\TestConfig; -use RetailCrm\TestUtils\ClientFactoryDependentService; use Symfony\Component\Cache\Adapter\ArrayAdapter; 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 diff --git a/tests/src/ResourceGroup/AbstractApiResourceGroupTest.php b/tests/src/ResourceGroup/AbstractApiResourceGroupTest.php index d4205f7..2cb123b 100644 --- a/tests/src/ResourceGroup/AbstractApiResourceGroupTest.php +++ b/tests/src/ResourceGroup/AbstractApiResourceGroupTest.php @@ -10,7 +10,6 @@ namespace RetailCrm\Tests\ResourceGroup; use League\Event\EventDispatcher; -use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestInterface; use RetailCrm\Api\Enum\RequestMethod; use RetailCrm\Api\Event\FailureRequestEvent; diff --git a/tests/src/ResourceGroup/CostsTest.php b/tests/src/ResourceGroup/CostsTest.php index 949f4d4..0dc5484 100644 --- a/tests/src/ResourceGroup/CostsTest.php +++ b/tests/src/ResourceGroup/CostsTest.php @@ -10,7 +10,6 @@ namespace RetailCrm\Tests\ResourceGroup; use DateTime; -use Pock\PockBuilder; use RetailCrm\Api\Enum\RequestMethod; use RetailCrm\Api\Model\Entity\Costs\Cost; use RetailCrm\Api\Model\Entity\Source; diff --git a/tests/src/ResourceGroup/PacksTest.php b/tests/src/ResourceGroup/PacksTest.php index 6a9d8af..1f8d499 100644 --- a/tests/src/ResourceGroup/PacksTest.php +++ b/tests/src/ResourceGroup/PacksTest.php @@ -11,7 +11,6 @@ namespace RetailCrm\Tests\ResourceGroup; use DateInterval; use DateTime; -use Pock\PockBuilder; use RetailCrm\Api\Component\Transformer\DateTimeTransformer; use RetailCrm\Api\Enum\RequestMethod; use RetailCrm\Api\Model\Entity\Packs\OrderProductPack; diff --git a/tests/utils/JsonFormFieldMatcher.php b/tests/utils/JsonFormFieldMatcher.php new file mode 100644 index 0000000..51ef1b9 --- /dev/null +++ b/tests/utils/JsonFormFieldMatcher.php @@ -0,0 +1,74 @@ + $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); + } +} diff --git a/tests/utils/PockBuilder.php b/tests/utils/PockBuilder.php new file mode 100644 index 0000000..362ad02 --- /dev/null +++ b/tests/utils/PockBuilder.php @@ -0,0 +1,37 @@ + $value + * + * @return $this + * @throws \Pock\Exception\JsonException + */ + public function matchJsonFormField(string $name, $value): self + { + $this->addMatcher(new JsonFormFieldMatcher($name, $value)); + + return $this; + } +} diff --git a/tests/utils/TestCase/AbstractApiResourceGroupTestCase.php b/tests/utils/TestCase/AbstractApiResourceGroupTestCase.php index 737952c..94cc313 100644 --- a/tests/utils/TestCase/AbstractApiResourceGroupTestCase.php +++ b/tests/utils/TestCase/AbstractApiResourceGroupTestCase.php @@ -15,7 +15,7 @@ use Http\Discovery\Psr17FactoryDiscovery; use InvalidArgumentException; use Liip\Serializer\SerializerInterface; use PHPUnit\Framework\TestCase; -use Pock\PockBuilder; +use RetailCrm\TestUtils\PockBuilder; use Psr\Http\Message\ResponseFactoryInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; @@ -51,7 +51,7 @@ abstract class AbstractApiResourceGroupTestCase extends TestCase /** * @param string $pathFragment * - * @return \Pock\PockBuilder + * @return \RetailCrm\TestUtils\PockBuilder */ protected static function createApiMockBuilder(string $pathFragment): PockBuilder { @@ -103,7 +103,7 @@ abstract class AbstractApiResourceGroupTestCase extends TestCase * @param string $path * @param bool $header * - * @return \Pock\PockBuilder + * @return \RetailCrm\TestUtils\PockBuilder */ protected static function createUnversionedApiMockBuilder(string $path = '', bool $header = true): PockBuilder {