Browse Source

Rename method to be consistent and use a verb.

mark_story 9 years ago
parent
commit
c2b9a4282e

+ 2 - 2
src/Routing/RouteBuilder.php

@@ -742,9 +742,9 @@ class RouteBuilder
      * @return $this
      * @see \Cake\Routing\RouteCollection::addMiddlewareToScope()
      */
-    public function middleware(...$names)
+    public function applyMiddleware(...$names)
     {
-        $this->_collection->enableMiddleware($this->_path, $names);
+        $this->_collection->applyMiddleware($this->_path, $names);
 
         return $this;
     }

+ 2 - 2
src/Routing/RouteCollection.php

@@ -411,13 +411,13 @@ class RouteCollection
     }
 
     /**
-     * Enable a registered middleware(s) for the provided path
+     * Apply a registered middleware(s) for the provided path
      *
      * @param string $path The URL path to register middleware for.
      * @param string[] $middleware The middleware names to add for the path.
      * @return $this
      */
-    public function enableMiddleware($path, array $middleware)
+    public function applyMiddleware($path, array $middleware)
     {
         foreach ($middleware as $name) {
             if (!$this->hasMiddleware($name)) {

+ 4 - 4
tests/TestCase/Routing/RouteBuilderTest.php

@@ -816,10 +816,10 @@ class RouteBuilderTest extends TestCase
      * @expectedExceptionMessage Cannot apply 'bad' middleware to path '/api'. It has not been registered.
      * @return void
      */
-    public function testMiddlewareInvalidName()
+    public function testApplyMiddlewareInvalidName()
     {
         $routes = new RouteBuilder($this->collection, '/api');
-        $routes->middleware('bad');
+        $routes->applyMiddleware('bad');
     }
 
     /**
@@ -827,14 +827,14 @@ class RouteBuilderTest extends TestCase
      *
      * @return void
      */
-    public function testMiddleware()
+    public function testApplyMiddleware()
     {
         $func = function () {
         };
         $routes = new RouteBuilder($this->collection, '/api');
         $routes->registerMiddleware('test', $func)
             ->registerMiddleware('test2', $func);
-        $result = $routes->middleware('test', 'test2');
+        $result = $routes->applyMiddleware('test', 'test2');
 
         $this->assertSame($result, $routes);
         $this->assertEquals(

+ 11 - 11
tests/TestCase/Routing/RouteCollectionTest.php

@@ -649,7 +649,7 @@ class RouteCollectionTest extends TestCase
      *
      * @return void
      */
-    public function testEnableMiddlewareBasic()
+    public function testApplyMiddlewareBasic()
     {
         $mock = $this->getMockBuilder('\stdClass')
             ->setMethods(['__invoke'])
@@ -657,7 +657,7 @@ class RouteCollectionTest extends TestCase
         $this->collection->registerMiddleware('callable', $mock);
         $this->collection->registerMiddleware('callback_two', $mock);
 
-        $result = $this->collection->enableMiddleware('/api', ['callable', 'callback_two']);
+        $result = $this->collection->applyMiddleware('/api', ['callable', 'callback_two']);
         $this->assertSame($result, $this->collection);
     }
 
@@ -674,7 +674,7 @@ class RouteCollectionTest extends TestCase
         $this->collection->registerMiddleware('callable', $mock);
         $this->collection->registerMiddleware('callback_two', $mock);
 
-        $result = $this->collection->enableMiddleware('/api', ['callable']);
+        $result = $this->collection->applyMiddleware('/api', ['callable']);
         $middleware = $this->collection->getMatchingMiddleware('/api/v1/articles');
         $this->assertCount(1, $middleware);
         $this->assertSame($middleware[0], $mock);
@@ -696,8 +696,8 @@ class RouteCollectionTest extends TestCase
         $this->collection->registerMiddleware('callable', $mock);
         $this->collection->registerMiddleware('callback_two', $mockTwo);
 
-        $this->collection->enableMiddleware('/api', ['callable']);
-        $this->collection->enableMiddleware('/api/v1/articles', ['callback_two']);
+        $this->collection->applyMiddleware('/api', ['callable']);
+        $this->collection->applyMiddleware('/api/v1/articles', ['callback_two']);
 
         $middleware = $this->collection->getMatchingMiddleware('/articles');
         $this->assertCount(0, $middleware);
@@ -727,8 +727,8 @@ class RouteCollectionTest extends TestCase
         $this->collection->registerMiddleware('callable', $mock);
         $this->collection->registerMiddleware('callback_two', $mockTwo);
 
-        $this->collection->enableMiddleware('/api', ['callable']);
-        $this->collection->enableMiddleware('/api/v1/articles', ['callback_two', 'callable']);
+        $this->collection->applyMiddleware('/api', ['callable']);
+        $this->collection->applyMiddleware('/api/v1/articles', ['callback_two', 'callable']);
 
         $middleware = $this->collection->getMatchingMiddleware('/api/v1/articles/1');
         $this->assertCount(2, $middleware);
@@ -740,14 +740,14 @@ class RouteCollectionTest extends TestCase
      *
      * @return void
      */
-    public function testEnableMiddlewareWithPlaceholder()
+    public function testApplyMiddlewareWithPlaceholder()
     {
         $mock = $this->getMockBuilder('\stdClass')
             ->setMethods(['__invoke'])
             ->getMock();
         $this->collection->registerMiddleware('callable', $mock);
 
-        $this->collection->enableMiddleware('/api-:version/articles/:article_id/comments', ['callable']);
+        $this->collection->applyMiddleware('/api-:version/articles/:article_id/comments', ['callable']);
 
         $middleware = $this->collection->getMatchingMiddleware('/api-1/articles/comments');
         $this->assertEmpty($middleware);
@@ -769,12 +769,12 @@ class RouteCollectionTest extends TestCase
      * @expectedExceptionMessage Cannot apply 'bad' middleware to path '/api'. It has not been registered.
      * @return void
      */
-    public function testEnableMiddlewareUnregistered()
+    public function testApplyMiddlewareUnregistered()
     {
         $mock = $this->getMockBuilder('\stdClass')
             ->setMethods(['__invoke'])
             ->getMock();
         $this->collection->registerMiddleware('callable', $mock);
-        $this->collection->enableMiddleware('/api', ['callable', 'bad']);
+        $this->collection->applyMiddleware('/api', ['callable', 'bad']);
     }
 }