RouteNotDefinedSolutionProviderTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Facade\Ignition\Tests\Solutions;
  3. use Facade\Ignition\SolutionProviders\RouteNotDefinedSolutionProvider;
  4. use Facade\Ignition\Tests\TestCase;
  5. use Illuminate\Support\Facades\Route;
  6. use Illuminate\Support\Str;
  7. use Symfony\Component\Routing\Exception\RouteNotFoundException;
  8. class RouteNotDefinedSolutionProviderTest extends TestCase
  9. {
  10. /** @test */
  11. public function it_can_solve_a_route_not_defined_exception()
  12. {
  13. $canSolve = app(RouteNotDefinedSolutionProvider::class)->canSolve($this->getRouteNotDefinedException());
  14. $this->assertTrue($canSolve);
  15. }
  16. /** @test */
  17. public function it_can_recommend_changing_the_route_name()
  18. {
  19. Route::get('/test', 'TestController@typo')->name('test.typo');
  20. /** @var \Facade\IgnitionContracts\Solution $solution */
  21. $solution = app(RouteNotDefinedSolutionProvider::class)->getSolutions($this->getRouteNotDefinedException())[0];
  22. $this->assertTrue(Str::contains($solution->getSolutionDescription(), 'Did you mean `test.typo`?'));
  23. }
  24. /** @test */
  25. public function it_wont_recommend_another_route_if_the_names_are_too_different()
  26. {
  27. Route::get('/test', 'TestController@typo')->name('test.typo');
  28. /** @var \Facade\IgnitionContracts\Solution $solution */
  29. $solution = app(RouteNotDefinedSolutionProvider::class)->getSolutions($this->getRouteNotDefinedException('test.is-too-different'))[0];
  30. $this->assertFalse(Str::contains($solution->getSolutionDescription(), 'Did you mean'));
  31. }
  32. protected function getRouteNotDefinedException(string $route = 'test.typoo'): RouteNotFoundException
  33. {
  34. return new RouteNotFoundException("Route [{$route}] not defined.");
  35. }
  36. }