Skip to content

Commit

Permalink
Enable MiddlewareQueue to be constructed with middleware objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Apr 29, 2017
1 parent 45b97d1 commit 1805536
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Http/MiddlewareQueue.php
Expand Up @@ -39,6 +39,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.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/TestCase/Http/MiddlewareQueueTest.php
Expand Up @@ -50,6 +50,15 @@ public function tearDown()
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()
*
Expand Down

0 comments on commit 1805536

Please sign in to comment.