Completed
Push — master ( 7eae42...8f150d )
by Thiago
10:26
created

UserTest::setNameReturnEmptyOnSuccess()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
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 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace User\Tests\Entity;
5
6
use DateTime;
7
use Common\ChangeProtectedAttribute;
8
use User\Entity\User;
9
use PHPUnit_Framework_TestCase;
10
use stdClass;
11
12
/**
13
 * User test case.
14
 *
15
 * @author Thiago Paes <[email protected]>
16
 * @author Romeu Mattos <[email protected]>
17
 */
18
class UserTest extends PHPUnit_Framework_TestCase
19
{
20
    use ChangeProtectedAttribute;
21
22
    /**
23
     * @return multitype:multitype:number
0 ignored issues
show
Documentation introduced by
The doc-type multitype:multitype:number could not be parsed: Unknown type name "multitype:multitype:number" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
24
     */
25 View Code Duplication
    public function validObjects()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $obj = new stdClass();
28
        $obj->id = 1;
29
        $obj->created = (new DateTime());
30
        $obj->updated = (new DateTime())->modify('+1 day');
31
        $obj->name  = 'Teste';
32
        $obj->email = '[email protected]';
33
34
        return [
35
            [
36
                $obj
37
            ]
38
        ];
39
    }
40
41
    /**
42
     * @return multitype:multitype:number
0 ignored issues
show
Documentation introduced by
The doc-type multitype:multitype:number could not be parsed: Unknown type name "multitype:multitype:number" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
43
     */
44 View Code Duplication
    public function invalidObjects()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        $obj = new stdClass();
47
        $obj->id = 'SS';
48
        $obj->created = (new DateTime())->modify('+3 day');
49
        $obj->updated = (new DateTime())->modify('-10 day');
50
        $obj->name = '';
51
        $obj->email = 'lalala';
52
53
        return [
54
            [
55
                $obj
56
            ]
57
        ];
58
    }
59
60
    /**
61
     * @test
62
     * @dataProvider validObjects
63
     * @covers       \User\Entity\User::setName
64
     */
65
    public function setNameReturnEmptyOnSuccess($obj)
66
    {
67
        $user = new User();
68
69
        $result = $user->setName($obj->name);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $user->setName($obj->name) (which targets User\Entity\User::setName()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
70
71
        $this->assertEmpty($result);
72
    }
73
74
    /**
75
     * @test
76
     * @dataProvider invalidObjects
77
     * @covers       \User\Entity\User::setName
78
     * @expectedException \InvalidArgumentException
79
     */
80
    public function setNameThrowsExceptionWhenEmpty($obj)
81
    {
82
        $user = new User();
83
        $user->setName($obj->name);
84
    }
85
86
    /**
87
     * @test
88
     * @dataProvider validObjects
89
     * @covers       \User\Entity\User::getName
90
     */
91
    public function getNameReturnNameAttribute($obj)
92
    {
93
        $user = new User();
94
95
        $this->modifyAttribute($user, 'name', $obj->name);
96
97
        $this->assertEquals($user->getName(), $obj->name);
98
    }
99
100
    /**
101
     * @test
102
     * @dataProvider validObjects
103
     * @covers       \User\Entity\User::getEmail
104
     */
105
    public function getEmailReturnEmailAttribute($obj)
106
    {
107
        $user = new User();
108
109
        $this->modifyAttribute($user, 'email', $obj->email);
110
111
        $this->assertEquals($user->getEmail(), $obj->email);
112
    }
113
114
    /**
115
     * @test
116
     * @dataProvider validObjects
117
     * @covers       \User\Entity\User::setEmail
118
     */
119
    public function setEmailReturnEmptyOnSuccess($obj)
120
    {
121
        $user = new User();
122
123
        $result = $user->setEmail($obj->email);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $result is correct as $user->setEmail($obj->email) (which targets User\Entity\User::setEmail()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
124
125
        $this->assertEmpty($result);
126
    }
127
128
    /**
129
     * @test
130
     * @dataProvider invalidObjects
131
     * @covers       \User\Entity\User::setEmail
132
     * @expectedException \InvalidArgumentException
133
     */
134
    public function setEmailThrowsInvalidArgumentExceptoinWhenInvalid($obj)
135
    {
136
        $user = new User();
137
        $user->setEmail($obj->email);
138
    }
139
}
140