From 09243d68e30e4a5e8112f6443323f1ccd6743d65 Mon Sep 17 00:00:00 2001 From: Giorgio Premi Date: Mon, 2 Mar 2015 12:44:48 +0100 Subject: [PATCH 1/2] Do not use deprecated _method requirement --- Routing/RouteLoader.php | 18 +++++++++++++++--- Tests/Controller/AbstractControllerTest.php | 18 ++++++++++-------- Tests/Routing/RouteLoaderTest.php | 8 ++++---- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php index fad6c0f8..4e8df119 100644 --- a/Routing/RouteLoader.php +++ b/Routing/RouteLoader.php @@ -32,14 +32,22 @@ public function load($resource, $type = null) $upload = new Route( sprintf('%s/_uploader/%s/upload', $options['route_prefix'], $type), array('_controller' => $service . ':upload', '_format' => 'json'), - array('_method' => 'POST') + array(), + array(), + '', + array(), + array('POST') ); if ($options['enable_progress'] === true) { $progress = new Route( sprintf('%s/_uploader/%s/progress', $options['route_prefix'], $type), array('_controller' => $service . ':progress', '_format' => 'json'), - array('_method' => 'POST') + array(), + array(), + '', + array(), + array('POST') ); $routes->add(sprintf('_uploader_progress_%s', $type), $progress); @@ -49,7 +57,11 @@ public function load($resource, $type = null) $progress = new Route( sprintf('%s/_uploader/%s/cancel', $options['route_prefix'], $type), array('_controller' => $service . ':cancel', '_format' => 'json'), - array('_method' => 'POST') + array(), + array(), + '', + array(), + array('POST') ); $routes->add(sprintf('_uploader_cancel_%s', $type), $progress); diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php index 9e6d26a3..b5460ef4 100644 --- a/Tests/Controller/AbstractControllerTest.php +++ b/Tests/Controller/AbstractControllerTest.php @@ -40,8 +40,7 @@ public function testRoute() */ public function testCallByGet() { - $endpoint = $this->helper->endpoint($this->getConfigKey()); - $this->client->request('GET', $endpoint); + $this->implTestCallBy('GET'); } /** @@ -49,8 +48,12 @@ public function testCallByGet() */ public function testCallByDelete() { - $endpoint = $this->helper->endpoint($this->getConfigKey()); - $this->client->request('DELETE', $endpoint); + $this->implTestCallBy('DELETE'); + } + + public function testCallByPost() + { + $this->implTestCallBy('POST'); } /** @@ -58,16 +61,15 @@ public function testCallByDelete() */ public function testCallByPut() { - $endpoint = $this->helper->endpoint($this->getConfigKey()); - $this->client->request('PUT', $endpoint); + $this->implTestCallBy('PUT'); } - public function testCallByPost() + protected function implTestCallBy($method) { $client = $this->client; $endpoint = $this->helper->endpoint($this->getConfigKey()); - $client->request('POST', $endpoint, array(), array(), $this->requestHeaders); + $client->request($method, $endpoint, array(), array(), $this->requestHeaders); $response = $client->getResponse(); $this->assertTrue($response->isSuccessful()); diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php index 4058039d..a09385e4 100644 --- a/Tests/Routing/RouteLoaderTest.php +++ b/Tests/Routing/RouteLoaderTest.php @@ -33,8 +33,8 @@ public function testRouteLoader() foreach ($routes as $route) { $this->assertInstanceOf('Symfony\Component\Routing\Route', $route); - $this->assertEquals($route->getDefault('_format'), 'json'); - $this->assertEquals($route->getRequirement('_method'), 'POST'); + $this->assertEquals('json', $route->getDefault('_format')); + $this->assertEquals(array('POST'), $route->getMethods()); } } @@ -55,8 +55,8 @@ public function testPrefixedRoutes() foreach ($routes as $route) { $this->assertInstanceOf('Symfony\Component\Routing\Route', $route); - $this->assertEquals($route->getDefault('_format'), 'json'); - $this->assertEquals($route->getRequirement('_method'), 'POST'); + $this->assertEquals('json', $route->getDefault('_format')); + $this->assertEquals(array('POST'), $route->getMethods()); $this->assertEquals(0, strpos($route->getPath(), $prefix)); } From d60f1ae8960853385ad3f803bb3fcd3a5651c2c6 Mon Sep 17 00:00:00 2001 From: Giorgio Premi Date: Mon, 2 Mar 2015 12:45:23 +0100 Subject: [PATCH 2/2] Allow PUT and PATCH verbs for upload --- Routing/RouteLoader.php | 2 +- Tests/Controller/AbstractControllerTest.php | 8 +++++--- Tests/Routing/RouteLoaderTest.php | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Routing/RouteLoader.php b/Routing/RouteLoader.php index 4e8df119..cd8c070e 100644 --- a/Routing/RouteLoader.php +++ b/Routing/RouteLoader.php @@ -36,7 +36,7 @@ public function load($resource, $type = null) array(), '', array(), - array('POST') + array('POST', 'PUT', 'PATCH') ); if ($options['enable_progress'] === true) { diff --git a/Tests/Controller/AbstractControllerTest.php b/Tests/Controller/AbstractControllerTest.php index b5460ef4..2b0abf7e 100644 --- a/Tests/Controller/AbstractControllerTest.php +++ b/Tests/Controller/AbstractControllerTest.php @@ -51,14 +51,16 @@ public function testCallByDelete() $this->implTestCallBy('DELETE'); } + public function testCallByPatch() + { + $this->implTestCallBy('PATCH'); + } + public function testCallByPost() { $this->implTestCallBy('POST'); } - /** - * @expectedException Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException - */ public function testCallByPut() { $this->implTestCallBy('PUT'); diff --git a/Tests/Routing/RouteLoaderTest.php b/Tests/Routing/RouteLoaderTest.php index a09385e4..95b35ab0 100644 --- a/Tests/Routing/RouteLoaderTest.php +++ b/Tests/Routing/RouteLoaderTest.php @@ -34,7 +34,7 @@ public function testRouteLoader() foreach ($routes as $route) { $this->assertInstanceOf('Symfony\Component\Routing\Route', $route); $this->assertEquals('json', $route->getDefault('_format')); - $this->assertEquals(array('POST'), $route->getMethods()); + $this->assertContains('POST', $route->getMethods()); } } @@ -56,7 +56,7 @@ public function testPrefixedRoutes() foreach ($routes as $route) { $this->assertInstanceOf('Symfony\Component\Routing\Route', $route); $this->assertEquals('json', $route->getDefault('_format')); - $this->assertEquals(array('POST'), $route->getMethods()); + $this->assertContains('POST', $route->getMethods()); $this->assertEquals(0, strpos($route->getPath(), $prefix)); }