setEmailThrowsInvalidArgumentExceptoinWhenInvalid()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace User\Tests\Entity;
5
6
use Common\ChangeProtectedAttribute;
7
use User\Entity\User;
8
use PHPUnit_Framework_TestCase;
9
use stdClass;
10
11
/**
12
 * User test case.
13
 *
14
 * @author Thiago Paes <[email protected]>
15
 */
16
class UserTest extends PHPUnit_Framework_TestCase
17
{
18
    use ChangeProtectedAttribute;
19
20
    /**
21
     * @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...
22
     */
23
    public function validObjects()
24
    {
25
        $obj = new stdClass();
26
        $obj->id = 1;
27
        $obj->name  = 'Teste';
28
        $obj->email = '[email protected]';
29
30
        return [
31
            [
32
                $obj
33
            ]
34
        ];
35
    }
36
37
    /**
38
     * @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...
39
     */
40
    public function invalidObjects()
41
    {
42
        $obj = new stdClass();
43
        $obj->id = 'SS';
44
        $obj->name = '';
45
        $obj->email = 'lalala';
46
47
        return [
48
            [
49
                $obj
50
            ]
51
        ];
52
    }
53
54
    /**
55
     * @test
56
     * @dataProvider validObjects
57
     * @covers       \User\Entity\User::setName
58
     */
59
    public function setNameReturnEmptyOnSuccess($obj)
60
    {
61
        $user = new User();
62
63
        $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...
64
65
        $this->assertEmpty($result);
66
    }
67
68
    /**
69
     * @test
70
     * @dataProvider invalidObjects
71
     * @covers       \User\Entity\User::setName
72
     * @expectedException \InvalidArgumentException
73
     */
74
    public function setNameThrowsExceptionWhenEmpty($obj)
75
    {
76
        $user = new User();
77
        $user->setName($obj->name);
78
    }
79
80
    /**
81
     * @test
82
     * @dataProvider validObjects
83
     * @covers       \User\Entity\User::getName
84
     */
85
    public function getNameReturnNameAttribute($obj)
86
    {
87
        $user = new User();
88
89
        $this->modifyAttribute($user, 'name', $obj->name);
90
91
        $this->assertEquals($user->getName(), $obj->name);
92
    }
93
94
    /**
95
     * @test
96
     * @dataProvider validObjects
97
     * @covers       \User\Entity\User::getEmail
98
     */
99
    public function getEmailReturnEmailAttribute($obj)
100
    {
101
        $user = new User();
102
103
        $this->modifyAttribute($user, 'email', $obj->email);
104
105
        $this->assertEquals($user->getEmail(), $obj->email);
106
    }
107
108
    /**
109
     * @test
110
     * @dataProvider validObjects
111
     * @covers       \User\Entity\User::setEmail
112
     */
113
    public function setEmailReturnEmptyOnSuccess($obj)
114
    {
115
        $user = new User();
116
117
        $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...
118
119
        $this->assertEmpty($result);
120
    }
121
122
    /**
123
     * @test
124
     * @dataProvider invalidObjects
125
     * @covers       \User\Entity\User::setEmail
126
     * @expectedException \InvalidArgumentException
127
     */
128
    public function setEmailThrowsInvalidArgumentExceptoinWhenInvalid($obj)
129
    {
130
        $user = new User();
131
        $user->setEmail($obj->email);
132
    }
133
}
134