Completed
Push — master ( 97f422...f36802 )
by David
02:02
created

testGetRelatedFieldForOrganisationId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace Test\Unit;
4
5
use Test\TestCase;
6
use Taskforcedev\CrudApi\Helpers\CrudApi;
7
8
class CrudApiHelperTest extends TestCase
9
{
10
    public function testGetRelatedFieldForUserId()
11
    {
12
        $crudApi = new CrudApi(['namespace' => null]);
13
        $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...
14
        $this->assertEquals('user', $related_field);
15
    }
16
17
    public function testGetRelatedFieldForOrganisationId()
18
    {
19
        $crudApi = new CrudApi(['namespace' => null]);
20
        $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...
21
        $this->assertEquals('organisation', $related_field);
22
    }
23
24
    public function testGetModelDisplayNameWithoutAnInstance()
25
    {
26
        $options = [
27
            'namespace' => null,
28
            'model' => 'User'
29
        ];
30
        $crudApi = new CrudApi($options);
31
        $display = $crudApi->getModelDisplayName();
32
        $this->assertEquals('User', $display);
33
    }
34
35
    public function testAuthorUserModelBinding()
36
    {
37
        $crudApi = new CrudApi(['namespace' => 'Test\\Models\\', 'model' => 'Post']);
38
        $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...
39
        $this->assertEquals('author', $related_field);
40
        $relation = $crudApi->getRelatedModel($related_field);
41
        $class = get_class($relation);
42
        $this->assertEquals('Test\\Models\\User', $class);
43
    }
44
}