/** * Transforms an object (route) to a string (id). * * @param RouteInterface|string $route * * @return string * * @throws TransformationFailedException if object (route) is of wrong type */ public function transform($route) { if (null === $route) { return; } if ($route instanceof RouteInterface || $route instanceof Generic) { return $route->getId(); } throw new TransformationFailedException(sprintf('"%s" should be of type %s or %s!', get_class($route), RouteInterface::class, Generic::class)); }
/** * Transforms an object (route) to a string (id). * * @param RouteInterface|string $route * * @return string * * @throws TransformationFailedException if object (route) is of wrong type */ public function transform($route) { if (null === $route) { return; } if (!$route instanceof RouteInterface) { throw new UnexpectedTypeException($route, RouteInterface::class); } return $route->getId(); }
public function it_should_transform_route_to_id(RouteInterface $route) { $route->getId()->willReturn('/some/path/id'); $this->transform($route)->shouldReturn('/some/path/id'); }