generated from spatie/package-skeleton-laravel
-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from michaelhrivnak/add-with-trashed-attribute
Added WithTrashed attribute
- Loading branch information
Showing
7 changed files
with
169 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Spatie\RouteAttributes\Attributes; | ||
|
||
use Attribute; | ||
|
||
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS )] | ||
class WithTrashed implements RouteAttribute | ||
{ | ||
public bool $withTrashed; | ||
|
||
public function __construct(bool $withTrashed = true) | ||
{ | ||
$this->withTrashed = $withTrashed; | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
namespace AttributeTests; | ||
|
||
use Spatie\RouteAttributes\Tests\TestCase; | ||
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\WithTrashedTestController; | ||
|
||
class WithTrashedAttributeTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_can_apply_with_trashed_on_a_controller(): void | ||
{ | ||
$this->routeRegistrar->registerClass(WithTrashedTestController::class); | ||
|
||
$this | ||
->assertRegisteredRoutesCount(3) | ||
->assertRouteRegistered( | ||
WithTrashedTestController::class, | ||
controllerMethod: 'withTrashedRoute', | ||
httpMethods: 'get', | ||
uri: 'with-trashed-test-method/{param}', | ||
withTrashed: true, | ||
|
||
) | ||
->assertRouteRegistered( | ||
WithTrashedTestController::class, | ||
controllerMethod: 'withoutTrashedRoute', | ||
httpMethods: 'get', | ||
uri: 'with-trashed-test-method-2/{param}', | ||
withTrashed: false, | ||
) | ||
// registered through | ||
->assertRouteRegistered( | ||
WithTrashedTestController::class, | ||
controllerMethod: 'noWithTrashedAttributeRoute', | ||
httpMethods: 'get', | ||
uri: 'with-trashed-test-method-3/{param}', | ||
withTrashed: true, | ||
) | ||
; | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
tests/TestClasses/Controllers/WithTrashedTestController.php
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,21 @@ | ||
<?php | ||
|
||
namespace Spatie\RouteAttributes\Tests\TestClasses\Controllers; | ||
|
||
use Spatie\RouteAttributes\Attributes\Get; | ||
use Spatie\RouteAttributes\Attributes\WithTrashed; | ||
|
||
#[WithTrashed] | ||
class WithTrashedTestController | ||
{ | ||
#[Get('with-trashed-test-method/{param}')] | ||
#[WithTrashed] | ||
public function withTrashedRoute() {} | ||
|
||
#[Get('with-trashed-test-method-2/{param}')] | ||
#[WithTrashed(false)] | ||
public function withoutTrashedRoute() {} | ||
|
||
#[Get('with-trashed-test-method-3/{param}')] | ||
public function noWithTrashedAttributeRoute() {} | ||
} |