-
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow for nullable route model bindings
- Loading branch information
1 parent
1e925c9
commit 17c69bd
Showing
2 changed files
with
56 additions
and
25 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 |
---|---|---|
|
@@ -123,10 +123,7 @@ public function handle(?Dummy $dummy, Request $request = null) { | |
public function it_resolves_type_hinted_models_using_route_model_binding() | ||
{ | ||
$this->loadLaravelMigrations(); | ||
$this->createUser([ | ||
'name' => 'John Doe', | ||
'email' => '[email protected]', | ||
]); | ||
$this->createUser(['name' => 'John Doe']); | ||
|
||
$action = new class(['user' => 1]) extends Action { | ||
public function handle(User $user) { | ||
|
@@ -137,7 +134,37 @@ public function handle(User $user) { | |
$user = $action->run(); | ||
$this->assertTrue($user instanceof User); | ||
$this->assertEquals('John Doe', $user->name); | ||
$this->assertEquals('[email protected]', $user->email); | ||
} | ||
|
||
/** @test */ | ||
public function it_resolves_nullable_type_hinted_models() | ||
{ | ||
$this->loadLaravelMigrations(); | ||
$this->createUser(['name' => 'John Doe']); | ||
|
||
$action = new class(['user' => 1]) extends Action { | ||
public function handle(?User $user) { | ||
return $user; | ||
} | ||
}; | ||
|
||
$user = $action->run(); | ||
$this->assertTrue($user instanceof User); | ||
$this->assertEquals('John Doe', $user->name); | ||
} | ||
|
||
/** @test */ | ||
public function it_returns_null_when_nullable_type_hinted_models_cannot_be_found() | ||
{ | ||
$this->loadLaravelMigrations(); | ||
|
||
$action = new class(['user' => null]) extends Action { | ||
public function handle(?User $user) { | ||
return $user; | ||
} | ||
}; | ||
|
||
$this->assertNull($action->run()); | ||
} | ||
|
||
/** @test */ | ||
|