Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] Tests for route closures (#35345)
* Test RouteAction * Add RouteSignatureParameters test
- Loading branch information
1 parent
10ad064
commit af49b8e
Showing
2 changed files
with
58 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,29 @@ | ||
<?php | ||
|
||
namespace Illuminate\Tests\Routing; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Routing\RouteAction; | ||
use Opis\Closure\SerializableClosure; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class RouteActionTest extends TestCase | ||
{ | ||
public function test_it_can_detect_a_serialized_closure() | ||
{ | ||
$action = ['uses' => serialize(new SerializableClosure(function (RouteActionUser $user) { | ||
return $user; | ||
}))]; | ||
|
||
$this->assertTrue(RouteAction::containsSerializedClosure($action)); | ||
|
||
$action = ['uses' => 'FooController@index']; | ||
|
||
$this->assertFalse(RouteAction::containsSerializedClosure($action)); | ||
} | ||
} | ||
|
||
class RouteActionUser extends Model | ||
{ | ||
// | ||
} |
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 | ||
|
||
namespace Illuminate\Tests\Routing; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Routing\RouteSignatureParameters; | ||
use Opis\Closure\SerializableClosure; | ||
use PHPUnit\Framework\TestCase; | ||
use ReflectionParameter; | ||
|
||
class RouteSignatureParametersTest extends TestCase | ||
{ | ||
public function test_it_can_extract_the_route_action_signature_parameters() | ||
{ | ||
$action = ['uses' => serialize(new SerializableClosure($callable = function (SignatureParametersUser $user) { | ||
return $user; | ||
}))]; | ||
|
||
$parameters = RouteSignatureParameters::fromAction($action); | ||
|
||
$this->assertContainsOnlyInstancesOf(ReflectionParameter::class, $parameters); | ||
$this->assertSame('user', $parameters[0]->getName()); | ||
} | ||
} | ||
|
||
class SignatureParametersUser extends Model | ||
{ | ||
// | ||
} |