Skip to content

Commit 8127309

Browse files
committed
Setup test Model in tests for clarity
1 parent b4f9f75 commit 8127309

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

tests/Stubs/Model.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,16 @@
77

88
class Model extends BaseModel
99
{
10-
/**
11-
* Fake localized slugs.
12-
*
13-
* @var array
14-
*/
15-
protected $slugs = [
16-
'en' => 'en-slug',
17-
'nl' => 'nl-slug',
18-
];
10+
protected $guarded = [];
1911

2012
/**
21-
* Fake localized route key.
13+
* Get the (fake) slug attribute.
2214
*
23-
* @return mixed
15+
* @return string
2416
*/
25-
public function getRouteKey()
17+
protected function getSlugAttribute()
2618
{
27-
return $this->slugs[App::getLocale()];
19+
return $this->attributes['slug'][App::getLocale()];
2820
}
2921

3022
/**
@@ -36,7 +28,7 @@ public function getRouteKey()
3628
*/
3729
public function resolveRouteBinding($slug)
3830
{
39-
$validSlug = $this->slugs[App::getLocale()];
31+
$validSlug = $this->attributes['slug'][App::getLocale()];
4032

4133
if ($validSlug !== $slug) {
4234
abort(404);

tests/Unit/Middleware/SetLocaleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,15 @@ public function it_allows_for_route_model_binding_using_a_localized_route_key()
8484
$this->setSupportedLocales(['en', 'nl']);
8585
$this->setUseLocaleMiddleware(true);
8686

87+
$model = (new Model([
88+
'slug' => [
89+
'en' => 'en-slug',
90+
'nl' => 'nl-slug',
91+
],
92+
]))->setKeyName('slug');
93+
94+
App::instance(Model::class, $model);
95+
8796
Route::localized(function () {
8897
Route::get('route/{model}', function (Model $model) {})
8998
->middleware(['web']);

tests/Unit/UrlGeneratorTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,21 @@ public function it_temporarily_changes_the_app_locale_when_generating_a_route_ur
125125
$this->setSupportedLocales(['en', 'nl']);
126126
$this->setAppLocale('en');
127127

128+
$model = (new Model([
129+
'slug' => [
130+
'en' => 'en-slug',
131+
'nl' => 'nl-slug',
132+
],
133+
]))->setKeyName('slug');
134+
135+
App::instance(Model::class, $model);
136+
128137
$this->registerRoute('en/route/{slug}', 'en.route.name');
129138
$this->registerRoute('nl/route/{slug}', 'nl.route.name');
130139

131-
$this->assertEquals(url('en/route/en-slug'), route('route.name', [new Model]));
132-
$this->assertEquals(url('en/route/en-slug'), route('route.name', [new Model], true, 'en'));
133-
$this->assertEquals(url('nl/route/nl-slug'), route('route.name', [new Model], true, 'nl'));
140+
$this->assertEquals(url('en/route/en-slug'), route('route.name', [$model]));
141+
$this->assertEquals(url('en/route/en-slug'), route('route.name', [$model], true, 'en'));
142+
$this->assertEquals(url('nl/route/nl-slug'), route('route.name', [$model], true, 'nl'));
134143
}
135144

136145
/** @test */

0 commit comments

Comments
 (0)