-
-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'vNext' into php-84-upgrade
- Loading branch information
Showing
9 changed files
with
187 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Knuckles\Scribe\Tests\Fixtures; | ||
|
||
enum TestGroupBackedEnum: string | ||
{ | ||
case Users = 'Users'; | ||
case Admins = 'Admins'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,10 @@ | |
|
||
namespace Knuckles\Scribe\Tests\Strategies\Responses; | ||
|
||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Foundation\Application; | ||
use Illuminate\Routing\Route; | ||
use Illuminate\Support\Facades\Schema; | ||
use Knuckles\Camel\Extraction\ExtractedEndpointData; | ||
use Knuckles\Scribe\Attributes\Response; | ||
use Knuckles\Scribe\Attributes\ResponseFromApiResource; | ||
|
@@ -285,7 +287,95 @@ public function can_parse_apiresource_attributes_with_cursor_pagination() | |
], $results); | ||
} | ||
|
||
protected function fetch($endpoint): array | ||
/** @test */ | ||
public function can_parse_apiresource_attributes_and_load_children_using_factory_create() | ||
{ | ||
Schema::create('test_users', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('first_name'); | ||
$table->string('last_name'); | ||
$table->string('email'); | ||
$table->integer('parent_id')->nullable(); | ||
}); | ||
|
||
$factory = app(\Illuminate\Database\Eloquent\Factory::class); | ||
$factory->afterCreating(TestUser::class, function (TestUser $user, $faker) { | ||
if ($user->id === 4) { | ||
Utils::getModelFactory(TestUser::class)->create(['id' => 5, 'parent_id' => 4]); | ||
} | ||
}); | ||
$documentationConfig = ['examples' => ['models_source' => ['factoryCreate']]]; | ||
|
||
$results = $this->fetch($this->endpoint("apiResourceAttributesIncludeChildren"), $documentationConfig); | ||
$this->assertArraySubset([ | ||
[ | ||
'status' => 200, | ||
'content' => json_encode([ | ||
"data" => [ | ||
"id" => 4, | ||
"name" => "Tested Again", | ||
"email" => "[email protected]", | ||
"children" => [ | ||
[ | ||
"id" => 5, | ||
"name" => "Tested Again", | ||
"email" => "[email protected]", | ||
] | ||
], | ||
], | ||
]), | ||
], | ||
], $results); | ||
} | ||
|
||
|
||
/** @test */ | ||
public function can_parse_apiresource_attributes_and_load_children_and_children_count_using_factory_create() | ||
{ | ||
if (version_compare(Application::VERSION, '9', '<')) { | ||
$this->markTestSkipped('The whenCounted method in JsonResource requires Laravel 9 or higher.'); | ||
} | ||
|
||
Schema::create('test_users', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('first_name'); | ||
$table->string('last_name'); | ||
$table->string('email'); | ||
$table->integer('parent_id')->nullable(); | ||
}); | ||
|
||
$factory = app(\Illuminate\Database\Eloquent\Factory::class); | ||
$factory->afterCreating(TestUser::class, function (TestUser $user, $faker) { | ||
if ($user->id === 4) { | ||
Utils::getModelFactory(TestUser::class)->create(['id' => 5, 'parent_id' => 4]); | ||
} | ||
}); | ||
$documentationConfig = ['examples' => ['models_source' => ['factoryCreate']]]; | ||
|
||
$results = $this->fetch($this->endpoint("apiResourceAttributesIncludeChildrenAndChildrenCount"), $documentationConfig); | ||
$this->assertArraySubset([ | ||
[ | ||
'status' => 200, | ||
'content' => json_encode([ | ||
"data" => [ | ||
"id" => 4, | ||
"name" => "Tested Again", | ||
"email" => "[email protected]", | ||
"children" => [ | ||
[ | ||
"id" => 5, | ||
"name" => "Tested Again", | ||
"email" => "[email protected]", | ||
] | ||
], | ||
'children_count' => 1, | ||
], | ||
]), | ||
], | ||
], $results); | ||
} | ||
|
||
protected function fetch($endpoint, array $documentationConfig = []): array | ||
{ | ||
$strategy = new UseResponseAttributes(new DocumentationConfig([])); | ||
return $strategy($endpoint, []); | ||
|
@@ -345,4 +435,16 @@ public function apiResourceAttributesWithCursorPaginate() | |
{ | ||
|
||
} | ||
|
||
#[ResponseFromApiResource(TestUserApiResource::class, with: ['children'], withCount: ['children'])] | ||
public function apiResourceAttributesIncludeChildrenAndChildrenCount() | ||
{ | ||
|
||
} | ||
|
||
#[ResponseFromApiResource(TestUserApiResource::class, with: ['children'])] | ||
public function apiResourceAttributesIncludeChildren() | ||
{ | ||
|
||
} | ||
} |