Skip to content

Commit

Permalink
Merge pull request #167 from giosh94mhz/allow_put_patch
Browse files Browse the repository at this point in the history
Allow PUT and PATCH method for upload route
  • Loading branch information
Jim Schmid committed Mar 11, 2015
2 parents 829d3e4 + d60f1ae commit 593e54e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
18 changes: 15 additions & 3 deletions Routing/RouteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', 'PUT', 'PATCH')
);

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);
Expand All @@ -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);
Expand Down
26 changes: 15 additions & 11 deletions Tests/Controller/AbstractControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,34 +40,38 @@ public function testRoute()
*/
public function testCallByGet()
{
$endpoint = $this->helper->endpoint($this->getConfigKey());
$this->client->request('GET', $endpoint);
$this->implTestCallBy('GET');
}

/**
* @expectedException Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
public function testCallByDelete()
{
$endpoint = $this->helper->endpoint($this->getConfigKey());
$this->client->request('DELETE', $endpoint);
$this->implTestCallBy('DELETE');
}

/**
* @expectedException Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
public function testCallByPut()
public function testCallByPatch()
{
$endpoint = $this->helper->endpoint($this->getConfigKey());
$this->client->request('PUT', $endpoint);
$this->implTestCallBy('PATCH');
}

public function testCallByPost()
{
$this->implTestCallBy('POST');
}

public function testCallByPut()
{
$this->implTestCallBy('PUT');
}

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());
Expand Down
8 changes: 4 additions & 4 deletions Tests/Routing/RouteLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->assertContains('POST', $route->getMethods());
}
}

Expand All @@ -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->assertContains('POST', $route->getMethods());

$this->assertEquals(0, strpos($route->getPath(), $prefix));
}
Expand Down

0 comments on commit 593e54e

Please sign in to comment.