GraphUserTest::testBirthdaysGetCastToBirthday()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 15
nc 1
nop 0
dl 0
loc 23
rs 9.0856
c 1
b 0
f 0
1
<?php
2
/**
3
 * Copyright 2016 Facebook, Inc.
4
 *
5
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
6
 * use, copy, modify, and distribute this software in source code or binary
7
 * form for use in connection with the web services and APIs provided by
8
 * Facebook.
9
 *
10
 * As with any software that integrates with the Facebook platform, your use
11
 * of this software is subject to the Facebook Developer Principles and
12
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
13
 * shall be included in all copies or substantial portions of the software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * DEALINGS IN THE SOFTWARE.
22
 *
23
 */
24
namespace Facebook\Tests\GraphNodes;
25
26
use Facebook\FacebookResponse;
27
use Mockery as m;
28
use Facebook\GraphNodes\GraphNodeFactory;
29
30
class GraphUserTest extends \PHPUnit_Framework_TestCase
31
{
32
    /**
33
     * @var FacebookResponse
34
     */
35
    protected $responseMock;
36
37
    protected function setUp()
38
    {
39
        $this->responseMock = m::mock('\\Facebook\\FacebookResponse');
40
    }
41
42 View Code Duplication
    public function testDatesGetCastToDateTime()
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...
43
    {
44
        $dataFromGraph = [
45
            'updated_time' => '2016-04-26 13:22:05',
46
        ];
47
48
        $this->responseMock
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Facebook\FacebookResponse>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
            ->shouldReceive('getDecodedBody')
50
            ->once()
51
            ->andReturn($dataFromGraph);
52
        $factory = new GraphNodeFactory($this->responseMock);
53
        $graphNode = $factory->makeGraphUser();
54
55
        $updatedTime = $graphNode->getField('updated_time');
56
57
        $this->assertInstanceOf('DateTime', $updatedTime);
58
    }
59
60
    public function testBirthdaysGetCastToBirthday()
61
    {
62
        $dataFromGraph = [
63
            'birthday' => '1984/01/01',
64
        ];
65
66
        $this->responseMock
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Facebook\FacebookResponse>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
67
            ->shouldReceive('getDecodedBody')
68
            ->once()
69
            ->andReturn($dataFromGraph);
70
        $factory = new GraphNodeFactory($this->responseMock);
71
        $graphNode = $factory->makeGraphUser();
72
73
        $birthday = $graphNode->getBirthday();
74
75
        // Test to ensure BC
76
        $this->assertInstanceOf('DateTime', $birthday);
77
78
        $this->assertInstanceOf('\\Facebook\\GraphNodes\\Birthday', $birthday);
79
        $this->assertTrue($birthday->hasDate());
80
        $this->assertTrue($birthday->hasYear());
81
        $this->assertEquals('1984/01/01', $birthday->format('Y/m/d'));
82
    }
83
84 View Code Duplication
    public function testBirthdayCastHandlesDateWithoutYear()
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...
85
    {
86
        $dataFromGraph = [
87
            'birthday' => '03/21',
88
        ];
89
90
        $this->responseMock
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Facebook\FacebookResponse>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
            ->shouldReceive('getDecodedBody')
92
            ->once()
93
            ->andReturn($dataFromGraph);
94
        $factory = new GraphNodeFactory($this->responseMock);
95
        $graphNode = $factory->makeGraphUser();
96
97
        $birthday = $graphNode->getBirthday();
98
99
        $this->assertTrue($birthday->hasDate());
100
        $this->assertFalse($birthday->hasYear());
101
        $this->assertEquals('03/21', $birthday->format('m/d'));
102
    }
103
104 View Code Duplication
    public function testBirthdayCastHandlesYearWithoutDate()
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...
105
    {
106
        $dataFromGraph = [
107
            'birthday' => '1984',
108
        ];
109
110
        $this->responseMock
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Facebook\FacebookResponse>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
111
            ->shouldReceive('getDecodedBody')
112
            ->once()
113
            ->andReturn($dataFromGraph);
114
        $factory = new GraphNodeFactory($this->responseMock);
115
        $graphNode = $factory->makeGraphUser();
116
117
        $birthday = $graphNode->getBirthday();
118
119
        $this->assertTrue($birthday->hasYear());
120
        $this->assertFalse($birthday->hasDate());
121
        $this->assertEquals('1984', $birthday->format('Y'));
122
    }
123
124 View Code Duplication
    public function testPagePropertiesWillGetCastAsGraphPageObjects()
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...
125
    {
126
        $dataFromGraph = [
127
            'id' => '123',
128
            'name' => 'Foo User',
129
            'hometown' => [
130
                'id' => '1',
131
                'name' => 'Foo Place',
132
            ],
133
            'location' => [
134
                'id' => '2',
135
                'name' => 'Bar Place',
136
            ],
137
        ];
138
139
        $this->responseMock
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Facebook\FacebookResponse>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
140
            ->shouldReceive('getDecodedBody')
141
            ->once()
142
            ->andReturn($dataFromGraph);
143
        $factory = new GraphNodeFactory($this->responseMock);
144
        $graphNode = $factory->makeGraphUser();
145
146
        $hometown = $graphNode->getHometown();
147
        $location = $graphNode->getLocation();
148
149
        $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphPage', $hometown);
150
        $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphPage', $location);
151
    }
152
153 View Code Duplication
    public function testUserPropertiesWillGetCastAsGraphUserObjects()
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...
154
    {
155
        $dataFromGraph = [
156
            'id' => '123',
157
            'name' => 'Foo User',
158
            'significant_other' => [
159
                'id' => '1337',
160
                'name' => 'Bar User',
161
            ],
162
        ];
163
164
        $this->responseMock
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Facebook\FacebookResponse>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
165
            ->shouldReceive('getDecodedBody')
166
            ->once()
167
            ->andReturn($dataFromGraph);
168
        $factory = new GraphNodeFactory($this->responseMock);
169
        $graphNode = $factory->makeGraphUser();
170
171
        $significantOther = $graphNode->getSignificantOther();
172
173
        $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphUser', $significantOther);
174
    }
175
176
    public function testPicturePropertiesWillGetCastAsGraphPictureObjects()
177
    {
178
        $dataFromGraph = [
179
            'id' => '123',
180
            'name' => 'Foo User',
181
            'picture' => [
182
                'is_silhouette' => true,
183
                'url' => 'http://foo.bar',
184
                'width' => 200,
185
                'height' => 200,
186
            ],
187
        ];
188
189
        $this->responseMock
0 ignored issues
show
Bug introduced by
The method shouldReceive() does not seem to exist on object<Facebook\FacebookResponse>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
190
            ->shouldReceive('getDecodedBody')
191
            ->once()
192
            ->andReturn($dataFromGraph);
193
        $factory = new GraphNodeFactory($this->responseMock);
194
        $graphNode = $factory->makeGraphUser();
195
196
        $Picture = $graphNode->getPicture();
197
198
        $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphPicture', $Picture);
199
        $this->assertTrue($Picture->isSilhouette());
200
        $this->assertEquals(200, $Picture->getWidth());
201
        $this->assertEquals(200, $Picture->getHeight());
202
        $this->assertEquals('http://foo.bar', $Picture->getUrl());
203
    }
204
}
205