UndefinedPropertySolutionProviderTest.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. use Facade\Ignition\SolutionProviders\UndefinedPropertySolutionProvider;
  3. use Facade\Ignition\Tests\TestCase;
  4. class UndefinedPropertySolutionProviderTest extends TestCase
  5. {
  6. /** @test */
  7. public function it_can_solve_an_undefined_property_exception_when_there_is_a_similar_property()
  8. {
  9. $canSolve = app(UndefinedPropertySolutionProvider::class)->canSolve($this->getUndefinedPropertyException());
  10. $this->assertTrue($canSolve);
  11. }
  12. /** @test */
  13. public function it_cannot_solve_an_undefined_property_exception_when_there_is_no_similar_property()
  14. {
  15. $canSolve = app(UndefinedPropertySolutionProvider::class)->canSolve($this->getUndefinedPropertyException('balance'));
  16. $this->assertFalse($canSolve);
  17. }
  18. /** @test */
  19. public function it_can_recommend_a_property_name_when_there_is_a_similar_property()
  20. {
  21. /** @var \Facade\IgnitionContracts\Solution $solution */
  22. $solution = app(UndefinedPropertySolutionProvider::class)->getSolutions($this->getUndefinedPropertyException())[0];
  23. $this->assertEquals('Did you mean Facade\Ignition\Tests\Support\Models\Car::$color ?', $solution->getSolutionDescription());
  24. }
  25. /** @test */
  26. public function it_cannot_recommend_a_property_name_when_there_is_no_similar_property()
  27. {
  28. /** @var \Facade\IgnitionContracts\Solution $solution */
  29. $solution = app(UndefinedPropertySolutionProvider::class)->getSolutions($this->getUndefinedPropertyException('balance'))[0];
  30. $this->assertEquals('', $solution->getSolutionDescription());
  31. }
  32. protected function getUndefinedPropertyException(string $property = 'colro'): ErrorException
  33. {
  34. return new ErrorException("Undefined property: Facade\Ignition\Tests\Support\Models\Car::$$property ");
  35. }
  36. }