Skip to content

Commit

Permalink
add failling test on inserting Middleware instances
Browse files Browse the repository at this point in the history
  • Loading branch information
antograssiot committed Aug 18, 2016
1 parent ad52e46 commit daa5dbe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
26 changes: 17 additions & 9 deletions tests/TestCase/Http/MiddlewareQueueTest.php
Expand Up @@ -17,6 +17,7 @@
use Cake\Core\Configure;
use Cake\Http\MiddlewareQueue;
use Cake\TestSuite\TestCase;
use TestApp\Middleware\DumbMiddleware;
use TestApp\Middleware\SampleMiddleware;

/**
Expand Down Expand Up @@ -186,12 +187,14 @@ public function testInsertAt()
};
$three = function () {
};
$four = new SampleMiddleware();

$queue = new MiddlewareQueue();
$queue->add($one)->add($two)->insertAt(0, $three);
$queue->add($one)->add($two)->insertAt(0, $three)->insertAt(2, $four);
$this->assertSame($three, $queue->get(0));
$this->assertSame($one, $queue->get(1));
$this->assertSame($two, $queue->get(2));
$this->assertSame($four, $queue->get(2));
$this->assertSame($two, $queue->get(3));

$queue = new MiddlewareQueue();
$queue->add($one)->add($two)->insertAt(1, $three);
Expand Down Expand Up @@ -231,13 +234,15 @@ public function testInsertAtNegative()
};
$two = function () {
};
$three = new SampleMiddleWare();

$queue = new MiddlewareQueue();
$queue->add($one)->insertAt(-1, $two);
$queue->add($one)->insertAt(-1, $two)->insertAt(-1, $three);

$this->assertCount(2, $queue);
$this->assertSame($two, $queue->get(0));
$this->assertSame($one, $queue->get(1));
$this->assertCount(3, $queue);
$this->assertSame($three, $queue->get(0));
$this->assertSame($two, $queue->get(1));
$this->assertSame($one, $queue->get(2));
}

/**
Expand All @@ -252,13 +257,16 @@ public function testInsertBefore()
$two = new SampleMiddleware();
$three = function () {
};
$four = new DumbMiddleware();

$queue = new MiddlewareQueue();
$queue->add($one)->add($two)->insertBefore(SampleMiddleware::class, $three);
$queue->add($one)->add($two)->insertBefore(SampleMiddleware::class, $three)->insertBefore(SampleMiddleware::class, $four);

$this->assertCount(3, $queue);
$this->assertCount(4, $queue);
$this->assertSame($one, $queue->get(0));
$this->assertSame($three, $queue->get(1));
$this->assertSame($two, $queue->get(2));
$this->assertSame($four, $queue->get(2));
$this->assertSame($two, $queue->get(3));

$two = SampleMiddleware::class;
$queue = new MiddlewareQueue();
Expand Down
25 changes: 25 additions & 0 deletions tests/test_app/TestApp/Middleware/DumbMiddleware.php
@@ -0,0 +1,25 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.3.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace TestApp\Middleware;

/**
* Testing stub for middleware tests.
*/
class DumbMiddleWare {
function __invoke($request, $response, $next)
{
return $next($request, $response);
}
}

0 comments on commit daa5dbe

Please sign in to comment.