Skip to content

Commit

Permalink
tests: update make resource console tests for new model option
Browse files Browse the repository at this point in the history
  • Loading branch information
lindyhopchris committed Mar 3, 2024
1 parent 808b968 commit 219e02b
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions tests/lib/Integration/Console/MakeResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

class MakeResourceTest extends TestCase
{

/**
* @return void
*/
Expand Down Expand Up @@ -60,6 +59,33 @@ public function test(): void
$this->assertResourceCreated();
}

public function testModelWithoutNamespace(): void
{
config()->set('jsonapi.servers', [
'v1' => Server::class,
]);

$result = $this->artisan('jsonapi:resource posts --model BlogPost');

$this->assertSame(0, $result);
$this->assertResourceCreated('App\Models\BlogPost', 'BlogPost');
}

public function testModelWithNamespace(): void
{
config()->set('jsonapi.servers', [
'v1' => Server::class,
]);

$result = $this->artisan('jsonapi:resource', [
'name' => 'posts',
'--model' => '\App\Foo\Bar\BlogPost',
]);

$this->assertSame(0, $result);
$this->assertResourceCreated('App\Foo\Bar\BlogPost', 'BlogPost');
}

public function testServer(): void
{
config()->set('jsonapi.servers', [
Expand Down Expand Up @@ -104,9 +130,14 @@ public function testInvalidServer(): void
}

/**
* @param string $namespacedModel
* @param string $model
* @return void
*/
private function assertResourceCreated(): void
private function assertResourceCreated(
string $namespacedModel = 'App\Models\Post',
string $model = 'Post'
): void
{
$this->assertFileExists($path = app_path('JsonApi/V1/Posts/PostResource.php'));
$content = file_get_contents($path);
Expand All @@ -115,6 +146,8 @@ private function assertResourceCreated(): void
'namespace App\JsonApi\V1\Posts;',
'use LaravelJsonApi\Core\Resources\JsonApiResource;',
'class PostResource extends JsonApiResource',
"use {$namespacedModel};",
"@property {$model} \$resource",
];

foreach ($tests as $expected) {
Expand Down

0 comments on commit 219e02b

Please sign in to comment.