Browse Source

Enable MiddlewareQueue to be constructed with middleware objects.

Mark Story 9 years ago
parent
commit
180553633c
2 changed files with 19 additions and 0 deletions
  1. 10 0
      src/Http/MiddlewareQueue.php
  2. 9 0
      tests/TestCase/Http/MiddlewareQueueTest.php

+ 10 - 0
src/Http/MiddlewareQueue.php

@@ -40,6 +40,16 @@ class MiddlewareQueue implements Countable
     protected $callables = [];
 
     /**
+     * Constructor
+     *
+     * @param array $middleware The list of middleware to append.
+     */
+    public function __construct(array $middleware = [])
+    {
+        $this->queue = $middleware;
+    }
+
+    /**
      * Get the middleware at the provided index.
      *
      * @param int $index The index to fetch.

+ 9 - 0
tests/TestCase/Http/MiddlewareQueueTest.php

@@ -50,6 +50,15 @@ class MiddlewareQueueTest extends TestCase
         Configure::write('App.namespace', $this->appNamespace);
     }
 
+    public function testConstructorAddingMiddleware()
+    {
+        $cb = function () {
+        };
+        $queue = new MiddlewareQueue([$cb]);
+        $this->assertCount(1, $queue);
+        $this->assertSame($cb, $queue->get(0));
+    }
+
     /**
      * Test get()
      *