Skip to content

Commit

Permalink
Merge pull request #132 from rico/main
Browse files Browse the repository at this point in the history
Allow to register multiple Get route declarations on one method
  • Loading branch information
freekmurze authored Nov 24, 2023
2 parents 10af3aa + 26e7bbf commit 7e25b05
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Attributes/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_METHOD)]
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Delete extends Route
{
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Get.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_METHOD)]
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Get extends Route
{
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_METHOD)]
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Options extends Route
{
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Patch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_METHOD)]
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Patch extends Route
{
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_METHOD)]
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Post extends Route
{
public function __construct(
Expand Down
2 changes: 1 addition & 1 deletion src/Attributes/Put.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use Attribute;

#[Attribute(Attribute::TARGET_METHOD)]
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
class Put extends Route
{
public function __construct(
Expand Down
12 changes: 12 additions & 0 deletions tests/AttributeTests/DeleteAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\RouteAttributes\Tests\AttributeTests;

use Spatie\RouteAttributes\Tests\TestCase;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\DeleteMultipleTestController;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\DeleteTestController;

class DeleteAttributeTest extends TestCase
Expand All @@ -16,4 +17,15 @@ public function it_can_register_a_delete_route()
->assertRegisteredRoutesCount(1)
->assertRouteRegistered(DeleteTestController::class, 'myDeleteMethod', 'delete', 'my-delete-method');
}

/** @test */
public function it_can_register_multiple_delete_routes()
{
$this->routeRegistrar->registerClass(DeleteMultipleTestController::class);

$this
->assertRegisteredRoutesCount(2)
->assertRouteRegistered(DeleteMultipleTestController::class, 'myDeleteMethod', 'delete', 'my-delete-method')
->assertRouteRegistered(DeleteMultipleTestController::class, 'myDeleteMethod', 'delete', 'my-other-delete-method');
}
}
12 changes: 12 additions & 0 deletions tests/AttributeTests/GetAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Spatie\RouteAttributes\Tests\TestCase;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\GetTestController;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\GetMultipleTestController;

class GetAttributeTest extends TestCase
{
Expand All @@ -16,4 +17,15 @@ public function it_can_register_a_get_route()
->assertRegisteredRoutesCount(1)
->assertRouteRegistered(GetTestController::class, 'myGetMethod', 'get', 'my-get-method');
}

/** @test */
public function it_can_register_multiple_get_routes()
{
$this->routeRegistrar->registerClass(GetMultipleTestController::class);

$this
->assertRegisteredRoutesCount(2)
->assertRouteRegistered(GetMultipleTestController::class, 'myGetMethod', 'get', 'my-get-method')
->assertRouteRegistered(GetMultipleTestController::class, 'myGetMethod', 'get', 'my-other-get-method');;
}
}
12 changes: 12 additions & 0 deletions tests/AttributeTests/OptionsAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\RouteAttributes\Tests\AttributeTests;

use Spatie\RouteAttributes\Tests\TestCase;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\OptionsMultipleTestController;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\OptionsTestController;

class OptionsAttributeTest extends TestCase
Expand All @@ -16,4 +17,15 @@ public function it_can_register_a_options_route()
->assertRegisteredRoutesCount(1)
->assertRouteRegistered(OptionsTestController::class, 'myOptionsMethod', 'options', 'my-options-method');
}

/** @test */
public function it_can_register_multiple_options_routes()
{
$this->routeRegistrar->registerClass(OptionsMultipleTestController::class);

$this
->assertRegisteredRoutesCount(2)
->assertRouteRegistered(OptionsMultipleTestController::class, 'myOptionsMethod', 'options', 'my-options-method')
->assertRouteRegistered(OptionsMultipleTestController::class, 'myOptionsMethod', 'options', 'my-other-options-method');
}
}
12 changes: 12 additions & 0 deletions tests/AttributeTests/PatchAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\RouteAttributes\Tests\AttributeTests;

use Spatie\RouteAttributes\Tests\TestCase;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\PatchMultipleTestController;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\PatchTestController;

class PatchAttributeTest extends TestCase
Expand All @@ -16,4 +17,15 @@ public function it_can_register_a_patch_route()
->assertRegisteredRoutesCount(1)
->assertRouteRegistered(PatchTestController::class, 'myPatchMethod', 'patch', 'my-patch-method');
}

/** @test */
public function it_can_register_multiple_patch_routes()
{
$this->routeRegistrar->registerClass(PatchMultipleTestController::class);

$this
->assertRegisteredRoutesCount(2)
->assertRouteRegistered(PatchMultipleTestController::class, 'myPatchMethod', 'patch', 'my-patch-method')
->assertRouteRegistered(PatchMultipleTestController::class, 'myPatchMethod', 'patch', 'my-other-patch-method');
}
}
12 changes: 12 additions & 0 deletions tests/AttributeTests/PostAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\RouteAttributes\Tests\AttributeTests;

use Spatie\RouteAttributes\Tests\TestCase;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\PostMultipleTestController;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\PostTestController;

class PostAttributeTest extends TestCase
Expand All @@ -16,4 +17,15 @@ public function it_can_register_a_post_route()
->assertRegisteredRoutesCount(1)
->assertRouteRegistered(PostTestController::class, 'myPostMethod', 'post', 'my-post-method');
}

/** @test */
public function it_can_register_multiple_post_routes()
{
$this->routeRegistrar->registerClass(PostMultipleTestController::class);

$this
->assertRegisteredRoutesCount(2)
->assertRouteRegistered(PostMultipleTestController::class, 'myPostMethod', 'post', 'my-post-method')
->assertRouteRegistered(PostMultipleTestController::class, 'myPostMethod', 'post', 'my-other-post-method');
}
}
12 changes: 12 additions & 0 deletions tests/AttributeTests/PutAttributeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Spatie\RouteAttributes\Tests\AttributeTests;

use Spatie\RouteAttributes\Tests\TestCase;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\PutMultipleTestController;
use Spatie\RouteAttributes\Tests\TestClasses\Controllers\PutTestController;

class PutAttributeTest extends TestCase
Expand All @@ -16,4 +17,15 @@ public function it_can_register_a_put_route()
->assertRegisteredRoutesCount(1)
->assertRouteRegistered(PutTestController::class, 'myPutMethod', 'put', 'my-put-method');
}

/** @test */
public function it_can_register_multiple_put_routes()
{
$this->routeRegistrar->registerClass(PutMultipleTestController::class);

$this
->assertRegisteredRoutesCount(2)
->assertRouteRegistered(PutMultipleTestController::class, 'myPutMethod', 'put', 'my-put-method')
->assertRouteRegistered(PutMultipleTestController::class, 'myPutMethod', 'put', 'my-other-put-method');
}
}
14 changes: 14 additions & 0 deletions tests/TestClasses/Controllers/DeleteMultipleTestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Spatie\RouteAttributes\Tests\TestClasses\Controllers;

use Spatie\RouteAttributes\Attributes\Delete;

class DeleteMultipleTestController
{
#[Delete('my-delete-method')]
#[Delete('my-other-delete-method')]
public function myDeleteMethod()
{
}
}
14 changes: 14 additions & 0 deletions tests/TestClasses/Controllers/GetMultipleTestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Spatie\RouteAttributes\Tests\TestClasses\Controllers;

use Spatie\RouteAttributes\Attributes\Get;

class GetMultipleTestController
{
#[Get('my-get-method')]
#[Get('my-other-get-method')]
public function myGetMethod()
{
}
}
14 changes: 14 additions & 0 deletions tests/TestClasses/Controllers/OptionsMultipleTestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Spatie\RouteAttributes\Tests\TestClasses\Controllers;

use Spatie\RouteAttributes\Attributes\Options;

class OptionsMultipleTestController
{
#[Options('my-options-method')]
#[Options('my-other-options-method')]
public function myOptionsMethod()
{
}
}
14 changes: 14 additions & 0 deletions tests/TestClasses/Controllers/PatchMultipleTestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Spatie\RouteAttributes\Tests\TestClasses\Controllers;

use Spatie\RouteAttributes\Attributes\Patch;

class PatchMultipleTestController
{
#[Patch('my-patch-method')]
#[Patch('my-other-patch-method')]
public function myPatchMethod()
{
}
}
14 changes: 14 additions & 0 deletions tests/TestClasses/Controllers/PostMultipleTestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Spatie\RouteAttributes\Tests\TestClasses\Controllers;

use Spatie\RouteAttributes\Attributes\Post;

class PostMultipleTestController
{
#[Post('my-post-method')]
#[Post('my-other-post-method')]
public function myPostMethod()
{
}
}
14 changes: 14 additions & 0 deletions tests/TestClasses/Controllers/PutMultipleTestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Spatie\RouteAttributes\Tests\TestClasses\Controllers;

use Spatie\RouteAttributes\Attributes\Put;

class PutMultipleTestController
{
#[Put('my-put-method')]
#[Put('my-other-put-method')]
public function myPutMethod()
{
}
}

0 comments on commit 7e25b05

Please sign in to comment.