GraphAlbumTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 70
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testFromGetsCastAsGraphUser() 0 17 1
A testPlacePropertyWillGetCastAsGraphPageObject() 0 18 1
A testDatesGetCastToDateTime() 0 18 1
A setUp() 0 3 1
1
<?php
2
/**
3
 * Copyright 2017 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
namespace Facebook\Tests\GraphNode;
24
25
use Facebook\GraphNode\GraphNodeFactory;
26
use Facebook\GraphNode\GraphPage;
27
use Facebook\GraphNode\GraphUser;
28
use Facebook\Response;
29
use PHPUnit\Framework\TestCase;
30
use Prophecy\Prophecy\ObjectProphecy;
31
32
class GraphAlbumTest extends TestCase
33
{
34
35
    /**
36
     * @var ObjectProphecy|Response
37
     */
38
    protected $responseMock;
39
40
    protected function setUp()
41
    {
42
        $this->responseMock = $this->prophesize(Response::class);
43
    }
44
45
    public function testDatesGetCastToDateTime()
46
    {
47
        $dataFromGraph = [
48
            'created_time' => '2014-07-15T03:54:34+0000',
49
            'updated_time' => '2014-07-12T01:24:09+0000',
50
            'id' => '123',
51
            'name' => 'Bar',
52
        ];
53
54
        $this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
55
        $factory = new GraphNodeFactory($this->responseMock->reveal());
56
        $graphNode = $factory->makeGraphAlbum();
57
58
        $createdTime = $graphNode->getCreatedTime();
59
        $updatedTime = $graphNode->getUpdatedTime();
60
61
        $this->assertInstanceOf(\DateTime::class, $createdTime);
62
        $this->assertInstanceOf(\DateTime::class, $updatedTime);
63
    }
64
65
    public function testFromGetsCastAsGraphUser()
66
    {
67
        $dataFromGraph = [
68
            'id' => '123',
69
            'from' => [
70
                'id' => '1337',
71
                'name' => 'Foo McBar',
72
            ],
73
        ];
74
75
        $this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
76
        $factory = new GraphNodeFactory($this->responseMock->reveal());
77
        $graphNode = $factory->makeGraphAlbum();
78
79
        $from = $graphNode->getFrom();
80
81
        $this->assertInstanceOf(GraphUser::class, $from);
82
    }
83
84
    public function testPlacePropertyWillGetCastAsGraphPageObject()
85
    {
86
        $dataFromGraph = [
87
            'id' => '123',
88
            'name' => 'Foo Album',
89
            'place' => [
90
                'id' => '1',
91
                'name' => 'For Bar Place',
92
            ]
93
        ];
94
95
        $this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
96
        $factory = new GraphNodeFactory($this->responseMock->reveal());
97
        $graphNode = $factory->makeGraphAlbum();
98
99
        $place = $graphNode->getPlace();
100
101
        $this->assertInstanceOf(GraphPage::class, $place);
102
    }
103
}
104