1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Test\Unit; |
4
|
|
|
|
5
|
|
|
use Test\TestCase; |
6
|
|
|
use \Mockery as m; |
7
|
|
|
use Taskforcedev\CrudApi\Helpers\CrudApi; |
8
|
|
|
|
9
|
|
|
class CrudApiHelperTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
public function testGetRelatedFieldForUserId() |
12
|
|
|
{ |
13
|
|
|
$crudApi = new CrudApi(['namespace' => null]); |
14
|
|
|
$related_field = $crudApi->getRelatedField('user_id'); |
|
|
|
|
15
|
|
|
$this->assertEquals('user', $related_field); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testGetRelatedFieldForOrganisationId() |
19
|
|
|
{ |
20
|
|
|
$crudApi = new CrudApi(['namespace' => null]); |
21
|
|
|
$related_field = $crudApi->getRelatedField('organisation_id'); |
|
|
|
|
22
|
|
|
$this->assertEquals('organisation', $related_field); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function testGetModelDisplayNameWithoutAnInstance() |
26
|
|
|
{ |
27
|
|
|
$options = [ |
28
|
|
|
'namespace' => null, |
29
|
|
|
'model' => 'User' |
30
|
|
|
]; |
31
|
|
|
$crudApi = new CrudApi($options); |
32
|
|
|
$display = $crudApi->getModelDisplayName(); |
33
|
|
|
$this->assertEquals('User', $display); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testAuthorUserModelBinding() |
37
|
|
|
{ |
38
|
|
|
$crudApi = new CrudApi(['namespace' => 'Test\\Models\\', 'model' => 'Post']); |
39
|
|
|
$related_field = $crudApi->getRelatedField('author_id'); |
|
|
|
|
40
|
|
|
$this->assertEquals('author', $related_field); |
41
|
|
|
$relation = $crudApi->getRelatedModel($related_field); |
42
|
|
|
$class = get_class($relation); |
43
|
|
|
$this->assertEquals('Test\\Models\\User', $class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testSetModelHelper() |
47
|
|
|
{ |
48
|
|
|
$options = ['namespace' => null]; |
49
|
|
|
$crudApi = new CrudApi($options); |
50
|
|
|
$crudApi->setModelHelper('test'); |
|
|
|
|
51
|
|
|
$this->assertEquals('test', $crudApi->modelHelper); |
52
|
|
|
} |
53
|
|
|
} |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: