UserTest::testUsername()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 7
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
namespace Wonnova\SDK\Test\Model;
3
4
use PHPUnit_Framework_TestCase as TestCase;
5
use Wonnova\SDK\Model\User;
6
7
class UserTest extends TestCase
8
{
9
    /**
10
     * @var User
11
     */
12
    private $user;
13
14
    public function setUp()
15
    {
16
        $this->user = new User();
17
    }
18
19
    public function testUserId()
20
    {
21
        $expected = '273c4392-4c5k-4c3b-a70e-72375216702f';
22
        $this->assertNull($this->user->getUserId());
23
        $this->assertSame($this->user, $this->user->setUserId($expected));
24
        $this->assertEquals($expected, $this->user->getUserId());
25
    }
26
27
    public function testUsername()
28
    {
29
        $expected = 'foobar';
30
        $this->assertNull($this->user->getUsername());
31
        $this->assertSame($this->user, $this->user->setUsername($expected));
32
        $this->assertEquals($expected, $this->user->getUsername());
33
    }
34
35
    public function testProvider()
36
    {
37
        $expected = 'facebook';
38
        $this->assertNull($this->user->getProvider());
39
        $this->assertSame($this->user, $this->user->setProvider($expected));
40
        $this->assertEquals($expected, $this->user->getProvider());
41
    }
42
43
    public function testFullName()
44
    {
45
        $expected = 'Jane Doe';
46
        $this->assertNull($this->user->getFullName());
47
        $this->assertSame($this->user, $this->user->setFullName($expected));
48
        $this->assertEquals($expected, $this->user->getFullName());
49
    }
50
51
    public function testAvatar()
52
    {
53
        $expected = 'https://graph.facebook.com';
54
        $this->assertNull($this->user->getAvatar());
55
        $this->assertSame($this->user, $this->user->setAvatar($expected));
56
        $this->assertEquals($expected, $this->user->getAvatar());
57
    }
58
59 View Code Duplication
    public function testDateOfBirth()
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...
60
    {
61
        $expected = new \DateTime('1990-05-08 00:00:00');
62
        $this->assertNull($this->user->getDateOfBirth());
63
        $this->assertSame($this->user, $this->user->setDateOfBirth($expected));
64
        $this->assertSame($expected, $this->user->getDateOfBirth());
65
66
        $this->user->setDateOfBirth(['date' => '1990-05-08 00:00:00']);
67
        $this->assertInstanceOf('DateTime', $this->user->getDateOfBirth());
68
69
        $this->user->setDateOfBirth(['date' => '1990-05-08 00:00:00', 'timezone' => 'Europe/Berlin']);
70
        $this->assertInstanceOf('DateTime', $this->user->getDateOfBirth());
71
72
        $this->user->setDateOfBirth('1990-05-08 00:00:00');
73
        $this->assertInstanceOf('DateTime', $this->user->getDateOfBirth());
74
    }
75
76
    public function testInvalidDateOfBirthSetsItToNull()
77
    {
78
        $this->user->setDateOfBirth(new \stdClass());
0 ignored issues
show
Documentation introduced by
new \stdClass() is of type object<stdClass>, but the function expects a object<DateTime>|array|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
79
        $this->assertNull($this->user->getDateOfBirth());
80
    }
81
82
    public function testEmail()
83
    {
84
        $expected = '[email protected]';
85
        $this->assertNull($this->user->getEmail());
86
        $this->assertSame($this->user, $this->user->setEmail($expected));
87
        $this->assertEquals($expected, $this->user->getEmail());
88
    }
89
90
    public function testAddress()
91
    {
92
        $expected = 'Fake address';
93
        $this->assertNull($this->user->getAddress());
94
        $this->assertSame($this->user, $this->user->setAddress($expected));
95
        $this->assertEquals($expected, $this->user->getAddress());
96
    }
97
98
    public function testCity()
99
    {
100
        $expected = 'New York';
101
        $this->assertNull($this->user->getCity());
102
        $this->assertSame($this->user, $this->user->setCity($expected));
103
        $this->assertEquals($expected, $this->user->getCity());
104
    }
105
106
    public function testCountry()
107
    {
108
        $expected = 'Italy';
109
        $this->assertNull($this->user->getCountry());
110
        $this->assertSame($this->user, $this->user->setCountry($expected));
111
        $this->assertEquals($expected, $this->user->getCountry());
112
    }
113
114
    public function testPostalCode()
115
    {
116
        $expected = '12345';
117
        $this->assertNull($this->user->getPostalCode());
118
        $this->assertSame($this->user, $this->user->setPostalCode($expected));
119
        $this->assertEquals($expected, $this->user->getPostalCode());
120
    }
121
122
    public function testPhone()
123
    {
124
        $expected = '555-1234';
125
        $this->assertNull($this->user->getPhone());
126
        $this->assertSame($this->user, $this->user->setPhone($expected));
127
        $this->assertEquals($expected, $this->user->getPhone());
128
    }
129
130
    public function testGender()
131
    {
132
        $expected = 'male';
133
        $this->assertNull($this->user->getGender());
134
        $this->assertSame($this->user, $this->user->setGender($expected));
135
        $this->assertEquals($expected, $this->user->getGender());
136
    }
137
138
    public function testLocale()
139
    {
140
        $expected = 'en_US';
141
        $this->assertNull($this->user->getLocale());
142
        $this->assertSame($this->user, $this->user->setLocale($expected));
143
        $this->assertEquals($expected, $this->user->getLocale());
144
    }
145
146 View Code Duplication
    public function testTimezone()
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...
147
    {
148
        $expected = 'Europe/London';
149
        $this->assertNull($this->user->getTimezone());
150
        $this->assertSame($this->user, $this->user->setTimezone($expected));
151
        $this->assertEquals($expected, $this->user->getTimezone());
152
    }
153
}
154