Skip to content

Commit

Permalink
Add tests for MiddlewareQueue::add()/prepend().
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Jul 27, 2016
1 parent 40d9671 commit 07aec60
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Http/MiddlewareQueue.php
Expand Up @@ -78,7 +78,7 @@ protected function resolve($index)
));
}

$callable = new $class;
$callable = new $className;
} else {
$callable = $this->queue[$index];
}
Expand Down
40 changes: 39 additions & 1 deletion tests/TestCase/Http/MiddlewareQueueTest.php
Expand Up @@ -14,6 +14,7 @@
*/
namespace Cake\Test\TestCase\Http;

use Cake\Core\Configure;
use Cake\Http\MiddlewareQueue;
use Cake\TestSuite\TestCase;
use TestApp\Middleware\SampleMiddleware;
Expand All @@ -38,7 +39,6 @@ public function testGet()
$this->assertNull($queue->get(1));
}


/**
* Test the return value of add()
*
Expand Down Expand Up @@ -115,6 +115,44 @@ public function testPrependOrdering()
$this->assertSame($one, $queue->get(1));
}

/**
* Test updating queue using class name
*
* @return void
*/
public function testAddingPrependingUsingString()
{
$appNamespace = Configure::read('App.namespace');
Configure::write('App.namespace', 'TestApp');

$queue = new MiddlewareQueue();
$queue->add('Sample');
$queue->prepend('TestApp\Middleware\SampleMiddleware');

$this->assertInstanceOf('TestApp\Middleware\SampleMiddleware', $queue->get(0));
$this->assertInstanceOf('TestApp\Middleware\SampleMiddleware', $queue->get(1));

Configure::write('App.namespace', $appNamespace);
}

/**
* Test updating queue using array
*
* @return void
*/
public function testAddingPrependingUsingArray()
{
$one = function () {
};

$queue = new MiddlewareQueue();
$queue->add([$one]);
$queue->prepend(['TestApp\Middleware\SampleMiddleware']);

$this->assertInstanceOf('TestApp\Middleware\SampleMiddleware', $queue->get(0));
$this->assertSame($one, $queue->get(1));
}

/**
* Test insertAt ordering
*
Expand Down

0 comments on commit 07aec60

Please sign in to comment.