Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #116 from spiffyjr/feature/any
Browse files Browse the repository at this point in the history
Added the any() method.
  • Loading branch information
weierophinney committed Sep 3, 2015
2 parents 1ff4527 + cab19e5 commit 4d012c2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions doc/book/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ where:
This method is typically only used if you want a single middleware to handle
multiple HTTP request methods.

### get(), post(), put(), patch(), delete()
### get(), post(), put(), patch(), delete(), any()

Each of the methods `get()`, `post()`, `put()`, `patch()`, and `delete()`
Each of the methods `get()`, `post()`, `put()`, `patch()`, `delete()`, and `any()`
proxies to `route()` and has the signature:

```php
Expand Down
11 changes: 11 additions & 0 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ public function __call($method, $args)
return call_user_func_array([$this, 'route'], $args);
}

/**
* @param string|Router\Route $path
* @param callable|string $middleware Middleware (or middleware service name) to associate with route.
* @param null|string $name the name of the route
* @return Router\Route
*/
public function any($path, $middleware, $name = null)
{
return $this->route($path, $middleware, null, $name);
}

/**
* Overload pipe() operation.
*
Expand Down
20 changes: 20 additions & 0 deletions test/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ public function testRouteMethodReturnsRouteInstance()
$this->assertSame($this->noopMiddleware, $route->getMiddleware());
}

public function testAnyRouteMethod()
{
$this->router->addRoute(Argument::type(Route::class))->shouldBeCalled();
$route = $this->getApp()->any('/foo', $this->noopMiddleware);
$this->assertInstanceOf(Route::class, $route);
$this->assertEquals('/foo', $route->getPath());
$this->assertSame($this->noopMiddleware, $route->getMiddleware());

$reflClass = new \ReflectionClass($this->getApp());
$routeMethods = $reflClass->getProperty('httpRouteMethods');
$routeMethods->setAccessible(true);
$routeMethods = $routeMethods->getValue($this->getApp());

foreach ($routeMethods as $method) {
$this->assertTrue($route->allowsMethod($method));
}

$this->assertSame($routeMethods, $route->getAllowedMethods());
}

/**
* @dataProvider commonHttpMethods
*/
Expand Down

0 comments on commit 4d012c2

Please sign in to comment.