Completed
Push — master ( ade8c5...1e1451 )
by David
01:56
created

testGetModelDisplayNameWithoutAnInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
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');
0 ignored issues
show
Documentation Bug introduced by
The method getRelatedField does not exist on object<Taskforcedev\CrudApi\Helpers\CrudApi>? Since you implemented __call, maybe consider adding a @method annotation.

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:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
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');
0 ignored issues
show
Documentation Bug introduced by
The method getRelatedField does not exist on object<Taskforcedev\CrudApi\Helpers\CrudApi>? Since you implemented __call, maybe consider adding a @method annotation.

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:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
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');
0 ignored issues
show
Documentation Bug introduced by
The method getRelatedField does not exist on object<Taskforcedev\CrudApi\Helpers\CrudApi>? Since you implemented __call, maybe consider adding a @method annotation.

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:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
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
}