-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add test for internal resources
- Loading branch information
Showing
4 changed files
with
93 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\LaraStrict\Feature\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use LaraStrict\Http\Resources\CreatedResource; | ||
use Tests\LaraStrict\Feature\TestCase; | ||
|
||
class CreatedResourceTest extends TestCase | ||
{ | ||
public function testSetsCode201(): void | ||
{ | ||
$response = (new CreatedResource(id: 1))->toResponse($this->app()->make(Request::class)); | ||
|
||
$this->assertEquals(201, $response->getStatusCode()); | ||
$this->assertEquals('{"message":"created","data":{"id":1}}', $response->getContent()); | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\LaraStrict\Unit\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use LaraStrict\Http\Resources\DeletedResource; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class DeletedResourceTest extends TestCase | ||
{ | ||
public function test(): void | ||
{ | ||
$this->assertEquals( | ||
expected: [ | ||
'message' => 'deleted', | ||
], | ||
actual: (new DeletedResource())->toArray(new Request()) | ||
); | ||
} | ||
} |
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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\LaraStrict\Unit\Http\Resources; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource as BaseJsonResource; | ||
use LaraStrict\Http\Resources\JsonResource; | ||
|
||
/** | ||
* @property BaseJsonResource $resource | ||
*/ | ||
class ResourceArrayResource extends JsonResource | ||
{ | ||
public function __construct(?BaseJsonResource $resource) | ||
{ | ||
parent::__construct($resource); | ||
} | ||
|
||
/** | ||
* @return array<string, array<array<string, mixed>>> | ||
*/ | ||
public function toArray($request) | ||
{ | ||
return [ | ||
'res' => $this->resourceArray($request, $this->resource), | ||
]; | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\LaraStrict\Unit\Http\Resources; | ||
|
||
use Illuminate\Http\Request; | ||
use LaraStrict\Http\Resources\UpdatedResource; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class UpdatedResourceTest extends TestCase | ||
{ | ||
public function test(): void | ||
{ | ||
$this->assertEquals( | ||
expected: [ | ||
'message' => 'updated', | ||
], | ||
actual: (new UpdatedResource())->toArray(new Request()) | ||
); | ||
} | ||
} |