GraphEventTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 3 1
A testPlaceGetsCastAsGraphPage() 0 12 1
A testPictureGetsCastAsGraphPicture() 0 12 1
A testParentGroupGetsCastAsGraphGroup() 0 12 1
A testCoverGetsCastAsGraphCoverPhoto() 0 12 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\Response;
26
use Facebook\GraphNode\GraphNodeFactory;
27
use Facebook\GraphNode\GraphGroup;
28
use Facebook\GraphNode\GraphPicture;
29
use Facebook\GraphNode\GraphPage;
30
use Facebook\GraphNode\GraphCoverPhoto;
31
use PHPUnit\Framework\TestCase;
32
use Prophecy\Prophecy\ObjectProphecy;
33
34
class GraphEventTest extends TestCase
35
{
36
    /**
37
     * @var ObjectProphecy|Response
38
     */
39
    protected $responseMock;
40
41
    protected function setUp()
42
    {
43
        $this->responseMock = $this->prophesize(Response::class);
44
    }
45
46
    public function testCoverGetsCastAsGraphCoverPhoto()
47
    {
48
        $dataFromGraph = [
49
            'cover' => ['id' => '1337']
50
        ];
51
52
        $this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
53
        $factory = new GraphNodeFactory($this->responseMock->reveal());
54
        $graphNode = $factory->makeGraphEvent();
55
56
        $cover = $graphNode->getCover();
57
        $this->assertInstanceOf(GraphCoverPhoto::class, $cover);
58
    }
59
60
    public function testPlaceGetsCastAsGraphPage()
61
    {
62
        $dataFromGraph = [
63
            'place' => ['id' => '1337']
64
        ];
65
66
        $this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
67
        $factory = new GraphNodeFactory($this->responseMock->reveal());
68
        $graphNode = $factory->makeGraphEvent();
69
70
        $place = $graphNode->getPlace();
71
        $this->assertInstanceOf(GraphPage::class, $place);
72
    }
73
74
    public function testPictureGetsCastAsGraphPicture()
75
    {
76
        $dataFromGraph = [
77
            'picture' => ['id' => '1337']
78
        ];
79
80
        $this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
81
        $factory = new GraphNodeFactory($this->responseMock->reveal());
82
        $graphNode = $factory->makeGraphEvent();
83
84
        $picture = $graphNode->getPicture();
85
        $this->assertInstanceOf(GraphPicture::class, $picture);
86
    }
87
88
    public function testParentGroupGetsCastAsGraphGroup()
89
    {
90
        $dataFromGraph = [
91
            'parent_group' => ['id' => '1337']
92
        ];
93
94
        $this->responseMock->getDecodedBody()->willReturn($dataFromGraph);
95
        $factory = new GraphNodeFactory($this->responseMock->reveal());
96
        $graphNode = $factory->makeGraphEvent();
97
98
        $parentGroup = $graphNode->getParentGroup();
99
        $this->assertInstanceOf(GraphGroup::class, $parentGroup);
100
    }
101
}
102