|
| 1 | +--- a/src/AbstractRequester.php |
| 2 | ++++ b/src/AbstractRequester.php |
| 3 | +@@ -126,7 +126,7 @@ abstract class AbstractRequester |
| 4 | + /** |
| 5 | + * @param array|null $query |
| 6 | + * @return $this |
| 7 | + */ |
| 8 | +- public function withQuery(array $query = null): self |
| 9 | ++ public function withQuery(?array $query = null): self |
| 10 | + { |
| 11 | + $uri = $this->psr7Request->getUri(); |
| 12 | + |
| 13 | +--- a/src/ApiTestCase.php |
| 14 | ++++ b/src/ApiTestCase.php |
| 15 | +@@ -80,8 +80,8 @@ abstract class ApiTestCase extends TestCase |
| 16 | + string $method, |
| 17 | + string $path, |
| 18 | + int $statusExpected = 200, |
| 19 | + string|array|null $query = null, |
| 20 | +- array|string $requestBody = null, |
| 21 | ++ array|string|null $requestBody = null, |
| 22 | + array $requestHeader = [] |
| 23 | + ): ResponseInterface { |
| 24 | + $this->checkSchema(); |
| 25 | +@@ -137,8 +137,8 @@ abstract class ApiTestCase extends TestCase |
| 26 | + |
| 27 | + return $body; |
| 28 | + } |
| 29 | + |
| 30 | +- public function assertRequestException(AbstractRequester $request, string $exceptionClass, string $exceptionMessage = null, bool $matchQueryParams = true): Throwable |
| 31 | ++ public function assertRequestException(AbstractRequester $request, string $exceptionClass, ?string $exceptionMessage = null, bool $matchQueryParams = true): Throwable |
| 32 | + { |
| 33 | + try { |
| 34 | + $this->assertRequest($request, $matchQueryParams); |
| 35 | +--- a/src/Exception/BaseException.php |
| 36 | ++++ b/src/Exception/BaseException.php |
| 37 | +@@ -9,7 +9,7 @@ class BaseException extends Exception |
| 38 | + { |
| 39 | + protected mixed $body; |
| 40 | + |
| 41 | +- public function __construct($message = "", $body = [], $code = 0, Throwable $previous = null) |
| 42 | ++ public function __construct($message = "", $body = [], $code = 0, ?Throwable $previous = null) |
| 43 | + { |
| 44 | + $this->body = $body; |
| 45 | + if (!empty($body)) { |
| 46 | + |
| 47 | +--- a/src/Base/Body.php |
| 48 | ++++ b/src/Base/Body.php |
| 49 | +@@ -328,6 +328,50 @@ |
| 50 | + return true; |
| 51 | + } |
| 52 | + |
| 53 | ++ protected function mergeAllOfSchemas(array $schemas): array |
| 54 | ++ { |
| 55 | ++ $mergedSchema = []; |
| 56 | ++ |
| 57 | ++ foreach ($schemas as $schema) { |
| 58 | ++ if (isset($schema['$ref'])) { |
| 59 | ++ $schema = $this->schema->getDefinition($schema['$ref']); |
| 60 | ++ } |
| 61 | ++ |
| 62 | ++ $mergedSchema = $this->mergeSchemaDefinitions($mergedSchema, $schema); |
| 63 | ++ } |
| 64 | ++ |
| 65 | ++ return $mergedSchema; |
| 66 | ++ } |
| 67 | ++ |
| 68 | ++ protected function mergeSchemaDefinitions(array $base, array $append): array |
| 69 | ++ { |
| 70 | ++ foreach ($append as $key => $value) { |
| 71 | ++ if (!array_key_exists($key, $base)) { |
| 72 | ++ $base[$key] = $value; |
| 73 | ++ continue; |
| 74 | ++ } |
| 75 | ++ |
| 76 | ++ if (($key === self::SWAGGER_REQUIRED || $key === 'enum') && is_array($base[$key]) && is_array($value)) { |
| 77 | ++ $base[$key] = array_values(array_unique(array_merge($base[$key], $value), SORT_REGULAR)); |
| 78 | ++ continue; |
| 79 | ++ } |
| 80 | ++ |
| 81 | ++ if (is_array($base[$key]) && is_array($value) && $this->isAssociativeArray($base[$key]) && $this->isAssociativeArray($value)) { |
| 82 | ++ $base[$key] = $this->mergeSchemaDefinitions($base[$key], $value); |
| 83 | ++ continue; |
| 84 | ++ } |
| 85 | ++ |
| 86 | ++ $base[$key] = $value; |
| 87 | ++ } |
| 88 | ++ |
| 89 | ++ return $base; |
| 90 | ++ } |
| 91 | ++ |
| 92 | ++ protected function isAssociativeArray(array $value): bool |
| 93 | ++ { |
| 94 | ++ return array_keys($value) !== range(0, count($value) - 1); |
| 95 | ++ } |
| 96 | ++ |
| 97 | + /** |
| 98 | + * @param string $name |
| 99 | + * @param array $schemaArray |
| 100 | +@@ -362,27 +406,21 @@ |
| 101 | + } |
| 102 | + |
| 103 | + if (isset($schemaArray['allOf'])) { |
| 104 | +- $allOfSchemas = $schemaArray['allOf']; |
| 105 | +- foreach ($allOfSchemas as &$schema) { |
| 106 | +- if (isset($schema['$ref'])) { |
| 107 | +- $schema = $this->schema->getDefinition($schema['$ref']); |
| 108 | +- } |
| 109 | +- } |
| 110 | +- unset($schema); |
| 111 | +- $mergedSchema = array_merge_recursive(...$allOfSchemas); |
| 112 | +- return $this->matchSchema($name, $mergedSchema, $body); |
| 113 | ++ return $this->matchSchema($name, $this->mergeAllOfSchemas($schemaArray['allOf']), $body); |
| 114 | + } |
| 115 | + |
| 116 | +- if (isset($schemaArray['oneOf'])) { |
| 117 | ++ if (isset($schemaArray['oneOf']) || isset($schemaArray['anyOf'])) { |
| 118 | ++ $schemas = $schemaArray['oneOf'] ?? $schemaArray['anyOf']; |
| 119 | + $matched = false; |
| 120 | + $catchException = null; |
| 121 | +- foreach ($schemaArray['oneOf'] as $schema) { |
| 122 | ++ foreach ($schemas as $schema) { |
| 123 | + try { |
| 124 | + $matched = $matched || $this->matchSchema($name, $schema, $body); |
| 125 | + } catch (NotMatchedException $exception) { |
| 126 | + $catchException = $exception; |
| 127 | + } |
| 128 | + } |
| 129 | ++ |
| 130 | + if ($catchException !== null && $matched === false) { |
| 131 | + throw $catchException; |
| 132 | + } |
0 commit comments