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