ViewNotFoundSolutionProviderTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Facade\Ignition\Tests\Solutions;
  3. use Facade\Ignition\SolutionProviders\ViewNotFoundSolutionProvider;
  4. use Facade\Ignition\Tests\TestCase;
  5. use Illuminate\Support\Facades\View;
  6. use Illuminate\Support\Str;
  7. use InvalidArgumentException;
  8. class ViewNotFoundSolutionProviderTest extends TestCase
  9. {
  10. public function setUp(): void
  11. {
  12. parent::setUp();
  13. View::addLocation(__DIR__.'/../stubs/views');
  14. }
  15. /** @test */
  16. public function it_can_solve_the_exception()
  17. {
  18. $canSolve = app(ViewNotFoundSolutionProvider::class)->canSolve($this->getViewNotFoundException());
  19. $this->assertTrue($canSolve);
  20. }
  21. /** @test */
  22. public function it_can_recommend_changing_a_typo_in_the_view_name()
  23. {
  24. /** @var \Facade\IgnitionContracts\Solution $solution */
  25. $solution = app(ViewNotFoundSolutionProvider::class)->getSolutions($this->getViewNotFoundException())[0];
  26. $this->assertTrue(Str::contains($solution->getSolutionDescription(), 'Did you mean `php-exception`?'));
  27. }
  28. /** @test */
  29. public function it_can_notice_if_the_view_name_contains_dots()
  30. {
  31. /** @var \Facade\IgnitionContracts\Solution $solution */
  32. $solution = app(ViewNotFoundSolutionProvider::class)->getSolutions($this->getViewNotFoundException('foo.bar'))[0];
  33. $this->assertTrue(Str::contains($solution->getSolutionDescription(), 'the . character'));
  34. }
  35. /** @test */
  36. public function it_wont_recommend_another_controller_class_if_the_names_are_too_different()
  37. {
  38. $unknownView = 'a-view-that-doesnt-exist-and-is-not-a-typo';
  39. /** @var \Facade\IgnitionContracts\Solution $solution */
  40. $solution = app(ViewNotFoundSolutionProvider::class)->getSolutions($this->getViewNotFoundException($unknownView))[0];
  41. $this->assertFalse(Str::contains($solution->getSolutionDescription(), 'Did you mean'));
  42. }
  43. protected function getViewNotFoundException(string $view = 'phpp-exceptionn'): InvalidArgumentException
  44. {
  45. return new InvalidArgumentException("View [{$view}] not found.");
  46. }
  47. }