From ea332dcfe682b7e6ee4493fa3712a2e4f65af36d Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Fri, 24 Apr 2026 12:07:08 +0200 Subject: [PATCH 01/16] chore(dependencies): updates --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 075f3b1..abcf203 100644 --- a/composer.json +++ b/composer.json @@ -15,20 +15,20 @@ "cebe/php-openapi": "^1.7", "fakerphp/faker": "^1.20", "league/openapi-psr7-validator": "^0.18", - "thecodingmachine/safe": "^2.4" + "thecodingmachine/safe": "^3.0" }, "require-dev": { "doctrine/coding-standard": "^11", "ergebnis/composer-normalize": "^2.29", - "infection/infection": "^0.26", + "infection/infection": "^0.32", "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.9", - "phpstan/phpstan-phpunit": "^1", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-phpunit": "^2.0", "phpunit/phpunit": "^9.5", - "rector/rector": "^0.15.2", + "rector/rector": "^2.4", "spatie/phpunit-snapshot-assertions": "^4.2", "symfony/var-dumper": "^6", - "thecodingmachine/phpstan-safe-rule": "^1.2" + "thecodingmachine/phpstan-safe-rule": "^1.4" }, "prefer-stable": true, "autoload": { From ea6050aafaeae275c753bc0a22fde678cf000638 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Fri, 24 Apr 2026 12:30:49 +0200 Subject: [PATCH 02/16] chore(phpstan): fix errors --- src/OpenAPIFaker.php | 12 +++++------ src/SchemaFaker/ArrayFaker.php | 4 +--- src/SchemaFaker/BooleanFaker.php | 4 ++-- src/SchemaFaker/NumberFaker.php | 4 ++-- src/SchemaFaker/ObjectFaker.php | 7 +++++-- src/SchemaFaker/SchemaFaker.php | 2 +- src/SchemaFaker/StringFaker.php | 12 +++++------ src/Utils/RegexUtils.php | 14 ++++++------- tests/Integration/E2ETest.php | 12 +++++++---- tests/Integration/OpenAPIFakerTest.php | 20 ++++++++----------- tests/Unit/SchemaFaker/ArrayFakerTest.php | 3 +-- tests/Unit/SchemaFaker/ObjectFakerTest.php | 4 ---- .../SchemaFaker/StaticObjectFakerTest.php | 3 --- tests/Unit/SchemaFaker/StringFakerTest.php | 2 +- 14 files changed, 48 insertions(+), 55 deletions(-) diff --git a/src/OpenAPIFaker.php b/src/OpenAPIFaker.php index 3808682..3f7b8da 100644 --- a/src/OpenAPIFaker.php +++ b/src/OpenAPIFaker.php @@ -24,7 +24,6 @@ use Vural\OpenAPIFaker\SchemaFaker\SchemaFaker; use function array_key_exists; -use function method_exists; use function strtolower; final class OpenAPIFaker @@ -157,11 +156,12 @@ public function mockComponentSchemaForExample(string $schemaName): mixed public function setOptions(array $options): self { foreach ($options as $key => $value) { - if (! method_exists($this->options, 'set' . $key)) { - continue; - } - - $this->options->{'set' . $key}($value); + match ($key) { + 'minItems' => $value !== null ? $this->options->setMinItems($value) : null, + 'maxItems' => $value !== null ? $this->options->setMaxItems($value) : null, + 'alwaysFakeOptionals' => $this->options->setAlwaysFakeOptionals($value), + default => $this->options->setStrategy($value), + }; } return $this; diff --git a/src/SchemaFaker/ArrayFaker.php b/src/SchemaFaker/ArrayFaker.php index cedc746..18b8d2b 100644 --- a/src/SchemaFaker/ArrayFaker.php +++ b/src/SchemaFaker/ArrayFaker.php @@ -30,12 +30,10 @@ public static function generate(Schema $schema, Options $options): array } if ($options->getMinItems() && $minimum < $options->getMinItems()) { - /** @var int $minimum */ $minimum = $options->getMinItems(); } if ($options->getMaxItems() && $maximum > $options->getMaxItems()) { - /** @var int $maximum */ $maximum = $options->getMaxItems(); // Don't allow user to set min items above our maximum @@ -57,7 +55,7 @@ public static function generate(Schema $schema, Options $options): array continue; } - $uniqueData = array_unique($fakeData, is_array($fakeData[0]) ? SORT_REGULAR : SORT_STRING); + $uniqueData = array_unique($fakeData, SORT_REGULAR); if (count($uniqueData) > count($fakeData)) { continue; diff --git a/src/SchemaFaker/BooleanFaker.php b/src/SchemaFaker/BooleanFaker.php index 479205a..cd83eae 100644 --- a/src/SchemaFaker/BooleanFaker.php +++ b/src/SchemaFaker/BooleanFaker.php @@ -25,7 +25,7 @@ public static function generate(Schema $schema, Options $options): bool|null private static function generateDynamic(Schema $schema): bool { - if ($schema->enum !== null) { + if (!empty($schema->enum)) { return Base::randomElement($schema->enum); } @@ -46,7 +46,7 @@ private static function generateStatic(Schema $schema): bool|null return null; } - if ($schema->enum !== null) { + if (!empty($schema->enum)) { $enums = $schema->enum; return reset($enums); diff --git a/src/SchemaFaker/NumberFaker.php b/src/SchemaFaker/NumberFaker.php index 5fe1197..c9539f2 100644 --- a/src/SchemaFaker/NumberFaker.php +++ b/src/SchemaFaker/NumberFaker.php @@ -28,7 +28,7 @@ public static function generate(Schema $schema, Options $options): int|float|nul private static function generateDynamic(Schema $schema): int|float|null { - if ($schema->enum !== null) { + if (!empty($schema->enum)) { return Base::randomElement($schema->enum); } @@ -65,7 +65,7 @@ private static function generateStatic(Schema $schema): int|float|null return null; } - if ($schema->enum !== null) { + if (!empty($schema->enum)) { $enums = $schema->enum; return reset($enums); diff --git a/src/SchemaFaker/ObjectFaker.php b/src/SchemaFaker/ObjectFaker.php index 9dee776..9054700 100644 --- a/src/SchemaFaker/ObjectFaker.php +++ b/src/SchemaFaker/ObjectFaker.php @@ -34,9 +34,12 @@ public static function generate(Schema $schema, Options $options, bool $request $allPropertyKeys = array_merge($requiredKeys, $selectedOptionalKeys); - /** @var Schema $property */ foreach ($schema->properties as $key => $property) { - if ($property instanceof Schema && (($request && $property->readOnly) || (! $request && $property->writeOnly))) { + if (! $property instanceof Schema) { + continue; + } + + if (($request && $property->readOnly) || (! $request && $property->writeOnly)) { continue; } diff --git a/src/SchemaFaker/SchemaFaker.php b/src/SchemaFaker/SchemaFaker.php index 4c67d82..b572c73 100644 --- a/src/SchemaFaker/SchemaFaker.php +++ b/src/SchemaFaker/SchemaFaker.php @@ -52,7 +52,7 @@ public function generate(): array|string|bool|int|float|null return NumberFaker::generate($this->schema, $this->options); } - if ($this->schema->properties !== null) { + if (!empty($this->schema->properties)) { return ObjectFaker::generate($this->schema, $this->options); } diff --git a/src/SchemaFaker/StringFaker.php b/src/SchemaFaker/StringFaker.php index 15e9a76..944b3db 100644 --- a/src/SchemaFaker/StringFaker.php +++ b/src/SchemaFaker/StringFaker.php @@ -38,15 +38,15 @@ public static function generate(Schema $schema, Options $options): string|null private static function generateDynamic(Schema $schema): string { - if ($schema->enum !== null) { + if (!empty($schema->enum)) { return Base::randomElement($schema->enum); } - if ($schema->format !== null) { + if (!empty($schema->format)) { return self::generateDynamicFromFormat($schema); } - if ($schema->pattern !== null) { + if (!empty($schema->pattern)) { return Lorem::regexify($schema->pattern); } @@ -101,17 +101,17 @@ private static function generateStatic(Schema $schema): string|null return null; } - if ($schema->enum !== null) { + if (!empty($schema->enum)) { $enums = $schema->enum; return reset($enums); } - if ($schema->format !== null) { + if (!empty($schema->format)) { return self::generateStaticFromFormat($schema); } - if ($schema->pattern !== null) { + if (!empty($schema->pattern)) { return RegexUtils::generateSample($schema->pattern); } diff --git a/src/Utils/RegexUtils.php b/src/Utils/RegexUtils.php index ef77332..2f04b6e 100644 --- a/src/Utils/RegexUtils.php +++ b/src/Utils/RegexUtils.php @@ -5,8 +5,8 @@ namespace Vural\OpenAPIFaker\Utils; use function explode; -use function preg_replace_callback; use function Safe\preg_replace; +use function Safe\preg_replace_callback; use function str_repeat; use function str_replace; use function str_split; @@ -28,13 +28,13 @@ public static function generateSample(string $regex): string // [12]{1,2} becomes [12] $regex = preg_replace_callback('#(\[[^\]]+\])\{(\d+),(\d+)\}#', static fn ($matches): string => str_repeat($matches[1], (int) $matches[2]), $regex); // (12|34){1,2} becomes (12|34) - $regex = preg_replace_callback('#(\([^\)]+\))\{(\d+),(\d+)\}#', static fn ($matches): string => str_repeat($matches[1], (int) $matches[2]), $regex ?? ''); + $regex = preg_replace_callback('#(\([^\)]+\))\{(\d+),(\d+)\}#', static fn ($matches): string => str_repeat($matches[1], (int) $matches[2]), $regex); // A{1,2} becomes A or \d{3} becomes \d\d\d - $regex = preg_replace_callback('#(\\\?.)\{(\d+),(\d+)\}#', static fn ($matches): string => str_repeat($matches[1], (int) $matches[2]), $regex ?? ''); + $regex = preg_replace_callback('#(\\\?.)\{(\d+),(\d+)\}#', static fn ($matches): string => str_repeat($matches[1], (int) $matches[2]), $regex); // (this|that) becomes 'this' - $regex = preg_replace_callback('#\((.*?)\)#', static fn ($matches): string => explode('|', str_replace(['(', ')'], '', $matches[1]))[0], $regex ?? ''); + $regex = preg_replace_callback('#\((.*?)\)#', static fn ($matches): string => explode('|', str_replace(['(', ')'], '', $matches[1]))[0], $regex); // [A-F] become [A] or [0-9] becomes [0] - $regex = preg_replace_callback('#\[([^\]]+)\]#', static fn ($matches): string => '[' . preg_replace_callback('#(\w|\d)\-(\w|\d)#', static fn ($range): string => $range[1], $matches[1]) . ']', $regex ?? ''); + $regex = preg_replace_callback('#\[([^\]]+)\]#', static fn ($matches): string => '[' . preg_replace_callback('#(\w|\d)\-(\w|\d)#', static fn ($range): string => $range[1], $matches[1]) . ']', $regex); // All [ABC] become A $regex = preg_replace_callback('#\[([^\]]+)\]#', static function ($matches): string { // remove backslashes (that are not followed by another backslash) because they are escape characters @@ -43,9 +43,9 @@ public static function generateSample(string $regex): string //[.] should not be a character, but a literal . return str_replace('.', '\.', $firstElement); - }, $regex ?? ''); + }, $regex); // replace \d with number 1 and \w with letter a - $regex = preg_replace('/\\\w/', 'a', $regex ?? ''); + $regex = preg_replace('/\\\w/', 'a', $regex); $regex = preg_replace('/\\\d/', '1', $regex); //replace . with ! $regex = preg_replace('/(?schema instanceof Schema) { + continue; + } + if ($mediaType->schema->description !== 'Video search results') { continue; } @@ -103,7 +107,7 @@ function it_can_generate_valid_response(string $filename, string $strategy) } } - self::assertTrue(true); + self::addToAssertionCount(1); } /** @@ -133,7 +137,7 @@ function it_can_generate_valid_component(string $filename, string $strategy) } } - self::assertTrue(true); + self::addToAssertionCount(1); } /** @@ -167,7 +171,7 @@ function it_can_generate_valid_component_examples(string $filename, string $stra } } - self::assertTrue(true); + self::addToAssertionCount(1); } /** @return string[][] */ diff --git a/tests/Integration/OpenAPIFakerTest.php b/tests/Integration/OpenAPIFakerTest.php index 386e06c..319608f 100644 --- a/tests/Integration/OpenAPIFakerTest.php +++ b/tests/Integration/OpenAPIFakerTest.php @@ -79,7 +79,7 @@ function it_can_create_faker_from_json() $faker = OpenAPIFaker::createFromJson($specJson); - self::assertInstanceOf(OpenAPIFaker::class, $faker); + self::addToAssertionCount(1); } /** @@ -134,7 +134,7 @@ function it_can_create_faker_from_yaml() $faker = OpenAPIFaker::createFromYaml($specYaml); - self::assertInstanceOf(OpenAPIFaker::class, $faker); + self::addToAssertionCount(1); } /** @@ -190,14 +190,13 @@ function it_can_create_faker_from_schema() $schema = new OpenApi(Yaml::parse($specYaml)); $faker = OpenAPIFaker::createFromSchema($schema); - self::assertInstanceOf(OpenAPIFaker::class, $faker); + self::addToAssertionCount(1); } /** * @test - * @testWith - * ["/todos", "get"] - * ["/todos", "post", "text/plain"] + * @testWith ["/todos", "get"] + * ["/todos", "post", "text/plain"] */ function it_throws_exception_if_request_cannot_be_found(string $path, string $method, string $contentType = 'application/json') { @@ -251,10 +250,9 @@ function it_throws_exception_if_request_cannot_be_found(string $path, string $me /** * @test - * @testWith - * ["/todos", "post"] - * ["/todos", "get", "201"] - * ["/todos", "get", "200", "text/plain"] + * @testWith ["/todos", "post"] + * ["/todos", "get", "201"] + * ["/todos", "get", "200", "text/plain"] */ function it_throws_exception_if_response_cannot_be_found(string $path, string $method, string $statusCode = '200', string $contentType = 'application/json') { @@ -558,8 +556,6 @@ function it_will_mock_the_request() self::assertIsArray($fakeData); self::assertGreaterThanOrEqual(0, count($fakeData)); - - self::assertIsArray($fakeData); self::assertArrayHasKey('id', $fakeData); self::assertIsInt($fakeData['id']); self::assertArrayHasKey('name', $fakeData); diff --git a/tests/Unit/SchemaFaker/ArrayFakerTest.php b/tests/Unit/SchemaFaker/ArrayFakerTest.php index 4b300a7..bff4627 100644 --- a/tests/Unit/SchemaFaker/ArrayFakerTest.php +++ b/tests/Unit/SchemaFaker/ArrayFakerTest.php @@ -12,7 +12,7 @@ use function array_unique; use function count; use function mt_srand; -use function Safe\sort; +use function sort; use const MT_RAND_PHP; @@ -160,7 +160,6 @@ function it_can_generate_unique_elements() JSON, ), $this->options); - self::assertIsArray($fakeData); self::assertCount(5, $fakeData); self::assertSame($fakeData, array_unique($fakeData)); } diff --git a/tests/Unit/SchemaFaker/ObjectFakerTest.php b/tests/Unit/SchemaFaker/ObjectFakerTest.php index d523762..4b41825 100644 --- a/tests/Unit/SchemaFaker/ObjectFakerTest.php +++ b/tests/Unit/SchemaFaker/ObjectFakerTest.php @@ -96,7 +96,6 @@ function it_includes_required_properties_all_the_time() $fakeData = ObjectFaker::generate(SchemaFactory::fromYaml($yaml), $this->options); - self::assertIsArray($fakeData); self::assertArrayHasKey('id', $fakeData); self::assertArrayHasKey('username', $fakeData); $this->assertMatchesJsonSnapshot($fakeData); @@ -130,7 +129,6 @@ function it_can_fake_all_properties_if_always_fake_optionals_option_is_set() $fakeData = ObjectFaker::generate(SchemaFactory::fromYaml($yaml), $options); - self::assertIsArray($fakeData); self::assertCount(6, $fakeData); $this->assertMatchesJsonSnapshot($fakeData); @@ -158,7 +156,6 @@ function it_does_not_inlcude_readonly_properties_when_type_is_request() $fakeData = ObjectFaker::generate(SchemaFactory::fromYaml($yaml), $this->options, true); - self::assertIsArray($fakeData); self::assertArrayNotHasKey('id', $fakeData); self::assertArrayHasKey('username', $fakeData); self::assertArrayHasKey('password', $fakeData); @@ -188,7 +185,6 @@ function it_does_not_inlcude_writeonly_properties_when_type_is_response() $fakeData = ObjectFaker::generate(SchemaFactory::fromYaml($yaml), $this->options); - self::assertIsArray($fakeData); self::assertArrayHasKey('id', $fakeData); self::assertArrayHasKey('username', $fakeData); self::assertArrayNotHasKey('password', $fakeData); diff --git a/tests/Unit/SchemaFaker/StaticObjectFakerTest.php b/tests/Unit/SchemaFaker/StaticObjectFakerTest.php index 00f1bdb..ec4dab8 100644 --- a/tests/Unit/SchemaFaker/StaticObjectFakerTest.php +++ b/tests/Unit/SchemaFaker/StaticObjectFakerTest.php @@ -57,7 +57,6 @@ function it_can_fake_all_properties_if_static_strategy_option_is_set() $fakeData = ObjectFaker::generate(SchemaFactory::fromYaml($yaml), $this->options); - self::assertIsArray($fakeData); self::assertCount(6, $fakeData); $this->assertMatchesJsonSnapshot($fakeData); @@ -83,8 +82,6 @@ function it_can_generate_example_value() $fakeData = ObjectFaker::generate(SchemaFactory::fromYaml($yaml), $this->options); - self::assertIsArray($fakeData); - $this->assertMatchesJsonSnapshot($fakeData); } } diff --git a/tests/Unit/SchemaFaker/StringFakerTest.php b/tests/Unit/SchemaFaker/StringFakerTest.php index 7cadd46..0e7cb71 100644 --- a/tests/Unit/SchemaFaker/StringFakerTest.php +++ b/tests/Unit/SchemaFaker/StringFakerTest.php @@ -11,7 +11,7 @@ use Vural\OpenAPIFaker\Tests\Unit\UnitTestCase; use function filter_var; -use function Safe\sprintf; +use function sprintf; use function strlen; use const FILTER_VALIDATE_URL; From f1395e766d981f3e726d7770fbe3b892c6bae047 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Fri, 24 Apr 2026 12:46:17 +0200 Subject: [PATCH 03/16] fix(tests): update snapshots and fix setOptions unknown key handling Use array_intersect_key to filter unknown keys before dispatching options, preventing UnhandledMatchError at runtime. Update FakerPHP email snapshots to match new generation format. Co-Authored-By: Claude Sonnet 4.6 --- src/OpenAPIFaker.php | 5 ++++- ...properties_if_always_fake_optionals_option_is_set__1.json | 2 +- ...SchemaFakerTest__it_can_merge_schemas_from_all_of__1.json | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/OpenAPIFaker.php b/src/OpenAPIFaker.php index 3f7b8da..5c722f7 100644 --- a/src/OpenAPIFaker.php +++ b/src/OpenAPIFaker.php @@ -23,6 +23,7 @@ use Vural\OpenAPIFaker\SchemaFaker\ResponseFaker; use Vural\OpenAPIFaker\SchemaFaker\SchemaFaker; +use function array_intersect_key; use function array_key_exists; use function strtolower; @@ -155,7 +156,9 @@ public function mockComponentSchemaForExample(string $schemaName): mixed /** @param array{minItems?:?int, maxItems?:?int, alwaysFakeOptionals?:bool, strategy?:string} $options */ public function setOptions(array $options): self { - foreach ($options as $key => $value) { + $knownKeys = ['minItems' => 1, 'maxItems' => 1, 'alwaysFakeOptionals' => 1, 'strategy' => 1]; + + foreach (array_intersect_key($options, $knownKeys) as $key => $value) { match ($key) { 'minItems' => $value !== null ? $this->options->setMinItems($value) : null, 'maxItems' => $value !== null ? $this->options->setMaxItems($value) : null, diff --git a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_fake_all_properties_if_always_fake_optionals_option_is_set__1.json b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_fake_all_properties_if_always_fake_optionals_option_is_set__1.json index e322d77..f4c7080 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_fake_all_properties_if_always_fake_optionals_option_is_set__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_fake_all_properties_if_always_fake_optionals_option_is_set__1.json @@ -4,5 +4,5 @@ "name": "harum", "age": -933357512, "birthdate": [], - "email": "weston94@example.com" + "email": "prohaska.weston@example.net" } diff --git a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_schemas_from_all_of__1.json b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_schemas_from_all_of__1.json index 28efc01..4a1118b 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_schemas_from_all_of__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_schemas_from_all_of__1.json @@ -1,5 +1,5 @@ { "age": 1318086903, "name": "in", - "email": "nader.arno@example.net" + "email": "nader.arnoldo@example.net" } From 0cfa9f945263ce914130eb84025136ab5bc22688 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Fri, 24 Apr 2026 12:52:03 +0200 Subject: [PATCH 04/16] fix(tests): fix MT_RAND_PHP and float modulo PHP 8.4 deprecations Replace MT_RAND_PHP (deprecated in PHP 8.4) with the default MT_RAND_MT19937 algorithm in UnitTestCase and ArrayFakerTest. Replace implicit float-to-int cast in modulo operation with explicit (int) cast. Update all test snapshots to match the new RNG sequence. Co-Authored-By: Claude Sonnet 4.6 --- tests/Unit/SchemaFaker/ArrayFakerTest.php | 2 +- tests/Unit/SchemaFaker/NumberFakerTest.php | 2 +- ...it_can_generate_elements_from_enum__1.json | 15 +++---- ...ayFakerTest__it_can_generate_items__1.json | 7 +-- ..._can_handle_both_min_and_max_items__1.json | 17 ++++--- ...FakerTest__it_can_handle_max_items__1.json | 14 ++++-- ...FakerTest__it_can_handle_min_items__1.json | 13 ++---- ...mum_and_maximum_items_with_options__1.json | 6 +-- ...override_maximum_items_with_option__1.json | 2 +- ...inimum_if_its_greater_than_maximum__1.json | 8 ++-- ...override_minimum_items_with_option__1.json | 24 +++++----- ...akerTest__it_handles_nested_arrays__1.json | 45 ++++++------------- ...s_with_option_if_option_is_greater__1.json | 6 +-- ...s_with_option_if_option_is_smaller__1.json | 6 +-- ...s_15_as_max_items_if_its_not_given__1.json | 7 +-- ...kerTest__it_can_generate_a_integer__1.json | 2 +- ...akerTest__it_can_generate_a_number__1.json | 2 +- ...it_can_generate_elements_from_enum__1.json | 2 +- ...e_both_minimum_and_maximum_keyword__1.json | 2 +- ...n_handle_exclusive_maximum_keyword__1.json | 2 +- ...n_handle_exclusive_minimum_keyword__1.json | 2 +- ...it_can_handle_integer_int32_format__1.json | 2 +- ...it_can_handle_integer_int64_format__1.json | 2 +- ...est__it_can_handle_maximum_keyword__1.json | 2 +- ...est__it_can_handle_minimum_keyword__1.json | 2 +- ...it_can_handle_number_double_format__1.json | 2 +- ..._it_can_handle_number_float_format__1.json | 2 +- ...lways_fake_optionals_option_is_set__1.json | 10 ++--- ...st__it_can_generate_nested_objects__1.json | 5 ++- ...est__it_can_generate_simple_object__1.json | 4 +- ...ly_properties_when_type_is_request__1.json | 4 +- ...y_properties_when_type_is_response__1.json | 4 +- ...s_required_properties_all_the_time__1.json | 7 +-- ...akerTest__it_will_mock_the_request__1.json | 5 ++- ...kerTest__it_will_mock_the_response__1.json | 6 +-- .../SchemaFakerTest__allof_merge__1.json | 6 +-- ...chemaFakerTest__another_merge_test__1.json | 6 +-- ...t_can_choose_one_schema_from_one_of__1.txt | 2 +- ...merge_all_of_with_other_properties__1.json | 11 ++--- ...__it_can_merge_schemas_from_all_of__1.json | 6 +-- ...n_recursively_merge_of_constraints__1.json | 6 +-- ..._merge_all_of_with_existing_schema__1.json | 3 +- ..._merge_one_of_with_existing_schema__1.json | 1 - ..._it_can_generate_elements_from_enum__1.txt | 2 +- ...Test__it_can_generate_single_string__1.txt | 2 +- ...erTest__it_can_handle_binary_format__1.txt | 2 +- ...akerTest__it_can_handle_byte_format__1.txt | 2 +- ...kerTest__it_can_handle_email_format__1.txt | 2 +- ...Test__it_can_handle_hostname_format__1.txt | 2 +- ...akerTest__it_can_handle_ipv4_format__1.txt | 2 +- ...akerTest__it_can_handle_ipv6_format__1.txt | 2 +- ...FakerTest__it_can_handle_max_length__1.txt | 2 +- ...FakerTest__it_can_handle_min_length__1.txt | 2 +- ...Test__it_can_handle_password_format__1.txt | 2 +- ...ngFakerTest__it_can_handle_patterns__1.txt | 2 +- ...FakerTest__it_can_handle_uri_format__1.txt | 2 +- ...akerTest__it_can_handle_uuid_format__1.txt | 2 +- ...a_string_if_unknown_format_is_given__1.txt | 2 +- tests/Unit/UnitTestCase.php | 4 +- 59 files changed, 145 insertions(+), 173 deletions(-) diff --git a/tests/Unit/SchemaFaker/ArrayFakerTest.php b/tests/Unit/SchemaFaker/ArrayFakerTest.php index bff4627..08453d9 100644 --- a/tests/Unit/SchemaFaker/ArrayFakerTest.php +++ b/tests/Unit/SchemaFaker/ArrayFakerTest.php @@ -142,7 +142,7 @@ function it_handles_nested_arrays() /** @test */ function it_can_generate_unique_elements() { - mt_srand(227, MT_RAND_PHP); + mt_srand(227); $fakeData = ArrayFaker::generate(SchemaFactory::fromJson( <<<'JSON' diff --git a/tests/Unit/SchemaFaker/NumberFakerTest.php b/tests/Unit/SchemaFaker/NumberFakerTest.php index db296a6..b9d5b25 100644 --- a/tests/Unit/SchemaFaker/NumberFakerTest.php +++ b/tests/Unit/SchemaFaker/NumberFakerTest.php @@ -229,7 +229,7 @@ function it_can_handle_multiple_of_keyword_with_float_number() $fakeData = NumberFaker::generate(SchemaFactory::fromYaml($yaml), $this->options); self::assertIsFloat($fakeData); - self::assertSame(0, $fakeData % 8); + self::assertSame(0, (int) $fakeData % 8); } /** @test */ diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_generate_elements_from_enum__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_generate_elements_from_enum__1.json index 63da332..e805179 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_generate_elements_from_enum__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_generate_elements_from_enum__1.json @@ -1,18 +1,13 @@ [ - 88, - 88, - 4, - 88, - 4, - 4, 6789, - 88, 6789, - 6789, - 4, 4, 4, + 88, + 6789, 4, 4, - 88 + 6789, + 88, + 4 ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_generate_items__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_generate_items__1.json index 266ba2e..745aeb3 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_generate_items__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_generate_items__1.json @@ -1,8 +1,3 @@ [ - "laborum", - "in", - "eaque", - "harum", - "veniam", - "veritatis" + "odit" ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_both_min_and_max_items__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_both_min_and_max_items__1.json index 4040373..796b3c0 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_both_min_and_max_items__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_both_min_and_max_items__1.json @@ -1,11 +1,10 @@ [ - "laborum", - "in", - "eaque", - "harum", - "veniam", - "veritatis", - "cumque", - "totam", - "reiciendis" + "odit", + "nobis", + "aut", + "placeat", + "qui", + "ut", + "dolores", + "aspernatur" ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_max_items__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_max_items__1.json index 2e4e9b1..c793fa2 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_max_items__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_max_items__1.json @@ -1,6 +1,12 @@ [ - "laborum", - "in", - "eaque", - "harum" + "odit", + "nobis", + "aut", + "placeat", + "qui", + "ut", + "dolores", + "aspernatur", + "ut", + "qui" ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_min_items__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_min_items__1.json index 4040373..1196e02 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_min_items__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_handle_min_items__1.json @@ -1,11 +1,6 @@ [ - "laborum", - "in", - "eaque", - "harum", - "veniam", - "veritatis", - "cumque", - "totam", - "reiciendis" + "odit", + "nobis", + "aut", + "placeat" ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_both_minimum_and_maximum_items_with_options__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_both_minimum_and_maximum_items_with_options__1.json index 2f5b864..c7eefbc 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_both_minimum_and_maximum_items_with_options__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_both_minimum_and_maximum_items_with_options__1.json @@ -1,5 +1,5 @@ [ - 488690146, - 321051476, - -1983034482 + -474531056, + 321051478, + 2002428260 ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_maximum_items_with_option__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_maximum_items_with_option__1.json index 0708075..2f36e51 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_maximum_items_with_option__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_maximum_items_with_option__1.json @@ -1,3 +1,3 @@ [ - 488690146 + -474531056 ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_minimum_if_its_greater_than_maximum__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_minimum_if_its_greater_than_maximum__1.json index d8bbd19..7fd11cb 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_minimum_if_its_greater_than_maximum__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_minimum_if_its_greater_than_maximum__1.json @@ -1,6 +1,6 @@ [ - 488690146, - 321051476, - -1983034482, - 572039736 + -474531056, + 321051478, + 2002428260, + -594589483 ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_minimum_items_with_option__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_minimum_items_with_option__1.json index a88793a..70a0bdc 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_minimum_items_with_option__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_can_override_minimum_items_with_option__1.json @@ -1,12 +1,16 @@ [ - 488690146, - 321051476, - -1983034482, - 572039736, - -933357512, - -1879644922, - 858398568, - -142637466, - 2046609882, - 1911609916 + -474531056, + 321051478, + 2002428260, + -594589483, + -933357510, + -1879644920, + 858398570, + -142637464, + -2023021769, + 1911609918, + 1732967516, + 1885698592, + -1817074197, + 1131664203 ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_handles_nested_arrays__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_handles_nested_arrays__1.json index 53aa8b7..8cab2bb 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_handles_nested_arrays__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_handles_nested_arrays__1.json @@ -1,38 +1,19 @@ [ [ - "in", - "eaque", - "harum", - "veniam", - "veritatis", - "cumque", - "totam", - "reiciendis", - "rerum" - ], - [ - "inventore" - ], - [ - "et" - ], - [ - "perspiciatis", - "ad", - "et" - ], - [ - "reprehenderit", - "quam", - "voluptates", - "non", - "odio" - ], - [ + "nobis", + "aut", "placeat", - "nihil", + "qui", + "ut", + "dolores", + "aspernatur", "ut", - "possimus", - "cumque" + "qui", + "eius", + "aperiam", + "qui", + "voluptatum", + "iste", + "est" ] ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_not_override_maximum_items_with_option_if_option_is_greater__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_not_override_maximum_items_with_option_if_option_is_greater__1.json index 2f5b864..c7eefbc 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_not_override_maximum_items_with_option_if_option_is_greater__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_not_override_maximum_items_with_option_if_option_is_greater__1.json @@ -1,5 +1,5 @@ [ - 488690146, - 321051476, - -1983034482 + -474531056, + 321051478, + 2002428260 ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_not_override_minimum_items_with_option_if_option_is_smaller__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_not_override_minimum_items_with_option_if_option_is_smaller__1.json index 2f5b864..c7eefbc 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_not_override_minimum_items_with_option_if_option_is_smaller__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_not_override_minimum_items_with_option_if_option_is_smaller__1.json @@ -1,5 +1,5 @@ [ - 488690146, - 321051476, - -1983034482 + -474531056, + 321051478, + 2002428260 ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_use_minimum_plus_15_as_max_items_if_its_not_given__1.json b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_use_minimum_plus_15_as_max_items_if_its_not_given__1.json index 266ba2e..745aeb3 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_use_minimum_plus_15_as_max_items_if_its_not_given__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ArrayFakerTest__it_will_use_minimum_plus_15_as_max_items_if_its_not_given__1.json @@ -1,8 +1,3 @@ [ - "laborum", - "in", - "eaque", - "harum", - "veniam", - "veritatis" + "odit" ] diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_a_integer__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_a_integer__1.json index e2ca84c..7e01bbd 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_a_integer__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_a_integer__1.json @@ -1 +1 @@ --472434772 +490790210 diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_a_number__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_a_number__1.json index 7d392d9..c3ac6fc 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_a_number__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_a_number__1.json @@ -1 +1 @@ -488690147 +-474531057.0000001 diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_elements_from_enum__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_elements_from_enum__1.json index 80ef413..6b2a722 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_elements_from_enum__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_generate_elements_from_enum__1.json @@ -1 +1 @@ --123.321 +1010.9865 diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_both_minimum_and_maximum_keyword__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_both_minimum_and_maximum_keyword__1.json index d932c05..8f4b30e 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_both_minimum_and_maximum_keyword__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_both_minimum_and_maximum_keyword__1.json @@ -1 +1 @@ -161.378 +138.9514629 diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_exclusive_maximum_keyword__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_exclusive_maximum_keyword__1.json index 29d6383..398050c 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_exclusive_maximum_keyword__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_exclusive_maximum_keyword__1.json @@ -1 +1 @@ -100 +101 diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_exclusive_minimum_keyword__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_exclusive_minimum_keyword__1.json index 398050c..257e563 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_exclusive_minimum_keyword__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_exclusive_minimum_keyword__1.json @@ -1 +1 @@ -101 +102 diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_integer_int32_format__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_integer_int32_format__1.json index e2ca84c..7e01bbd 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_integer_int32_format__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_integer_int32_format__1.json @@ -1 +1 @@ --472434772 +490790210 diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_integer_int64_format__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_integer_int64_format__1.json index e2ca84c..7e01bbd 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_integer_int64_format__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_integer_int64_format__1.json @@ -1 +1 @@ --472434772 +490790210 diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_maximum_keyword__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_maximum_keyword__1.json index 0c32d34..4a1f959 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_maximum_keyword__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_maximum_keyword__1.json @@ -1 +1 @@ --1309959170 +-474531056 diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_minimum_keyword__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_minimum_keyword__1.json index 9d8a4d0..cbee5d2 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_minimum_keyword__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_minimum_keyword__1.json @@ -1 +1 @@ -837524498 +490790409 diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_number_double_format__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_number_double_format__1.json index 7d392d9..c3ac6fc 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_number_double_format__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_number_double_format__1.json @@ -1 +1 @@ -488690147 +-474531057.0000001 diff --git a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_number_float_format__1.json b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_number_float_format__1.json index 7d392d9..c3ac6fc 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_number_float_format__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/NumberFakerTest__it_can_handle_number_float_format__1.json @@ -1 +1 @@ -488690147 +-474531057.0000001 diff --git a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_fake_all_properties_if_always_fake_optionals_option_is_set__1.json b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_fake_all_properties_if_always_fake_optionals_option_is_set__1.json index f4c7080..4ce37b8 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_fake_all_properties_if_always_fake_optionals_option_is_set__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_fake_all_properties_if_always_fake_optionals_option_is_set__1.json @@ -1,8 +1,8 @@ { - "id": 321051476, - "username": "eaque", - "name": "harum", - "age": -933357512, + "id": 2002428260, + "username": "placeat", + "name": "qui", + "age": -1879644920, "birthdate": [], - "email": "prohaska.weston@example.net" + "email": "tess.crooks@example.com" } diff --git a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_generate_nested_objects__1.json b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_generate_nested_objects__1.json index eb0673d..5288110 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_generate_nested_objects__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_generate_nested_objects__1.json @@ -1,3 +1,6 @@ { - "name": "in" + "contact_info": { + "email": "polly.kessler@example.net", + "phone": "qui" + } } diff --git a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_generate_simple_object__1.json b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_generate_simple_object__1.json index eb0673d..fe51488 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_generate_simple_object__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_can_generate_simple_object__1.json @@ -1,3 +1 @@ -{ - "name": "in" -} +[] diff --git a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_does_not_inlcude_readonly_properties_when_type_is_request__1.json b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_does_not_inlcude_readonly_properties_when_type_is_request__1.json index 6900424..a5624c6 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_does_not_inlcude_readonly_properties_when_type_is_request__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_does_not_inlcude_readonly_properties_when_type_is_request__1.json @@ -1,4 +1,4 @@ { - "username": "laborum", - "password": "in" + "username": "odit", + "password": "nobis" } diff --git a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_does_not_inlcude_writeonly_properties_when_type_is_response__1.json b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_does_not_inlcude_writeonly_properties_when_type_is_response__1.json index f60b676..15a6577 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_does_not_inlcude_writeonly_properties_when_type_is_response__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_does_not_inlcude_writeonly_properties_when_type_is_response__1.json @@ -1,4 +1,4 @@ { - "id": 488690146, - "username": "in" + "id": -474531056, + "username": "nobis" } diff --git a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_includes_required_properties_all_the_time__1.json b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_includes_required_properties_all_the_time__1.json index 3df0a16..f4794dd 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_includes_required_properties_all_the_time__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ObjectFakerTest__it_includes_required_properties_all_the_time__1.json @@ -1,5 +1,6 @@ { - "id": 321051476, - "username": "eaque", - "birthdate": [] + "id": 2002428260, + "username": "placeat", + "age": -933357510, + "email": "ppouros@example.net" } diff --git a/tests/Unit/SchemaFaker/__snapshots__/RequestFakerTest__it_will_mock_the_request__1.json b/tests/Unit/SchemaFaker/__snapshots__/RequestFakerTest__it_will_mock_the_request__1.json index 544344e..716fbe6 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/RequestFakerTest__it_will_mock_the_request__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/RequestFakerTest__it_will_mock_the_request__1.json @@ -1,4 +1,5 @@ { - "id": 488690146, - "name": "in" + "id": 321051478, + "name": "aut", + "tag": "placeat" } diff --git a/tests/Unit/SchemaFaker/__snapshots__/ResponseFakerTest__it_will_mock_the_response__1.json b/tests/Unit/SchemaFaker/__snapshots__/ResponseFakerTest__it_will_mock_the_response__1.json index af93109..036b549 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/ResponseFakerTest__it_will_mock_the_response__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/ResponseFakerTest__it_will_mock_the_response__1.json @@ -1,7 +1,7 @@ { "todo": { - "id": -1983034482, - "name": "harum", - "tag": "veniam" + "id": 2002428260, + "name": "placeat", + "tag": "qui" } } diff --git a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__allof_merge__1.json b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__allof_merge__1.json index fb493fe..885ccab 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__allof_merge__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__allof_merge__1.json @@ -1,6 +1,6 @@ { - "status": 321051476, + "status": 321051478, "type": "about:blank", - "detail": "harum", - "title": "veniam" + "detail": "placeat", + "title": "qui" } diff --git a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__another_merge_test__1.json b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__another_merge_test__1.json index b56e554..dd02460 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__another_merge_test__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__another_merge_test__1.json @@ -1,6 +1,6 @@ { - "status": 321051476, + "status": 321051478, "type": "http:\/\/example.com", - "detail": "harum", - "title": "veniam" + "detail": "placeat", + "title": "qui" } diff --git a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_choose_one_schema_from_one_of__1.txt b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_choose_one_schema_from_one_of__1.txt index 9bbd50d..2ca78cb 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_choose_one_schema_from_one_of__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_choose_one_schema_from_one_of__1.txt @@ -1 +1 @@ -73.254.74.206 \ No newline at end of file +3b0f:db55:a163:48d4:1839:e507:1f69:8667 \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_all_of_with_other_properties__1.json b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_all_of_with_other_properties__1.json index d7a8dd0..c939278 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_all_of_with_other_properties__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_all_of_with_other_properties__1.json @@ -1,11 +1,12 @@ { - "resource_id": "in", + "resource_id": "nobis", "resource_type": "tweet", - "section": "includes", + "section": "data", "type": "https:\/\/api.twitter.com\/labs\/1\/problems\/not-authorized-for-resource", - "detail": "veritatis", - "title": "cumque", + "detail": "ut", + "title": "dolores", "foo": { - "loop": [] + "shiz": "2000-12-03", + "ship": -194250775 } } diff --git a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_schemas_from_all_of__1.json b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_schemas_from_all_of__1.json index 4a1118b..0edcde1 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_schemas_from_all_of__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_schemas_from_all_of__1.json @@ -1,5 +1,5 @@ { - "age": 1318086903, - "name": "in", - "email": "nader.arnoldo@example.net" + "age": 1672952609, + "name": "nobis", + "email": "dheaney@example.net" } diff --git a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_recursively_merge_of_constraints__1.json b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_recursively_merge_of_constraints__1.json index 8c24af7..f8efc45 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_recursively_merge_of_constraints__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_recursively_merge_of_constraints__1.json @@ -1,6 +1,6 @@ { - "baz": "harum", - "bar": "2034-09-26", - "foo": -1879644922, + "baz": "placeat", + "bar": "2196-08-08", + "foo": 858398570, "bap": "compact" } diff --git a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_will_merge_all_of_with_existing_schema__1.json b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_will_merge_all_of_with_existing_schema__1.json index beaf2f3..df78c97 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_will_merge_all_of_with_existing_schema__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_will_merge_all_of_with_existing_schema__1.json @@ -1,3 +1,4 @@ { - "format": "compact" + "format": "compact", + "id": -594589483 } diff --git a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_will_merge_one_of_with_existing_schema__1.json b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_will_merge_one_of_with_existing_schema__1.json index 164ee93..beaf2f3 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_will_merge_one_of_with_existing_schema__1.json +++ b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_will_merge_one_of_with_existing_schema__1.json @@ -1,4 +1,3 @@ { - "id": -1983034482, "format": "compact" } diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_generate_elements_from_enum__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_generate_elements_from_enum__1.txt index ba0e162..1910281 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_generate_elements_from_enum__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_generate_elements_from_enum__1.txt @@ -1 +1 @@ -bar \ No newline at end of file +foo \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_generate_single_string__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_generate_single_string__1.txt index f820d12..d34ed81 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_generate_single_string__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_generate_single_string__1.txt @@ -1 +1 @@ -reprehenderit \ No newline at end of file +laboriosam \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_binary_format__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_binary_format__1.txt index 7167931..b74c3a0 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_binary_format__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_binary_format__1.txt @@ -1 +1 @@ -1110010 1100101 1110000 1110010 1100101 1101000 1100101 1101110 1100100 1100101 1110010 1101001 1110100 \ No newline at end of file +1101100 1100001 1100010 1101111 1110010 1101001 1101111 1110011 1100001 1101101 \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_byte_format__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_byte_format__1.txt index ea33b68..cdd17bf 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_byte_format__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_byte_format__1.txt @@ -1 +1 @@ -cmVwcmVoZW5kZXJpdA== \ No newline at end of file +bGFib3Jpb3NhbQ== \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_email_format__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_email_format__1.txt index 2db2674..e63de33 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_email_format__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_email_format__1.txt @@ -1 +1 @@ -lavonne.batz@example.org \ No newline at end of file +otha.bruen@example.com \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_hostname_format__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_hostname_format__1.txt index e13336e..99a30b7 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_hostname_format__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_hostname_format__1.txt @@ -1 +1 @@ -howell.biz \ No newline at end of file +zulauf.com \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_ipv4_format__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_ipv4_format__1.txt index 72f0b2d..58fad8b 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_ipv4_format__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_ipv4_format__1.txt @@ -1 +1 @@ -206.144.104.240 \ No newline at end of file +100.183.59.15 \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_ipv6_format__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_ipv6_format__1.txt index 88baf42..870c30a 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_ipv6_format__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_ipv6_format__1.txt @@ -1 +1 @@ -63d7:9d20:9322:9cd:a218:485e:ff6:b32a \ No newline at end of file +dd41:3b0f:db55:a163:48d4:1839:e507:1f69 \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_max_length__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_max_length__1.txt index 65f84b7..147cc7c 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_max_length__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_max_length__1.txt @@ -1 +1 @@ -rep \ No newline at end of file +lab \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_min_length__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_min_length__1.txt index 67c0532..1737224 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_min_length__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_min_length__1.txt @@ -1 +1 @@ -reprehenderitlaborumineaque \ No newline at end of file +laboriosamoditnobisautplaceat \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_password_format__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_password_format__1.txt index 1d3bbbf..be9f889 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_password_format__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_password_format__1.txt @@ -1 +1 @@ -EZW$\;&bL| \ No newline at end of file +0~|"aP0FtS \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_patterns__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_patterns__1.txt index 041aae3..49db9ac 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_patterns__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_patterns__1.txt @@ -1 +1 @@ -206-49-9100 \ No newline at end of file +777-38-5390 \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_uri_format__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_uri_format__1.txt index cc6e627..8dbd07f 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_uri_format__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_uri_format__1.txt @@ -1 +1 @@ -http://www.morar.com/harum-veniam-veritatis-cumque \ No newline at end of file +http://okon.com/placeat-qui-ut-dolores-aspernatur-ut \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_uuid_format__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_uuid_format__1.txt index 835b75b..639c037 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_uuid_format__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_can_handle_uuid_format__1.txt @@ -1 +1 @@ -ed362eda-e6a6-3117-a859-04184adc442b \ No newline at end of file +af12c48d-d649-34d9-a6f2-25e7f3549980 \ No newline at end of file diff --git a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_will_return_a_string_if_unknown_format_is_given__1.txt b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_will_return_a_string_if_unknown_format_is_given__1.txt index f820d12..d34ed81 100644 --- a/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_will_return_a_string_if_unknown_format_is_given__1.txt +++ b/tests/Unit/SchemaFaker/__snapshots__/StringFakerTest__it_will_return_a_string_if_unknown_format_is_given__1.txt @@ -1 +1 @@ -reprehenderit \ No newline at end of file +laboriosam \ No newline at end of file diff --git a/tests/Unit/UnitTestCase.php b/tests/Unit/UnitTestCase.php index 9f6cf61..d681492 100644 --- a/tests/Unit/UnitTestCase.php +++ b/tests/Unit/UnitTestCase.php @@ -9,8 +9,6 @@ use function mt_srand; -use const MT_RAND_PHP; - class UnitTestCase extends TestCase { use MatchesSnapshots; @@ -20,6 +18,6 @@ public function setUp(): void parent::setUp(); // Use predefined seed, so we can make realistic assertions - mt_srand((int) 9175, MT_RAND_PHP); + mt_srand(9175); } } From 3bfb4e0c21f5809f17a794a681a171542d39bbb4 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Fri, 24 Apr 2026 13:02:21 +0200 Subject: [PATCH 05/16] fix(ArrayFaker): re-index array after array_unique to avoid associative keys array_unique() preserves original keys, which can leave gaps in integer keys when a duplicate is removed (e.g. [0,1,2,3,4,6,7,8,9] missing 5). League\OpenAPIValidation treats any array with non-sequential keys as an associative array (object), causing validation to fail for schemas with uniqueItems: true (e.g. TweetWithheld.country_codes). Co-Authored-By: Claude Sonnet 4.6 --- src/SchemaFaker/ArrayFaker.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SchemaFaker/ArrayFaker.php b/src/SchemaFaker/ArrayFaker.php index 18b8d2b..a762bc7 100644 --- a/src/SchemaFaker/ArrayFaker.php +++ b/src/SchemaFaker/ArrayFaker.php @@ -9,6 +9,7 @@ use Vural\OpenAPIFaker\Options; use function array_unique; +use function array_values; use function count; use function is_array; @@ -63,7 +64,7 @@ public static function generate(Schema $schema, Options $options): array $i -= count($fakeData) - count($uniqueData); - $fakeData = $uniqueData; + $fakeData = array_values($uniqueData); } return $fakeData; From cc54508a16f94bb7229afc37afb37ca7675df4e0 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Fri, 24 Apr 2026 13:17:35 +0200 Subject: [PATCH 06/16] fix(deps): patch cebe/php-openapi for PHP 8.4 implicit nullable deprecations cebe/php-openapi 1.8.0 (latest, effectively abandoned) uses the old `SomeType $param = null` syntax instead of `?SomeType $param = null` across 9 methods in 6 files. PHP 8.4 emits Deprecated notices for each, causing PHPUnit to mark integration tests as risky (unexpected output). Also bumps cebe/php-openapi to ^1.8 and spatie/phpunit-snapshot-assertions to ^5.3 to remove remaining PHP 8.4 deprecations. Adds cweagans/composer-patches with a single patch file applied automatically on every composer install. Co-Authored-By: Claude Sonnet 4.6 --- composer.json | 15 ++- patches/cebe-php-openapi-php84-nullable.patch | 95 +++++++++++++++++++ 2 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 patches/cebe-php-openapi-php84-nullable.patch diff --git a/composer.json b/composer.json index abcf203..0dde975 100644 --- a/composer.json +++ b/composer.json @@ -12,12 +12,13 @@ "require": { "php": "^8.0", "ext-json": "*", - "cebe/php-openapi": "^1.7", + "cebe/php-openapi": "^1.8", "fakerphp/faker": "^1.20", "league/openapi-psr7-validator": "^0.18", "thecodingmachine/safe": "^3.0" }, "require-dev": { + "cweagans/composer-patches": "^1.7", "doctrine/coding-standard": "^11", "ergebnis/composer-normalize": "^2.29", "infection/infection": "^0.32", @@ -26,10 +27,17 @@ "phpstan/phpstan-phpunit": "^2.0", "phpunit/phpunit": "^9.5", "rector/rector": "^2.4", - "spatie/phpunit-snapshot-assertions": "^4.2", + "spatie/phpunit-snapshot-assertions": "^5.3", "symfony/var-dumper": "^6", "thecodingmachine/phpstan-safe-rule": "^1.4" }, + "extra": { + "patches": { + "cebe/php-openapi": { + "Fix PHP 8.4 implicit nullable parameter deprecations": "patches/cebe-php-openapi-php84-nullable.patch" + } + } + }, "prefer-stable": true, "autoload": { "psr-4": { @@ -47,7 +55,8 @@ "infection/extension-installer": true, "ergebnis/composer-normalize": true, "phpstan/extension-installer": true, - "ocramius/package-versions": true + "ocramius/package-versions": true, + "cweagans/composer-patches": true }, "sort-packages": true }, diff --git a/patches/cebe-php-openapi-php84-nullable.patch b/patches/cebe-php-openapi-php84-nullable.patch new file mode 100644 index 0000000..d8af4ec --- /dev/null +++ b/patches/cebe-php-openapi-php84-nullable.patch @@ -0,0 +1,95 @@ +--- a/src/SpecObjectInterface.php 2026-04-24 13:10:20 ++++ b/src/SpecObjectInterface.php 2026-04-24 13:10:20 +@@ -40,7 +40,7 @@ + /** + * Resolves all Reference Objects in this object and replaces them with their resolution. + */ +- public function resolveReferences(ReferenceContext $context = null); ++ public function resolveReferences(?ReferenceContext $context = null); + + /** + * Set context for all Reference Objects in this object. +--- a/src/SpecBaseObject.php 2026-04-24 13:10:20 ++++ b/src/SpecBaseObject.php 2026-04-24 13:10:20 +@@ -393,7 +393,7 @@ + * Resolves all Reference Objects in this object and replaces them with their resolution. + * @throws exceptions\UnresolvableReferenceException in case resolving a reference fails. + */ +- public function resolveReferences(ReferenceContext $context = null) ++ public function resolveReferences(?ReferenceContext $context = null) + { + // avoid recursion to get stuck in a loop + if ($this->_recursingReferences) { +--- a/src/spec/Paths.php 2026-04-24 13:10:20 ++++ b/src/spec/Paths.php 2026-04-24 13:10:20 +@@ -246,7 +246,7 @@ + * Resolves all Reference Objects in this object and replaces them with their resolution. + * @throws UnresolvableReferenceException + */ +- public function resolveReferences(ReferenceContext $context = null) ++ public function resolveReferences(?ReferenceContext $context = null) + { + foreach ($this->_paths as $key => $path) { + if ($path === null) { +--- a/src/spec/PathItem.php 2026-04-24 13:10:20 ++++ b/src/spec/PathItem.php 2026-04-24 13:10:20 +@@ -150,7 +150,7 @@ + * Resolves all Reference Objects in this object and replaces them with their resolution. + * @throws \cebe\openapi\exceptions\UnresolvableReferenceException in case resolving a reference fails. + */ +- public function resolveReferences(ReferenceContext $context = null) ++ public function resolveReferences(?ReferenceContext $context = null) + { + if ($this->_ref instanceof Reference) { + $pathItem = $this->_ref->resolve($context); +--- a/src/spec/Responses.php 2026-04-24 13:10:20 ++++ b/src/spec/Responses.php 2026-04-24 13:10:20 +@@ -236,7 +236,7 @@ + * Resolves all Reference Objects in this object and replaces them with their resolution. + * @throws UnresolvableReferenceException + */ +- public function resolveReferences(ReferenceContext $context = null) ++ public function resolveReferences(?ReferenceContext $context = null) + { + foreach ($this->_responses as $key => $response) { + if ($response instanceof Reference) { +--- a/src/spec/Callback.php 2026-04-24 13:10:20 ++++ b/src/spec/Callback.php 2026-04-24 13:10:20 +@@ -133,7 +133,7 @@ + * Resolves all Reference Objects in this object and replaces them with their resolution. + * @throws UnresolvableReferenceException + */ +- public function resolveReferences(ReferenceContext $context = null) ++ public function resolveReferences(?ReferenceContext $context = null) + { + if ($this->_pathItem !== null) { + $this->_pathItem->resolveReferences($context); +--- a/src/spec/Reference.php 2026-04-24 13:10:20 ++++ b/src/spec/Reference.php 2026-04-24 13:10:20 +@@ -69,7 +69,7 @@ + * @param string|null $to class name of the type referenced by this Reference + * @throws TypeErrorException in case invalid data is supplied. + */ +- public function __construct(array $data, string $to = null) ++ public function __construct(array $data, ?string $to = null) + { + $this->_rawSpec = $data; + if (!isset($data['$ref'])) { +@@ -176,7 +176,7 @@ + * If you call resolveReferences() make sure to replace the Reference with the resolved object first. + * @throws UnresolvableReferenceException in case of errors. + */ +- public function resolve(ReferenceContext $context = null) ++ public function resolve(?ReferenceContext $context = null) + { + if ($context === null) { + $context = $this->getContext(); +@@ -363,7 +363,7 @@ + * Resolves all Reference Objects in this object and replaces them with their resolution. + * @throws UnresolvableReferenceException + */ +- public function resolveReferences(ReferenceContext $context = null) ++ public function resolveReferences(?ReferenceContext $context = null) + { + throw new UnresolvableReferenceException('Cyclic reference detected, resolveReferences() called on a Reference Object.'); + } From 1a5160d502ea96785bdb1420e692b62f47eb51a4 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Mon, 27 Apr 2026 09:45:34 +0200 Subject: [PATCH 07/16] Revert "fix(deps): patch cebe/php-openapi for PHP 8.4 implicit nullable deprecations" This reverts commit d1292591ef79c39b829bab0773906f3e6d9a7c55. --- composer.json | 15 +-- patches/cebe-php-openapi-php84-nullable.patch | 95 ------------------- 2 files changed, 3 insertions(+), 107 deletions(-) delete mode 100644 patches/cebe-php-openapi-php84-nullable.patch diff --git a/composer.json b/composer.json index 0dde975..abcf203 100644 --- a/composer.json +++ b/composer.json @@ -12,13 +12,12 @@ "require": { "php": "^8.0", "ext-json": "*", - "cebe/php-openapi": "^1.8", + "cebe/php-openapi": "^1.7", "fakerphp/faker": "^1.20", "league/openapi-psr7-validator": "^0.18", "thecodingmachine/safe": "^3.0" }, "require-dev": { - "cweagans/composer-patches": "^1.7", "doctrine/coding-standard": "^11", "ergebnis/composer-normalize": "^2.29", "infection/infection": "^0.32", @@ -27,17 +26,10 @@ "phpstan/phpstan-phpunit": "^2.0", "phpunit/phpunit": "^9.5", "rector/rector": "^2.4", - "spatie/phpunit-snapshot-assertions": "^5.3", + "spatie/phpunit-snapshot-assertions": "^4.2", "symfony/var-dumper": "^6", "thecodingmachine/phpstan-safe-rule": "^1.4" }, - "extra": { - "patches": { - "cebe/php-openapi": { - "Fix PHP 8.4 implicit nullable parameter deprecations": "patches/cebe-php-openapi-php84-nullable.patch" - } - } - }, "prefer-stable": true, "autoload": { "psr-4": { @@ -55,8 +47,7 @@ "infection/extension-installer": true, "ergebnis/composer-normalize": true, "phpstan/extension-installer": true, - "ocramius/package-versions": true, - "cweagans/composer-patches": true + "ocramius/package-versions": true }, "sort-packages": true }, diff --git a/patches/cebe-php-openapi-php84-nullable.patch b/patches/cebe-php-openapi-php84-nullable.patch deleted file mode 100644 index d8af4ec..0000000 --- a/patches/cebe-php-openapi-php84-nullable.patch +++ /dev/null @@ -1,95 +0,0 @@ ---- a/src/SpecObjectInterface.php 2026-04-24 13:10:20 -+++ b/src/SpecObjectInterface.php 2026-04-24 13:10:20 -@@ -40,7 +40,7 @@ - /** - * Resolves all Reference Objects in this object and replaces them with their resolution. - */ -- public function resolveReferences(ReferenceContext $context = null); -+ public function resolveReferences(?ReferenceContext $context = null); - - /** - * Set context for all Reference Objects in this object. ---- a/src/SpecBaseObject.php 2026-04-24 13:10:20 -+++ b/src/SpecBaseObject.php 2026-04-24 13:10:20 -@@ -393,7 +393,7 @@ - * Resolves all Reference Objects in this object and replaces them with their resolution. - * @throws exceptions\UnresolvableReferenceException in case resolving a reference fails. - */ -- public function resolveReferences(ReferenceContext $context = null) -+ public function resolveReferences(?ReferenceContext $context = null) - { - // avoid recursion to get stuck in a loop - if ($this->_recursingReferences) { ---- a/src/spec/Paths.php 2026-04-24 13:10:20 -+++ b/src/spec/Paths.php 2026-04-24 13:10:20 -@@ -246,7 +246,7 @@ - * Resolves all Reference Objects in this object and replaces them with their resolution. - * @throws UnresolvableReferenceException - */ -- public function resolveReferences(ReferenceContext $context = null) -+ public function resolveReferences(?ReferenceContext $context = null) - { - foreach ($this->_paths as $key => $path) { - if ($path === null) { ---- a/src/spec/PathItem.php 2026-04-24 13:10:20 -+++ b/src/spec/PathItem.php 2026-04-24 13:10:20 -@@ -150,7 +150,7 @@ - * Resolves all Reference Objects in this object and replaces them with their resolution. - * @throws \cebe\openapi\exceptions\UnresolvableReferenceException in case resolving a reference fails. - */ -- public function resolveReferences(ReferenceContext $context = null) -+ public function resolveReferences(?ReferenceContext $context = null) - { - if ($this->_ref instanceof Reference) { - $pathItem = $this->_ref->resolve($context); ---- a/src/spec/Responses.php 2026-04-24 13:10:20 -+++ b/src/spec/Responses.php 2026-04-24 13:10:20 -@@ -236,7 +236,7 @@ - * Resolves all Reference Objects in this object and replaces them with their resolution. - * @throws UnresolvableReferenceException - */ -- public function resolveReferences(ReferenceContext $context = null) -+ public function resolveReferences(?ReferenceContext $context = null) - { - foreach ($this->_responses as $key => $response) { - if ($response instanceof Reference) { ---- a/src/spec/Callback.php 2026-04-24 13:10:20 -+++ b/src/spec/Callback.php 2026-04-24 13:10:20 -@@ -133,7 +133,7 @@ - * Resolves all Reference Objects in this object and replaces them with their resolution. - * @throws UnresolvableReferenceException - */ -- public function resolveReferences(ReferenceContext $context = null) -+ public function resolveReferences(?ReferenceContext $context = null) - { - if ($this->_pathItem !== null) { - $this->_pathItem->resolveReferences($context); ---- a/src/spec/Reference.php 2026-04-24 13:10:20 -+++ b/src/spec/Reference.php 2026-04-24 13:10:20 -@@ -69,7 +69,7 @@ - * @param string|null $to class name of the type referenced by this Reference - * @throws TypeErrorException in case invalid data is supplied. - */ -- public function __construct(array $data, string $to = null) -+ public function __construct(array $data, ?string $to = null) - { - $this->_rawSpec = $data; - if (!isset($data['$ref'])) { -@@ -176,7 +176,7 @@ - * If you call resolveReferences() make sure to replace the Reference with the resolved object first. - * @throws UnresolvableReferenceException in case of errors. - */ -- public function resolve(ReferenceContext $context = null) -+ public function resolve(?ReferenceContext $context = null) - { - if ($context === null) { - $context = $this->getContext(); -@@ -363,7 +363,7 @@ - * Resolves all Reference Objects in this object and replaces them with their resolution. - * @throws UnresolvableReferenceException - */ -- public function resolveReferences(ReferenceContext $context = null) -+ public function resolveReferences(?ReferenceContext $context = null) - { - throw new UnresolvableReferenceException('Cyclic reference detected, resolveReferences() called on a Reference Object.'); - } From b863756fe1f42d0a70923bb8ff5af1223df3d0ae Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Mon, 27 Apr 2026 12:43:03 +0200 Subject: [PATCH 08/16] chore: fix empty usages --- src/SchemaFaker/StringFaker.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SchemaFaker/StringFaker.php b/src/SchemaFaker/StringFaker.php index 944b3db..2f7a704 100644 --- a/src/SchemaFaker/StringFaker.php +++ b/src/SchemaFaker/StringFaker.php @@ -38,15 +38,15 @@ public static function generate(Schema $schema, Options $options): string|null private static function generateDynamic(Schema $schema): string { - if (!empty($schema->enum)) { + if ($schema->enum !== null) { return Base::randomElement($schema->enum); } - if (!empty($schema->format)) { + if ($schema->format !== null) { return self::generateDynamicFromFormat($schema); } - if (!empty($schema->pattern)) { + if ($schema->pattern !== null) { return Lorem::regexify($schema->pattern); } From dfac95679755b1729858ba174502ba96e807de68 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Mon, 27 Apr 2026 12:43:21 +0200 Subject: [PATCH 09/16] chore: remove useless const --- tests/Integration/OpenAPIFakerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/OpenAPIFakerTest.php b/tests/Integration/OpenAPIFakerTest.php index 319608f..ed79f85 100644 --- a/tests/Integration/OpenAPIFakerTest.php +++ b/tests/Integration/OpenAPIFakerTest.php @@ -79,7 +79,7 @@ function it_can_create_faker_from_json() $faker = OpenAPIFaker::createFromJson($specJson); - self::addToAssertionCount(1); + self::assertInstanceOf(OpenAPIFaker::class, $faker); } /** @@ -134,7 +134,7 @@ function it_can_create_faker_from_yaml() $faker = OpenAPIFaker::createFromYaml($specYaml); - self::addToAssertionCount(1); + self::assertInstanceOf(OpenAPIFaker::class, $faker); } /** @@ -190,7 +190,7 @@ function it_can_create_faker_from_schema() $schema = new OpenApi(Yaml::parse($specYaml)); $faker = OpenAPIFaker::createFromSchema($schema); - self::addToAssertionCount(1); + self::assertInstanceOf(OpenAPIFaker::class, $faker); } /** From 2a5f99358636228a9d39660402c76335911181c4 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Mon, 27 Apr 2026 12:44:02 +0200 Subject: [PATCH 10/16] test: keep assertInstanceOf usages --- tests/Unit/SchemaFaker/ArrayFakerTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Unit/SchemaFaker/ArrayFakerTest.php b/tests/Unit/SchemaFaker/ArrayFakerTest.php index 08453d9..38bb01c 100644 --- a/tests/Unit/SchemaFaker/ArrayFakerTest.php +++ b/tests/Unit/SchemaFaker/ArrayFakerTest.php @@ -14,8 +14,6 @@ use function mt_srand; use function sort; -use const MT_RAND_PHP; - /** * @uses \Vural\OpenAPIFaker\SchemaFaker\SchemaFaker * @uses \Vural\OpenAPIFaker\SchemaFaker\StringFaker From 884193395c9ac6c8269a22c585345f74df6e315d Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:43:53 +0200 Subject: [PATCH 11/16] Revert "chore: fix empty usages" This reverts commit 054d5156914eebc15ab2764bd421baf294f40709. --- src/SchemaFaker/StringFaker.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SchemaFaker/StringFaker.php b/src/SchemaFaker/StringFaker.php index 2f7a704..944b3db 100644 --- a/src/SchemaFaker/StringFaker.php +++ b/src/SchemaFaker/StringFaker.php @@ -38,15 +38,15 @@ public static function generate(Schema $schema, Options $options): string|null private static function generateDynamic(Schema $schema): string { - if ($schema->enum !== null) { + if (!empty($schema->enum)) { return Base::randomElement($schema->enum); } - if ($schema->format !== null) { + if (!empty($schema->format)) { return self::generateDynamicFromFormat($schema); } - if ($schema->pattern !== null) { + if (!empty($schema->pattern)) { return Lorem::regexify($schema->pattern); } From 13021437cd71f076c973d011518029375873e211 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Mon, 27 Apr 2026 14:46:35 +0200 Subject: [PATCH 12/16] chore: quickfix phpstan --- tests/Integration/OpenAPIFakerTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Integration/OpenAPIFakerTest.php b/tests/Integration/OpenAPIFakerTest.php index ed79f85..35d5f0a 100644 --- a/tests/Integration/OpenAPIFakerTest.php +++ b/tests/Integration/OpenAPIFakerTest.php @@ -79,7 +79,7 @@ function it_can_create_faker_from_json() $faker = OpenAPIFaker::createFromJson($specJson); - self::assertInstanceOf(OpenAPIFaker::class, $faker); + self::assertInstanceOf(OpenAPIFaker::class, $faker); // @phpstan-ignore-line } /** @@ -134,7 +134,7 @@ function it_can_create_faker_from_yaml() $faker = OpenAPIFaker::createFromYaml($specYaml); - self::assertInstanceOf(OpenAPIFaker::class, $faker); + self::assertInstanceOf(OpenAPIFaker::class, $faker); // @phpstan-ignore-line } /** @@ -190,7 +190,7 @@ function it_can_create_faker_from_schema() $schema = new OpenApi(Yaml::parse($specYaml)); $faker = OpenAPIFaker::createFromSchema($schema); - self::assertInstanceOf(OpenAPIFaker::class, $faker); + self::assertInstanceOf(OpenAPIFaker::class, $faker); // @phpstan-ignore-line } /** From d731c924a4480ad0b9887c356d32a6a4b06ce9ff Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:57:10 +0200 Subject: [PATCH 13/16] chore: fix codestyle --- src/SchemaFaker/ArrayFaker.php | 2 -- src/SchemaFaker/BooleanFaker.php | 4 ++-- src/SchemaFaker/NumberFaker.php | 4 ++-- src/SchemaFaker/SchemaFaker.php | 2 +- src/SchemaFaker/StringFaker.php | 12 ++++++------ 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/SchemaFaker/ArrayFaker.php b/src/SchemaFaker/ArrayFaker.php index a762bc7..956f2e1 100644 --- a/src/SchemaFaker/ArrayFaker.php +++ b/src/SchemaFaker/ArrayFaker.php @@ -11,10 +11,8 @@ use function array_unique; use function array_values; use function count; -use function is_array; use const SORT_REGULAR; -use const SORT_STRING; /** @internal */ final class ArrayFaker diff --git a/src/SchemaFaker/BooleanFaker.php b/src/SchemaFaker/BooleanFaker.php index cd83eae..7996e80 100644 --- a/src/SchemaFaker/BooleanFaker.php +++ b/src/SchemaFaker/BooleanFaker.php @@ -25,7 +25,7 @@ public static function generate(Schema $schema, Options $options): bool|null private static function generateDynamic(Schema $schema): bool { - if (!empty($schema->enum)) { + if (! empty($schema->enum)) { return Base::randomElement($schema->enum); } @@ -46,7 +46,7 @@ private static function generateStatic(Schema $schema): bool|null return null; } - if (!empty($schema->enum)) { + if (! empty($schema->enum)) { $enums = $schema->enum; return reset($enums); diff --git a/src/SchemaFaker/NumberFaker.php b/src/SchemaFaker/NumberFaker.php index c9539f2..38d5823 100644 --- a/src/SchemaFaker/NumberFaker.php +++ b/src/SchemaFaker/NumberFaker.php @@ -28,7 +28,7 @@ public static function generate(Schema $schema, Options $options): int|float|nul private static function generateDynamic(Schema $schema): int|float|null { - if (!empty($schema->enum)) { + if (! empty($schema->enum)) { return Base::randomElement($schema->enum); } @@ -65,7 +65,7 @@ private static function generateStatic(Schema $schema): int|float|null return null; } - if (!empty($schema->enum)) { + if (! empty($schema->enum)) { $enums = $schema->enum; return reset($enums); diff --git a/src/SchemaFaker/SchemaFaker.php b/src/SchemaFaker/SchemaFaker.php index b572c73..1185f2f 100644 --- a/src/SchemaFaker/SchemaFaker.php +++ b/src/SchemaFaker/SchemaFaker.php @@ -52,7 +52,7 @@ public function generate(): array|string|bool|int|float|null return NumberFaker::generate($this->schema, $this->options); } - if (!empty($this->schema->properties)) { + if (! empty($this->schema->properties)) { return ObjectFaker::generate($this->schema, $this->options); } diff --git a/src/SchemaFaker/StringFaker.php b/src/SchemaFaker/StringFaker.php index 944b3db..a665528 100644 --- a/src/SchemaFaker/StringFaker.php +++ b/src/SchemaFaker/StringFaker.php @@ -38,15 +38,15 @@ public static function generate(Schema $schema, Options $options): string|null private static function generateDynamic(Schema $schema): string { - if (!empty($schema->enum)) { + if (! empty($schema->enum)) { return Base::randomElement($schema->enum); } - if (!empty($schema->format)) { + if (! empty($schema->format)) { return self::generateDynamicFromFormat($schema); } - if (!empty($schema->pattern)) { + if (! empty($schema->pattern)) { return Lorem::regexify($schema->pattern); } @@ -101,17 +101,17 @@ private static function generateStatic(Schema $schema): string|null return null; } - if (!empty($schema->enum)) { + if (! empty($schema->enum)) { $enums = $schema->enum; return reset($enums); } - if (!empty($schema->format)) { + if (! empty($schema->format)) { return self::generateStaticFromFormat($schema); } - if (!empty($schema->pattern)) { + if (! empty($schema->pattern)) { return RegexUtils::generateSample($schema->pattern); } From 82b8a87aee18c68b70e6f17a71a86420580b7112 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Mon, 27 Apr 2026 17:08:28 +0200 Subject: [PATCH 14/16] test: remove snapshots usage --- tests/Unit/SchemaFaker/SchemaFakerTest.php | 15 +++++++++++++-- ...can_merge_all_of_with_other_properties__1.json | 12 ------------ ...t_can_recursively_merge_of_constraints__1.json | 6 ------ 3 files changed, 13 insertions(+), 20 deletions(-) delete mode 100644 tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_all_of_with_other_properties__1.json delete mode 100644 tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_recursively_merge_of_constraints__1.json diff --git a/tests/Unit/SchemaFaker/SchemaFakerTest.php b/tests/Unit/SchemaFaker/SchemaFakerTest.php index 60bd485..271e71c 100644 --- a/tests/Unit/SchemaFaker/SchemaFakerTest.php +++ b/tests/Unit/SchemaFaker/SchemaFakerTest.php @@ -12,6 +12,8 @@ use Vural\OpenAPIFaker\Tests\Unit\UnitTestCase; use function array_keys; +use function is_array; +use function is_int; /** * @uses \Vural\OpenAPIFaker\SchemaFaker\StringFaker @@ -179,7 +181,10 @@ function it_can_recursively_merge_of_constraints() self::assertArrayHasKey('bar', $fakeData); self::assertArrayHasKey('baz', $fakeData); self::assertArrayHasKey('bap', $fakeData); - $this->assertMatchesJsonSnapshot($fakeData); + self::assertIsInt($fakeData['foo']); + self::assertMatchesRegularExpression('/^\d{4}-\d{2}-\d{2}$/', $fakeData['bar']); + self::assertIsString($fakeData['baz']); + self::assertSame('compact', $fakeData['bap']); } /** @test */ @@ -255,7 +260,13 @@ enum: self::assertArrayHasKey('type', $fakeData); self::assertArrayHasKey('title', $fakeData); self::assertArrayHasKey('detail', $fakeData); - $this->assertMatchesJsonSnapshot($fakeData); + self::assertIsString($fakeData['resource_id']); + self::assertSame('tweet', $fakeData['resource_type']); + self::assertContains($fakeData['section'], ['data', 'includes']); + self::assertSame('https://api.twitter.com/labs/1/problems/not-authorized-for-resource', $fakeData['type']); + self::assertIsString($fakeData['title']); + self::assertIsString($fakeData['detail']); + self::assertTrue(is_int($fakeData['foo']) || is_array($fakeData['foo'])); } /** @test */ diff --git a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_all_of_with_other_properties__1.json b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_all_of_with_other_properties__1.json deleted file mode 100644 index c939278..0000000 --- a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_merge_all_of_with_other_properties__1.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "resource_id": "nobis", - "resource_type": "tweet", - "section": "data", - "type": "https:\/\/api.twitter.com\/labs\/1\/problems\/not-authorized-for-resource", - "detail": "ut", - "title": "dolores", - "foo": { - "shiz": "2000-12-03", - "ship": -194250775 - } -} diff --git a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_recursively_merge_of_constraints__1.json b/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_recursively_merge_of_constraints__1.json deleted file mode 100644 index f8efc45..0000000 --- a/tests/Unit/SchemaFaker/__snapshots__/SchemaFakerTest__it_can_recursively_merge_of_constraints__1.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "baz": "placeat", - "bar": "2196-08-08", - "foo": 858398570, - "bap": "compact" -} From e7c1e10beac1bdc4143426373aad342dd100f537 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Mon, 27 Apr 2026 17:17:32 +0200 Subject: [PATCH 15/16] chore: require php 8.4.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index abcf203..5d27ae5 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": "^8.0", + "php": "^8.4.2", "ext-json": "*", "cebe/php-openapi": "^1.7", "fakerphp/faker": "^1.20", From b4eb74a13254789b274cf7e81362f79b664cdc70 Mon Sep 17 00:00:00 2001 From: Nicolas Mugnier <6680190+NicolasMugnier@users.noreply.github.com> Date: Tue, 28 Apr 2026 11:16:00 +0200 Subject: [PATCH 16/16] chore: clean code --- phpstan-baseline.neon | 21 +-------------------- src/OpenAPIFaker.php | 28 ++++++++++++++++++---------- src/Options.php | 14 +++++++------- src/SchemaFaker/ArrayFaker.php | 4 ++++ src/SchemaFaker/ObjectFaker.php | 10 +++++----- src/SchemaFaker/RequestFaker.php | 20 ++++++++++++-------- src/SchemaFaker/ResponseFaker.php | 22 +++++++++++++--------- src/SchemaFaker/SchemaFaker.php | 8 +++++++- src/SchemaFaker/StringFaker.php | 12 ++++++------ src/Utils/NumberUtils.php | 10 +++------- src/Utils/RegexUtils.php | 3 +++ src/Utils/StringUtils.php | 3 +++ 12 files changed, 82 insertions(+), 73 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 61eb039..1339890 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,21 +1,2 @@ parameters: - ignoreErrors: - - - message: "#^Method Vural\\\\OpenAPIFaker\\\\OpenAPIFaker\\:\\:findComponentSchema\\(\\) should return cebe\\\\openapi\\\\spec\\\\Schema but returns cebe\\\\openapi\\\\spec\\\\Reference\\|cebe\\\\openapi\\\\spec\\\\Schema\\.$#" - count: 1 - path: src/OpenAPIFaker.php - - - - message: "#^Parameter \\#1 \\$schema of class Vural\\\\OpenAPIFaker\\\\SchemaFaker\\\\SchemaFaker constructor expects cebe\\\\openapi\\\\spec\\\\Schema, cebe\\\\openapi\\\\spec\\\\Reference\\|cebe\\\\openapi\\\\spec\\\\Schema\\|null given\\.$#" - count: 1 - path: src/SchemaFaker/ArrayFaker.php - - - - message: "#^Parameter \\#1 \\$schema of class Vural\\\\OpenAPIFaker\\\\SchemaFaker\\\\SchemaFaker constructor expects cebe\\\\openapi\\\\spec\\\\Schema, cebe\\\\openapi\\\\spec\\\\Reference\\|cebe\\\\openapi\\\\spec\\\\Schema\\|null given\\.$#" - count: 1 - path: src/SchemaFaker/RequestFaker.php - - - - message: "#^Parameter \\#1 \\$schema of class Vural\\\\OpenAPIFaker\\\\SchemaFaker\\\\SchemaFaker constructor expects cebe\\\\openapi\\\\spec\\\\Schema, cebe\\\\openapi\\\\spec\\\\Reference\\|cebe\\\\openapi\\\\spec\\\\Schema\\|null given\\.$#" - count: 1 - path: src/SchemaFaker/ResponseFaker.php \ No newline at end of file + ignoreErrors: \ No newline at end of file diff --git a/src/OpenAPIFaker.php b/src/OpenAPIFaker.php index 5c722f7..17c2915 100644 --- a/src/OpenAPIFaker.php +++ b/src/OpenAPIFaker.php @@ -46,7 +46,7 @@ private function __construct() public static function createFromJson(string $json): self { $instance = new self(); - $instance->openAPISchema = (new LeagueOpenAPI\SchemaFactory\JsonFactory($json))->createSchema(); + $instance->openAPISchema = new LeagueOpenAPI\SchemaFactory\JsonFactory($json)->createSchema(); return $instance; } @@ -58,7 +58,7 @@ public static function createFromJson(string $json): self public static function createFromYaml(string $yaml): self { $instance = new self(); - $instance->openAPISchema = (new LeagueOpenAPI\SchemaFactory\YamlFactory($yaml))->createSchema(); + $instance->openAPISchema = new LeagueOpenAPI\SchemaFactory\YamlFactory($yaml)->createSchema(); return $instance; } @@ -74,6 +74,7 @@ public static function createFromSchema(OpenApi $schema): self /** * @throws NoPath * @throws NoRequest + * @throws NoExample */ public function mockRequest( string $path, @@ -82,7 +83,7 @@ public function mockRequest( ): mixed { $content = $this->findContentForRequest($path, $method, $contentType); - return (new RequestFaker($content, $this->options))->generate(); + return new RequestFaker($content, $this->options)->generate(); } /** @@ -98,12 +99,13 @@ public function mockRequestForExample( ): mixed { $content = $this->findContentForRequest($path, $method, $contentType); - return (new RequestFaker($content, $this->options))->generate($exampleName); + return new RequestFaker($content, $this->options)->generate($exampleName); } /** * @throws NoPath * @throws NoResponse + * @throws NoExample */ public function mockResponse( string $path, @@ -113,7 +115,7 @@ public function mockResponse( ): mixed { $content = $this->findContentForResponse($path, $method, $statusCode, $contentType); - return (new ResponseFaker($content, $this->options))->generate(); + return new ResponseFaker($content, $this->options)->generate(); } /** @@ -130,7 +132,7 @@ public function mockResponseForExample( ): mixed { $content = $this->findContentForResponse($path, $method, $statusCode, $contentType); - return (new ResponseFaker($content, $this->options))->generate($exampleName); + return new ResponseFaker($content, $this->options)->generate($exampleName); } /** @throws Exception */ @@ -138,7 +140,7 @@ public function mockComponentSchema(string $schemaName): mixed { $schema = $this->findComponentSchema($schemaName); - return (new SchemaFaker($schema, $this->options))->generate(); + return new SchemaFaker($schema, $this->options)->generate(); } /** @throws Exception */ @@ -153,7 +155,7 @@ public function mockComponentSchemaForExample(string $schemaName): mixed return $schema->example; } - /** @param array{minItems?:?int, maxItems?:?int, alwaysFakeOptionals?:bool, strategy?:string} $options */ + /** @param array{minItems?:int|null, maxItems?:int|null, alwaysFakeOptionals?:bool, strategy?:string} $options */ public function setOptions(array $options): self { $knownKeys = ['minItems' => 1, 'maxItems' => 1, 'alwaysFakeOptionals' => 1, 'strategy' => 1]; @@ -174,7 +176,7 @@ public function setOptions(array $options): self private function findOperation(string $path, string $method): Operation { try { - $operation = (new LeagueOpenAPI\SpecFinder($this->openAPISchema)) + $operation = new LeagueOpenAPI\SpecFinder($this->openAPISchema) ->findOperationSpec(new LeagueOpenAPI\OperationAddress($path, strtolower($method))); } catch (LeagueOpenAPI\Exception\NoPath) { throw NoPath::forPathAndMethod($path, $method); @@ -257,6 +259,12 @@ private function findComponentSchema(string $schemaName): Schema throw NoSchema::forComponentName($schemaName); } - return $this->openAPISchema->components->schemas[$schemaName]; + $schema = $this->openAPISchema->components->schemas[$schemaName]; + + if (! $schema instanceof Schema) { + throw NoSchema::forComponentName($schemaName); + } + + return $schema; } } diff --git a/src/Options.php b/src/Options.php index 5a622f4..154eb6c 100644 --- a/src/Options.php +++ b/src/Options.php @@ -11,9 +11,9 @@ final class Options { - public const STRATEGY_STATIC = 'static'; + public const string STRATEGY_STATIC = 'static'; - public const STRATEGY_DYNAMIC = 'dynamic'; + public const string STRATEGY_DYNAMIC = 'dynamic'; private int|null $minItems = null; @@ -23,23 +23,23 @@ final class Options private string $strategy = self::STRATEGY_DYNAMIC; - private const ALLOWED = [self::STRATEGY_STATIC, self::STRATEGY_DYNAMIC]; + private const array ALLOWED = [self::STRATEGY_STATIC, self::STRATEGY_DYNAMIC]; - public function setMinItems(int $minItems): Options + public function setMinItems(int $minItems): self { $this->minItems = $minItems; return $this; } - public function setMaxItems(int $maxItems): Options + public function setMaxItems(int $maxItems): self { $this->maxItems = $maxItems; return $this; } - public function setAlwaysFakeOptionals(bool $alwaysFakeOptionals): Options + public function setAlwaysFakeOptionals(bool $alwaysFakeOptionals): self { $this->alwaysFakeOptionals = $alwaysFakeOptionals; @@ -47,7 +47,7 @@ public function setAlwaysFakeOptionals(bool $alwaysFakeOptionals): Options } /** @throws InvalidArgumentException */ - public function setStrategy(string $strategy): Options + public function setStrategy(string $strategy): self { if (! in_array($strategy, self::ALLOWED, true)) { throw new InvalidArgumentException(sprintf('Unknown generation strategy: %s', $strategy)); diff --git a/src/SchemaFaker/ArrayFaker.php b/src/SchemaFaker/ArrayFaker.php index 956f2e1..5bd59f4 100644 --- a/src/SchemaFaker/ArrayFaker.php +++ b/src/SchemaFaker/ArrayFaker.php @@ -45,6 +45,10 @@ public static function generate(Schema $schema, Options $options): array $fakeData = []; + if (! $schema->items instanceof Schema) { + return $fakeData; + } + $itemSchema = new SchemaFaker($schema->items, $options); for ($i = 0; $i < $itemSize; ++$i) { diff --git a/src/SchemaFaker/ObjectFaker.php b/src/SchemaFaker/ObjectFaker.php index 9054700..cfa5b03 100644 --- a/src/SchemaFaker/ObjectFaker.php +++ b/src/SchemaFaker/ObjectFaker.php @@ -44,19 +44,19 @@ public static function generate(Schema $schema, Options $options, bool $request } if ( - ! $options->getAlwaysFakeOptionals() - && ! $useStaticStrategy + ! $useStaticStrategy + && ! $options->getAlwaysFakeOptionals() && ! in_array($key, $allPropertyKeys, true) ) { continue; } - $value = (new SchemaFaker($property, $options))->generate(); + $value = new SchemaFaker($property, $options)->generate(); if ( - ! $options->getAlwaysFakeOptionals() - && $useStaticStrategy + $useStaticStrategy && $property->nullable + && ! $options->getAlwaysFakeOptionals() ) { continue; } diff --git a/src/SchemaFaker/RequestFaker.php b/src/SchemaFaker/RequestFaker.php index 238351e..58b3d04 100644 --- a/src/SchemaFaker/RequestFaker.php +++ b/src/SchemaFaker/RequestFaker.php @@ -20,7 +20,7 @@ final class RequestFaker private Schema|Reference|null $schema = null; /** @var Example[]|Reference[] */ - private array $examples = []; + private array $examples; public function __construct(MediaType $mediaType, private Options $options) { @@ -35,22 +35,26 @@ public function __construct(MediaType $mediaType, private Options $options) */ public function generate(string|null $exampleName = null): array|string|bool|int|float|null { - if ($this->options->getStrategy() === Options::STRATEGY_STATIC && ! empty($this->examples)) { + if (! $this->schema instanceof Schema) { + return null; + } + + if (! empty($this->examples) && $this->options->getStrategy() === Options::STRATEGY_STATIC) { if ($exampleName !== null) { if (! array_key_exists($exampleName, $this->examples)) { throw NoExample::forRequest($exampleName); } - /** @var Example $exampleName */ - $exampleName = $this->examples[$exampleName]; + /** @var Example $exampleNameExample */ + $exampleNameExample = $this->examples[$exampleName]; } else { - /** @var Example $exampleName */ - $exampleName = reset($this->examples); + /** @var Example $exampleNameExample */ + $exampleNameExample = reset($this->examples); } - return $exampleName->value; + return $exampleNameExample->value; } - return (new SchemaFaker($this->schema, $this->options, true))->generate(); + return new SchemaFaker($this->schema, $this->options, true)->generate(); } } diff --git a/src/SchemaFaker/ResponseFaker.php b/src/SchemaFaker/ResponseFaker.php index a7b8904..db6dce0 100644 --- a/src/SchemaFaker/ResponseFaker.php +++ b/src/SchemaFaker/ResponseFaker.php @@ -17,10 +17,10 @@ /** @internal */ final class ResponseFaker { - private Schema|Reference|null $schema = null; + private Schema|Reference|null $schema; /** @var Example[]|Reference[] */ - private array $examples = []; + private array $examples; public function __construct(MediaType $mediaType, private Options $options) { @@ -35,22 +35,26 @@ public function __construct(MediaType $mediaType, private Options $options) */ public function generate(string|null $exampleName = null): array|string|bool|int|float|null { - if ($this->options->getStrategy() === Options::STRATEGY_STATIC && ! empty($this->examples)) { + if (! $this->schema instanceof Schema) { + return null; + } + + if (! empty($this->examples) && $this->options->getStrategy() === Options::STRATEGY_STATIC) { if ($exampleName !== null) { if (! array_key_exists($exampleName, $this->examples)) { throw NoExample::forResponse($exampleName); } - /** @var Example $exampleName */ - $exampleName = $this->examples[$exampleName]; + /** @var Example $exampleNameExample */ + $exampleNameExample = $this->examples[$exampleName]; } else { - /** @var Example $exampleName */ - $exampleName = reset($this->examples); + /** @var Example $exampleNameExample */ + $exampleNameExample = reset($this->examples); } - return $exampleName->value; + return $exampleNameExample->value; } - return (new SchemaFaker($this->schema, $this->options, false))->generate(); + return new SchemaFaker($this->schema, $this->options, false)->generate(); } } diff --git a/src/SchemaFaker/SchemaFaker.php b/src/SchemaFaker/SchemaFaker.php index 1185f2f..dc43a28 100644 --- a/src/SchemaFaker/SchemaFaker.php +++ b/src/SchemaFaker/SchemaFaker.php @@ -4,8 +4,10 @@ namespace Vural\OpenAPIFaker\SchemaFaker; +use cebe\openapi\exceptions\TypeErrorException; use cebe\openapi\spec\Schema; use Faker\Provider\Base; +use Safe\Exceptions\JsonException; use Vural\OpenAPIFaker\Options; use function array_key_exists; @@ -23,7 +25,11 @@ final class SchemaFaker { private Schema $schema; - public function __construct(Schema $schema, private Options $options, private bool $request = false) + /** + * @throws TypeErrorException + * @throws JsonException + */ + public function __construct(Schema $schema, private readonly Options $options, private readonly bool $request = false) { $schemaData = json_decode(json_encode($schema->getSerializableData()), true); $this->schema = new Schema($this->resolveOfConstraints($schemaData, $options)); diff --git a/src/SchemaFaker/StringFaker.php b/src/SchemaFaker/StringFaker.php index a665528..7a55551 100644 --- a/src/SchemaFaker/StringFaker.php +++ b/src/SchemaFaker/StringFaker.php @@ -74,12 +74,12 @@ private static function generateDynamicFromFormat(Schema $schema): string return match ($schema->format) { 'date' => DateTime::date('Y-m-d', '2199-01-01'), 'date-time' => DateTime::dateTime('2199-01-01 00:00:00')->format(DATE_RFC3339), - 'email' => (new Internet(Factory::create()))->safeEmail(), + 'email' => new Internet(Factory::create())->safeEmail(), 'uuid' => Uuid::uuid(), - 'uri' => (new Internet(Factory::create()))->url(), - 'hostname' => (new Internet(Factory::create()))->domainName(), - 'ipv4' => (new Internet(Factory::create()))->ipv4(), - 'ipv6' => (new Internet(Factory::create()))->ipv6(), + 'uri' => new Internet(Factory::create())->url(), + 'hostname' => new Internet(Factory::create())->domainName(), + 'ipv4' => new Internet(Factory::create())->ipv4(), + 'ipv6' => new Internet(Factory::create())->ipv6(), 'byte' => base64_encode(Lorem::word()), 'binary' => StringUtils::convertToBinary(Lorem::word()), 'password' => Base::asciify(str_repeat('*', $maxLength)), @@ -128,7 +128,7 @@ private static function generateStaticFromFormat(Schema $schema): string return match ($schema->format) { 'date' => '2019-08-24', - 'date-time' => (new \Safe\DateTime('2019-08-24T14:15:22'))->format(DATE_RFC3339), + 'date-time' => new \Safe\DateTime('2019-08-24T14:15:22')->format(DATE_RFC3339), 'email' => 'user@example.com', 'uuid' => '095be615-a8ad-4c33-8e9c-c7612fbf6c9f', 'uri' => 'http://example.com', diff --git a/src/Utils/NumberUtils.php b/src/Utils/NumberUtils.php index d1c3a68..61a980a 100644 --- a/src/Utils/NumberUtils.php +++ b/src/Utils/NumberUtils.php @@ -12,17 +12,13 @@ public static function ensureRange(int|float $sample, int|float|null $minimum, i { if ($minimum === null) { $minimum = $sample; + } elseif ($minimum > $sample) { + $sample = $minimum; } if ($maximum === null) { $maximum = $minimum; - } - - if ($minimum > $sample) { - $sample = $minimum; - } - - if ($maximum < $sample) { + } elseif ($maximum < $sample) { $sample = $maximum; } diff --git a/src/Utils/RegexUtils.php b/src/Utils/RegexUtils.php index 2f04b6e..77aeba1 100644 --- a/src/Utils/RegexUtils.php +++ b/src/Utils/RegexUtils.php @@ -4,6 +4,8 @@ namespace Vural\OpenAPIFaker\Utils; +use Safe\Exceptions\PcreException; + use function explode; use function Safe\preg_replace; use function Safe\preg_replace_callback; @@ -14,6 +16,7 @@ /** @internal */ final class RegexUtils { + /** @throws PcreException */ public static function generateSample(string $regex): string { // ditch the anchors diff --git a/src/Utils/StringUtils.php b/src/Utils/StringUtils.php index 687d7e3..0faae32 100644 --- a/src/Utils/StringUtils.php +++ b/src/Utils/StringUtils.php @@ -4,6 +4,8 @@ namespace Vural\OpenAPIFaker\Utils; +use Safe\Exceptions\MiscException; + use function base_convert; use function ceil; use function implode; @@ -17,6 +19,7 @@ /** @internal */ final class StringUtils { + /** @throws MiscException */ public static function convertToBinary(string $text): string { $characters = str_split($text);