Shalvah 3 ماه پیش
والد
کامیت
d5e61ebbe7

+ 2 - 4
src/Attributes/GenericParam.php

@@ -41,12 +41,10 @@ class GenericParam
             return $this->enum;
         }
 
-        if (function_exists('enum_exists') && enum_exists($this->enum)
-            && method_exists($this->enum, 'tryFrom')
-        ) {
+        if (enum_exists($this->enum) && method_exists($this->enum, 'tryFrom')) {
             return array_map(
             // $case->value only exists on BackedEnums, not UnitEnums
-            // method_exists($enum, 'tryFrom') implies $enum instanceof BackedEnum
+            // method_exists($enum, 'tryFrom') implies the enum is a BackedEnum
             // @phpstan-ignore-next-line
                 fn ($case) => $case->value,
                 $this->enum::cases()

+ 2 - 2
src/Extracting/ParsesValidationRules.php

@@ -205,7 +205,7 @@ trait ParsesValidationRules
             return true;
         }
 
-        if (function_exists('enum_exists') && $rule instanceof \Illuminate\Validation\Rules\Enum) {
+        if ($rule instanceof \Illuminate\Validation\Rules\Enum) {
             $reflection = new \ReflectionClass($rule);
             $property = $reflection->getProperty('type');
             $property->setAccessible(true);
@@ -213,7 +213,7 @@ trait ParsesValidationRules
 
             if (enum_exists($type) && method_exists($type, 'tryFrom')) {
                 // $case->value only exists on BackedEnums, not UnitEnums
-                // method_exists($enum, 'tryFrom') implies $enum instanceof BackedEnum
+                // method_exists($enum, 'tryFrom') implies the enum is a BackedEnum
                 // @phpstan-ignore-next-line
                 $cases = array_map(fn ($case) => $case->value, $type::cases());
                 $parameterData['type'] = gettype($cases[0]);

+ 1 - 2
src/Extracting/Strategies/GetFromInlineValidatorBase.php

@@ -84,12 +84,11 @@ class GetFromInlineValidatorBase extends Strategy
                     }
                     // Try to extract Enum rule
                     else if (
-                        function_exists('enum_exists') &&
                         ($enum = $this->extractEnumClassFromArrayItem($arrayItem)) &&
                         enum_exists($enum) && method_exists($enum, 'tryFrom')
                     ) {
                         // $case->value only exists on BackedEnums, not UnitEnums
-                        // method_exists($enum, 'tryFrom') implies $enum instanceof BackedEnum
+                        // method_exists($enum, 'tryFrom') implies the enum is a BackedEnum
                         // @phpstan-ignore-next-line
                         $rulesList[] = 'in:' . implode(',', array_map(fn ($case) => $case->value, $enum::cases()));
                     }

+ 0 - 5
tests/Fixtures/TestController.php

@@ -704,19 +704,14 @@ class TestController extends Controller
         ]);
     }
 
-    /**
-     * Can only run on PHP 8.1
     public function withInjectedEnumAndModel(Category $category, TestUser $user)
     {
         return null;
     }
-     */
 }
 
-/**
 enum Category: string
 {
     case Fruits = 'fruits';
     case People = 'people';
 }
-*/

+ 9 - 9
tests/Fixtures/collection.json

@@ -128,7 +128,7 @@
             ],
             "body": {
               "mode": "raw",
-              "raw": "{\"user_id\":9,\"room_id\":\"consequatur\",\"forever\":false,\"another_one\":11613.31890586,\"yet_another_param\":{\"name\":\"consequatur\"},\"even_more_param\":[11613.31890586],\"book\":{\"name\":\"consequatur\",\"author_id\":17,\"pages_count\":17},\"ids\":[17],\"users\":[{\"first_name\":\"John\",\"last_name\":\"Doe\"}]}"
+              "raw": "{\"user_id\":9,\"room_id\":\"architecto\",\"forever\":false,\"another_one\":4326.41688,\"yet_another_param\":{\"name\":\"architecto\"},\"even_more_param\":[4326.41688],\"book\":{\"name\":\"architecto\",\"author_id\":16,\"pages_count\":16},\"ids\":[16],\"users\":[{\"first_name\":\"John\",\"last_name\":\"Doe\"}]}"
             },
             "description": "",
             "auth": {
@@ -146,7 +146,7 @@
               "query": [
                 {
                   "key": "location_id",
-                  "value": "consequatur",
+                  "value": "architecto",
                   "description": "The id of the location.",
                   "disabled": false
                 },
@@ -164,7 +164,7 @@
                 },
                 {
                   "key": "filters",
-                  "value": "consequatur",
+                  "value": "architecto",
                   "description": "The filters.",
                   "disabled": false
                 },
@@ -175,7 +175,7 @@
                   "disabled": false
                 }
               ],
-              "raw": "{{baseUrl}}/api/withQueryParameters?location_id=consequatur&user_id=me&page=4&filters=consequatur&url_encoded=%2B+%5B%5D%26%3D"
+              "raw": "{{baseUrl}}/api/withQueryParameters?location_id=architecto&user_id=me&page=4&filters=architecto&url_encoded=%2B+%5B%5D%26%3D"
             },
             "method": "GET",
             "header": [
@@ -268,12 +268,12 @@
               "query": [
                 {
                   "key": "something",
-                  "value": "consequatur",
+                  "value": "architecto",
                   "description": "",
                   "disabled": false
                 }
               ],
-              "raw": "{{baseUrl}}/api/echoesUrlParameters/:param/:param2/:param3/:param4?something=consequatur",
+              "raw": "{{baseUrl}}/api/echoesUrlParameters/:param/:param2/:param3/:param4?something=architecto",
               "variable": [
                 {
                   "id": "param",
@@ -284,13 +284,13 @@
                 {
                   "id": "param2",
                   "key": "param2",
-                  "value": "consequatur",
+                  "value": "architecto",
                   "description": ""
                 },
                 {
                   "id": "param3",
                   "key": "param3",
-                  "value": "consequatur",
+                  "value": "architecto",
                   "description": ""
                 },
                 {
@@ -331,7 +331,7 @@
                 }
               ],
               "code": 200,
-              "body": "{\"param\":\"4\",\"param2\":\"consequatur\",\"param3\":\"consequatur\",\"param4\":null}",
+              "body": "{\"param\":\"4\",\"param2\":\"architecto\",\"param3\":\"architecto\",\"param4\":null}",
               "name": null
             }
           ]

+ 12 - 12
tests/Fixtures/openapi.yaml

@@ -91,12 +91,12 @@ paths:
                     in: query
                     name: location_id
                     description: 'The id of the location.'
-                    example: consequatur
+                    example: architecto
                     required: true
                     schema:
                         type: string
                         description: 'The id of the location.'
-                        example: consequatur
+                        example: architecto
                         nullable: false
                 -
                     in: query
@@ -124,12 +124,12 @@ paths:
                     in: query
                     name: filters
                     description: 'The filters.'
-                    example: consequatur
+                    example: architecto
                     required: false
                     schema:
                         type: string
                         description: 'The filters.'
-                        example: consequatur
+                        example: architecto
                         nullable: false
                 -
                     in: query
@@ -193,12 +193,12 @@ paths:
                     in: query
                     name: something
                     description: ''
-                    example: consequatur
+                    example: architecto
                     required: false
                     schema:
                         type: string
                         description: ''
-                        example: consequatur
+                        example: architecto
                         nullable: false
                 -
                     in: header
@@ -216,13 +216,13 @@ paths:
                                 type: object
                                 example:
                                     param: '4'
-                                    param2: consequatur
-                                    param3: consequatur
+                                    param2: architecto
+                                    param3: architecto
                                     param4: null
                                 properties:
                                     param: { type: string, example: '4' }
-                                    param2: { type: string, example: consequatur }
-                                    param3: { type: string, example: consequatur }
+                                    param2: { type: string, example: architecto }
+                                    param3: { type: string, example: architecto }
                                     param4: { type: string, example: null }
             tags:
                 - Other😎
@@ -243,7 +243,7 @@ paths:
                 required: true
                 schema:
                     type: string
-                example: consequatur
+                example: architecto
             -
                 in: path
                 name: param3
@@ -257,7 +257,7 @@ paths:
                         value: ''
                     present:
                         summary: 'When the value is present'
-                        value: consequatur
+                        value: architecto
             -
                 in: path
                 name: param4

+ 12 - 0
tests/GenerateDocumentation/OutputTest.php

@@ -171,6 +171,12 @@ class OutputTest extends BaseLaravelTest
     /** @test */
     public function generated_postman_collection_file_is_correct()
     {
+        if (phpversion() < 8.3) {
+            // See https://github.com/FakerPHP/Faker/issues/694
+            $this->markTestSkipped('Faker seeding changed in PHP 8.3');
+            return;
+        }
+
         RouteFacade::post('/api/withBodyParametersAsArray', [TestController::class, 'withBodyParametersAsArray']);
         RouteFacade::post('/api/withFormDataParams', [TestController::class, 'withFormDataParams']);
         RouteFacade::post('/api/withBodyParameters', [TestController::class, 'withBodyParameters']);
@@ -205,6 +211,12 @@ class OutputTest extends BaseLaravelTest
     /** @test */
     public function generated_openapi_spec_file_is_correct()
     {
+        if (phpversion() < 8.3) {
+            // See https://github.com/FakerPHP/Faker/issues/694
+            $this->markTestSkipped('Faker seeding changed in PHP 8.3');
+            return;
+        }
+
         RouteFacade::post('/api/withBodyParametersAsArray', [TestController::class, 'withBodyParametersAsArray']);
         RouteFacade::post('/api/withFormDataParams', [TestController::class, 'withFormDataParams']);
         RouteFacade::get('/api/withResponseTag', [TestController::class, 'withResponseTag']);

+ 0 - 4
tests/Strategies/GetFromInlineValidatorTest.php

@@ -232,10 +232,6 @@ class GetFromInlineValidatorTest extends BaseLaravelTest
     /** @test */
     public function can_fetch_inline_enum_rules()
     {
-        if (phpversion() < 8.1) {
-            $this->markTestSkipped('Enums are only supported in PHP 8.1 or later');
-        }
-
         $endpoint = $this->endpoint(function (ExtractedEndpointData $e) {
             $e->method = new \ReflectionMethod(TestController::class, 'withEnumRule');
         });

+ 4 - 5
tests/Strategies/UrlParameters/GetFromLaravelAPITest.php

@@ -22,9 +22,8 @@ class GetFromLaravelAPITest extends BaseLaravelTest
     /** @test */
     public function can_infer_type_from_model_binding()
     {
-        $endpoint = $this->endpointForRoute("users/{id}", TestController::class, 'withInjectedModel');
-        // Can only run on PHP 8.1
-        // $endpoint = $this->endpointForRoute("categories/{category}/users/{id}/", TestController::class, 'withInjectedEnumAndModel');
+        // $endpoint = $this->endpointForRoute("users/{id}", TestController::class, 'withInjectedModel');
+        $endpoint = $this->endpointForRoute("categories/{category}/users/{id}/", TestController::class, 'withInjectedEnumAndModel');
         $results = $this->fetch($endpoint);
 
         $this->assertArraySubset([
@@ -32,14 +31,14 @@ class GetFromLaravelAPITest extends BaseLaravelTest
             "description" => "The ID of the user.",
             "required" => true,
             "type" => "integer",
-        ], $results['id']);/*
+        ], $results['id']);
         $this->assertArraySubset([
             "name" => "category",
             "description" => "The category.",
             "required" => true,
             "type" => "string",
             "example" => \Knuckles\Scribe\Tests\Fixtures\Category::cases()[0]->value,
-        ], $results['category']);*/
+        ], $results['category']);
         $this->assertIsInt($results['id']['example']);
     }
 

+ 2 - 6
tests/Unit/ValidationRuleParsingTest.php

@@ -45,7 +45,7 @@ class ValidationRuleParsingTest extends BaseLaravelTest
         Schema::create('users', function ($table) {
             $table->id();
         });
-        
+
         $results = $this->strategy->parse($ruleset, $customInfo);
 
         $parameterName = array_keys($ruleset)[0];
@@ -57,7 +57,7 @@ class ValidationRuleParsingTest extends BaseLaravelTest
 
         // Validate that the generated values actually pass validation (for rules where we can generate some data)
         if (is_string($ruleset[$parameterName]) && str_contains($ruleset[$parameterName], "exists")) return;
-        
+
         $exampleData = [$parameterName => $results[$parameterName]['example']];
         $validator = Validator::make($exampleData, $ruleset);
         try {
@@ -552,10 +552,6 @@ class ValidationRuleParsingTest extends BaseLaravelTest
     /** @test */
     public function can_parse_enum_rules()
     {
-        if (phpversion() < 8.1) {
-            $this->markTestSkipped('Enums are only supported in PHP 8.1 or later');
-        }
-
         $results = $this->strategy->parse([
             'enum' => [
                 'required',