Person   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 21
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A getSurname() 0 4 1
1
<?php
2
3
namespace SumoCoders\FrameworkSearchBundle\Tests\Entity;
4
5
use SumoCoders\FrameworkSearchBundle\Entity\IndexItem;
6
7
class IndexItemTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @var SumoCoders\FrameworkSearchBundle\Entity\IndexItem
11
     */
12
    private $indexItem;
13
14
    /**
15
     * @var array
16
     */
17
    private $defaultData = array(
18
        'objectType' => 'User',
19
        'otherId' => 1,
20
        'field' => 'nickname',
21
        'value' => 'J. Doe',
22
    );
23
24
    /**
25
     * Test the getters and setters
26
     */
27
    public function testGettersAndSetters()
28
    {
29
        $this->indexItem = new IndexItem(
0 ignored issues
show
Documentation Bug introduced by
It seems like new \SumoCoders\Framewor...->defaultData['value']) of type object<SumoCoders\Framew...undle\Entity\IndexItem> is incompatible with the declared type object<SumoCoders\Framew...undle\Entity\IndexItem> of property $indexItem.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
30
            $this->defaultData['objectType'],
31
            $this->defaultData['otherId'],
32
            $this->defaultData['field'],
33
            $this->defaultData['value']
34
        );
35
36
        $this->assertEquals($this->defaultData['objectType'], $this->indexItem->getObjectType());
37
        $this->assertEquals($this->defaultData['otherId'], $this->indexItem->getOtherId());
38
        $this->assertEquals($this->defaultData['field'], $this->indexItem->getField());
39
        $this->assertEquals($this->defaultData['value'], $this->indexItem->getValue());
40
    }
41
42
    public function testCreateMultipleObjectsBasedOnProperties()
43
    {
44
        $properties = array(
45
            'name' => 'John',
46
            'surname' => 'Doe',
47
            'email' => '[email protected]',
48
            'nickname' => 'J. Doe',
49
        );
50
51
        $fakeObject = new \stdClass();
52
        $fakeObject->name = 'John';
53
        $fakeObject->surname = 'Doe';
54
        $fakeObject->email = '[email protected]';
55
        $fakeObject->nickname = 'J. Doe';
56
57
        $indexItems = IndexItem::createMultipleObjectsBasedOnProperties(
58
            $this->defaultData['objectType'],
59
            $this->defaultData['otherId'],
60
            array_keys($properties),
61
            $fakeObject
62
        );
63
64
        foreach ($indexItems as $index) {
65
            /** @var SumoCoders\FrameworkSearchBundle\Entity\IndexItem $index*/
66
            $this->assertInstanceOf('\SumoCoders\FrameworkSearchBundle\Entity\IndexItem', $index);
67
            $this->assertEquals($properties[$index->getField()], $index->getValue());
68
        }
69
    }
70
71
    public function testCreateMultipleObjectsBasedOnPropertiesFromObject()
72
    {
73
        $properties = array(
74
            'name' => 'John',
75
            'surname' => 'Doe',
76
        );
77
        $object = new Person('John', 'Doe');
78
79
        $indexItems = IndexItem::createMultipleObjectsBasedOnProperties(
80
            $this->defaultData['objectType'],
81
            $this->defaultData['otherId'],
82
            array_keys($properties),
83
            $object
84
        );
85
86
        foreach ($indexItems as $index) {
87
            /** @var SumoCoders\FrameworkSearchBundle\Entity\IndexItem $index*/
88
            $this->assertInstanceOf('\SumoCoders\FrameworkSearchBundle\Entity\IndexItem', $index);
89
            $this->assertEquals($properties[$index->getField()], $index->getValue());
90
        }
91
    }
92
}
93
94
/**
95
 * Test class to test building an index item from a real object
96
 */
97
final class Person
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
98
{
99
    private $name;
100
    private $surname;
101
102
    public function __construct($name, $surname)
103
    {
104
        $this->name = $name;
105
        $this->surname = $surname;
106
    }
107
108
    public function getName()
109
    {
110
        return $this->name;
111
    }
112
113
    public function getSurname()
114
    {
115
        return $this->surname;
116
    }
117
}
118