Skip to content
Browse files

Map now throws UnexpectedType when attach route spec is bad, and [BC …

…BREAK] throws RouteNotFound when generate() cannot find the named route
  • Loading branch information...
1 parent 717beef commit 7173c382cbf8d6dcb4ae4901b2d8090ad18b7996 @pmjones pmjones committed Jan 4, 2013
Showing with 9 additions and 7 deletions.
  1. +2 −0 src.php
  2. +4 −2 src/Aura/Router/Map.php
  3. +3 −5 tests/Aura/Router/MapTest.php
View
2 src.php
@@ -1,5 +1,7 @@
<?php
require __DIR__ . '/src/Aura/Router/Exception.php';
+require __DIR__ . '/src/Aura/Router/Exception/RouteNotFound.php';
+require __DIR__ . '/src/Aura/Router/Exception/UnexpectedType.php';
require __DIR__ . '/src/Aura/Router/Map.php';
require __DIR__ . '/src/Aura/Router/Definition.php';
require __DIR__ . '/src/Aura/Router/DefinitionFactory.php';
View
6 src/Aura/Router/Map.php
@@ -10,6 +10,8 @@
*/
namespace Aura\Router;
+use Aura\Router\Exception;
+
/**
*
* A collection point for URI routes.
@@ -222,7 +224,7 @@ public function generate($name, $data = null)
}
// no joy
- return false;
+ throw new Exception\RouteNotFound($name);
}
/**
@@ -397,7 +399,7 @@ protected function getNextAttach()
// long form, no name
$spec = $val;
} else {
- throw new Exception("Route spec for '$key' should be a string or array.");
+ throw new Exception\UnexpectedType("Route spec for '$key' should be a string or array.");
}
// unset any path or name prefix on the spec itself
View
8 tests/Aura/Router/MapTest.php
@@ -74,9 +74,6 @@ public function testAddComplexRoute()
$this->assertSame('gir', $actual->values['zim']);
}
- /**
- * @expectedException \Aura\Router\Exception
- */
public function testAttachWithBadRouteSpec()
{
$this->map->attach(null, [
@@ -85,6 +82,7 @@ public function testAttachWithBadRouteSpec()
],
]);
+ $this->setExpectedException('Aura\Router\Exception\UnexpectedType');
$this->map->match('/', $this->server);
}
@@ -647,8 +645,8 @@ public function testGenerate()
// fail to match again, for code coverage of the portion that checks
// if there are definitions left to convert
+ $this->setExpectedException('Aura\Router\Exception\RouteNotFound');
$actual = $this->map->generate('no-route-again');
- $this->assertFalse($actual);
}
@@ -674,8 +672,8 @@ public function testGenerateWhenMissing()
]);
// fail to match
+ $this->setExpectedException('Aura\Router\Exception\RouteNotFound');
$actual = $this->map->generate('no-route');
- $this->assertFalse($actual);
}
public function testAttachAtConstructionTime()

0 comments on commit 7173c38

Please sign in to comment.
Something went wrong with that request. Please try again.