Skip to content

Commit 904cbd6

Browse files
committed
Merge branch 'singleton-routing' into 9.x
2 parents 8bcd484 + ed566a6 commit 904cbd6

File tree

6 files changed

+43
-14
lines changed

6 files changed

+43
-14
lines changed

src/Illuminate/Routing/Console/stubs/controller.nested.singleton.api.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ class {{ class }} extends Controller
5252
*/
5353
public function destroy({{ parentModel }} ${{ parentModelVariable }})
5454
{
55-
//
55+
abort(404);
5656
}
5757
}

src/Illuminate/Routing/Console/stubs/controller.nested.singleton.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ class {{ class }} extends Controller
7474
*/
7575
public function destroy({{ parentModel }} ${{ parentModelVariable }})
7676
{
77-
//
77+
abort(404);
7878
}
7979
}

src/Illuminate/Routing/Console/stubs/controller.singleton.api.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ class {{ class }} extends Controller
4646
*/
4747
public function destroy()
4848
{
49-
//
49+
abort(404);
5050
}
5151
}

src/Illuminate/Routing/Console/stubs/controller.singleton.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ class {{ class }} extends Controller
6666
*/
6767
public function destroy()
6868
{
69-
//
69+
abort(404);
7070
}
7171
}

src/Illuminate/Routing/ResourceRegistrar.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ResourceRegistrar
2626
*
2727
* @var string[]
2828
*/
29-
protected $singletonResourceDefaults = ['show', 'edit', 'update', 'destroy'];
29+
protected $singletonResourceDefaults = ['show', 'edit', 'update'];
3030

3131
/**
3232
* The parameters set for this resource instance.
@@ -251,8 +251,8 @@ protected function getResourceMethods($defaults, $options)
251251

252252
if (isset($options['creatable'])) {
253253
$methods = isset($options['apiSingleton'])
254-
? array_merge(['store'], $methods)
255-
: array_merge(['create', 'store'], $methods);
254+
? array_merge(['store', 'destroy'], $methods)
255+
: array_merge(['create', 'store', 'destroy'], $methods);
256256

257257
return $this->getResourceMethods(
258258
$methods, array_values(Arr::except($options, ['creatable']))

tests/Integration/Routing/RouteSingletonTest.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ public function testSingletonDefaults()
3636
$this->assertEquals(200, $response->getStatusCode());
3737
$this->assertSame('singleton update', $response->getContent());
3838

39-
$this->assertSame('http://localhost/avatar', route('avatar.destroy'));
40-
$response = $this->delete('/avatar');
41-
$this->assertEquals(200, $response->getStatusCode());
42-
$this->assertSame('singleton destroy', $response->getContent());
39+
// $this->assertSame('http://localhost/avatar', route('avatar.destroy'));
40+
// $response = $this->delete('/avatar');
41+
// $this->assertEquals(404, $response->getStatusCode());
42+
// $this->assertSame('singleton destroy', $response->getContent());
4343
}
4444

4545
public function testCreatableSingleton()
@@ -55,6 +55,11 @@ public function testCreatableSingleton()
5555
$response = $this->post('/avatar');
5656
$this->assertEquals(200, $response->getStatusCode());
5757
$this->assertSame('singleton store', $response->getContent());
58+
59+
$this->assertSame('http://localhost/avatar', route('avatar.destroy'));
60+
$response = $this->delete('/avatar');
61+
$this->assertEquals(200, $response->getStatusCode());
62+
$this->assertSame('singleton destroy', $response->getContent());
5863
}
5964

6065
public function testApiSingleton()
@@ -130,9 +135,9 @@ public function testSingletonExcept()
130135
$this->assertEquals(200, $response->getStatusCode());
131136
$this->assertSame('singleton update', $response->getContent());
132137

133-
$response = $this->delete('/avatar');
134-
$this->assertEquals(200, $response->getStatusCode());
135-
$this->assertSame('singleton destroy', $response->getContent());
138+
// $response = $this->delete('/avatar');
139+
// $this->assertEquals(200, $response->getStatusCode());
140+
// $this->assertSame('singleton destroy', $response->getContent());
136141
}
137142

138143
public function testSingletonName()
@@ -169,6 +174,30 @@ public function testNestedSingleton()
169174
$this->assertEquals(200, $response->getStatusCode());
170175
$this->assertSame('singleton update for 123', $response->getContent());
171176

177+
$response = $this->delete('/videos/123/thumbnail');
178+
$this->assertEquals(405, $response->getStatusCode());
179+
}
180+
181+
public function testCreatableNestedSingleton()
182+
{
183+
Route::singleton('videos.thumbnail', NestedSingletonTestController::class)->creatable();
184+
185+
$response = $this->get('/videos/123/thumbnail');
186+
$this->assertEquals(200, $response->getStatusCode());
187+
$this->assertSame('singleton show for 123', $response->getContent());
188+
189+
$response = $this->get('/videos/123/thumbnail/edit');
190+
$this->assertEquals(200, $response->getStatusCode());
191+
$this->assertSame('singleton edit for 123', $response->getContent());
192+
193+
$response = $this->put('/videos/123/thumbnail');
194+
$this->assertEquals(200, $response->getStatusCode());
195+
$this->assertSame('singleton update for 123', $response->getContent());
196+
197+
$response = $this->patch('/videos/123/thumbnail');
198+
$this->assertEquals(200, $response->getStatusCode());
199+
$this->assertSame('singleton update for 123', $response->getContent());
200+
172201
$response = $this->delete('/videos/123/thumbnail');
173202
$this->assertEquals(200, $response->getStatusCode());
174203
$this->assertSame('singleton destroy for 123', $response->getContent());

0 commit comments

Comments
 (0)