Skip to content
Permalink
Browse files

Raise an exception in insertBefore()

Raise an exception When attempting to insertBefore an unknown middleware.
Based on feedback in cakephp/docs#4023 this is what the reviewers felt
was a more correct behavior.
  • Loading branch information...
markstory committed Jun 1, 2016
1 parent a65a4f5 commit 33bbf8424ec6769ba75c2547395c71405c10cdcc
Showing with 4 additions and 6 deletions.
  1. +2 −1 src/Http/MiddlewareStack.php
  2. +2 −5 tests/TestCase/Http/MiddlewareStackTest.php
@@ -15,6 +15,7 @@
namespace Cake\Http;
use Countable;
use LogicException;
/**
* Provides methods for creating and manipulating a 'stack' of
@@ -108,7 +109,7 @@ public function insertBefore($class, $callable)
if ($found) {
return $this->insertAt($i, $callable);
}
return $this->push($callable);
throw new LogicException(sprintf("No middleware matching '%s' could be found.", $class));
}
/**
@@ -206,6 +206,8 @@ public function testInsertBefore()
/**
* Test insertBefore an invalid classname
*
* @expectedException LogicException
* @expectedExceptionMessage No middleware matching 'InvalidClassName' could be found.
* @return void
*/
public function testInsertBeforeInvalid()
@@ -217,11 +219,6 @@ public function testInsertBeforeInvalid()
};
$stack = new MiddlewareStack();
$stack->push($one)->push($two)->insertBefore('InvalidClassName', $three);
$this->assertCount(3, $stack);
$this->assertSame($one, $stack->get(0));
$this->assertSame($two, $stack->get(1));
$this->assertSame($three, $stack->get(2));
}
/**

0 comments on commit 33bbf84

Please sign in to comment.
You can’t perform that action at this time.