Skip to content

Commit

Permalink
remove export check
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Dec 14, 2022
1 parent 443d0d6 commit 658cd5e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 49 deletions.
23 changes: 0 additions & 23 deletions src/Exceptions/NotRoutableException.php

This file was deleted.

26 changes: 10 additions & 16 deletions src/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
namespace Chevere\Router;

use Chevere\Message\Message;
use Chevere\Router\Exceptions\NotRoutableException;
use Chevere\Router\Exceptions\WithoutEndpointsException;
use Chevere\Router\Interfaces\IndexInterface;
use Chevere\Router\Interfaces\RouteInterface;
use Chevere\Router\Interfaces\RouterInterface;
use Chevere\Router\Interfaces\RoutesInterface;
use Chevere\Router\Parsers\StrictStd;
use Chevere\VariableSupport\Exceptions\UnableToStoreException;
use Chevere\VariableSupport\StorableVariable;
use FastRoute\DataGenerator\GroupCountBased;
use FastRoute\RouteCollector;

Expand All @@ -43,7 +40,7 @@ public function __construct()

public function withAddedRoute(string $group, RouteInterface $route): RouterInterface
{
$this->assertRoute($route);
$this->assertHasEndpoints($route);
$new = clone $this;
$new->index = $new->index->withAddedRoute($route, $group);
$new->routes = $new->routes->withAdded($route);
Expand Down Expand Up @@ -73,19 +70,16 @@ public function routeCollector(): RouteCollector
return $this->routeCollector;
}

private function assertRoute(RouteInterface $route): void
private function assertHasEndpoints(RouteInterface $route): void
{
try {
(new StorableVariable($route))->toExport();
} catch (UnableToStoreException $e) {
throw new NotRoutableException(previous: $e);
}
if ($route->endpoints()->count() === 0) {
throw new WithoutEndpointsException(
(new Message("Route %name% (%path%) doesn't contain any endpoint."))
->withCode('%path%', $route->path()->__toString())
->withCode('%name%', $route->name())
);
if ($route->endpoints()->count() > 0) {
return;
}

throw new WithoutEndpointsException(
(new Message("Route %name% (%path%) doesn't contain any endpoint."))
->withCode('%path%', $route->path()->__toString())
->withCode('%name%', $route->name())
);
}
}
10 changes: 0 additions & 10 deletions tests/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@

use Chevere\Http\Methods\GetMethod;
use Chevere\Router\Endpoint;
use Chevere\Router\Exceptions\NotRoutableException;
use Chevere\Router\Exceptions\WithoutEndpointsException;
use function Chevere\Router\route;
use Chevere\Router\Router;
use Chevere\Router\Tests\_resources\TestControllerNotExportable;
use Chevere\Router\Tests\_resources\TestControllerWithParameters;
use FastRoute\RouteCollector;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -75,12 +73,4 @@ public function testConstructInvalidArgument(): void
(new Router())
->withAddedRoute('my-group', $route);
}

public function testNotExportable(): void
{
$route = route('/test', GET: new TestControllerNotExportable());
$this->expectException(NotRoutableException::class);
(new Router())
->withAddedRoute('my-group', $route);
}
}

0 comments on commit 658cd5e

Please sign in to comment.