ActivityTest::__construct()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 3
1
<?php
2
namespace FlexyProject\GitHub\Tests\Receiver;
3
4
use FlexyProject\GitHub\Client;
5
use FlexyProject\GitHub\Receiver\Activity;
6
use FlexyProject\GitHub\Tests\AbstractClientTest;
7
8
/**
9
 * Class ActivityTest
10
 *
11
 * @package FlexyProject\GitHub\Tests\Receiver
12
 */
13
class ActivityTest extends AbstractClientTest
14
{
15
    /** @var Activity\Events */
16
    protected $events;
17
18
    /** @var Activity\Feeds */
19
    protected $feeds;
20
21
    /** @var Activity\Notifications */
22
    protected $notifications;
23
24
    /** @var Activity\Starring */
25
    protected $starring;
26
27
    /** @var Activity\Watching */
28
    protected $watching;
29
30
    /**
31
     * ActivityTest constructor.
32
     *
33
     * @param null   $name
34
     * @param array  $data
35
     * @param string $dataName
36
     */
37
    public function __construct($name = null, array $data = [], $dataName = '')
38
    {
39
        parent::__construct($name, $data, $dataName);
40
41
        // Activity
42
        $activity = $this->client->getReceiver(Client::ACTIVITY);
43
        $activity->setRepo('GitHubAPI');
44
        $activity->setOwner('FlexyProject');
45
46
        // Events
47
        $this->events = $activity->getReceiver(Activity::EVENTS);
48
49
        // Feeds
50
        $this->feeds = $activity->getReceiver(Activity::FEEDS);
51
52
        // Notifications
53
        $this->notifications = $activity->getReceiver(Activity::NOTIFICATIONS);
54
55
        // Starring
56
        $this->starring = $activity->getReceiver(Activity::STARRING);
57
58
        // Watching
59
        $this->watching = $activity->getReceiver(Activity::WATCHING);
60
    }
61
62
    /**
63
     * Test instance of Events's class
64
     */
65
    public function testEvents()
66
    {
67
        $this->assertInstanceOf(Activity\Events::class, $this->events);
68
    }
69
70
    /**
71
     * Test instance of Feeds's class
72
     */
73
    public function testFeeds()
74
    {
75
        $this->assertInstanceOf(Activity\Feeds::class, $this->feeds);
76
    }
77
78
    /**
79
     * Test instance of Notifications's class
80
     */
81
    public function testNotifications()
82
    {
83
        $this->assertInstanceOf(Activity\Notifications::class, $this->notifications);
84
    }
85
86
    /**
87
     * Test instance of Starring's class
88
     */
89
    public function testStarring()
90
    {
91
        $this->assertInstanceOf(Activity\Starring::class, $this->starring);
92
    }
93
94
    /**
95
     * Test instance of Watching's class
96
     */
97
    public function testWatching()
98
    {
99
        $this->assertInstanceOf(Activity\Watching::class, $this->watching);
100
    }
101
102
    /**
103
     * Test listing public events
104
     */
105
    public function testListPublicEvents()
106
    {
107
        $events = $this->events->listPublicEvents();
108
        if (!empty($events)) {
109
            $event = array_pop($events);
110
111
            $this->assertArrayHasKey('id', $event);
112
            $this->assertArrayHasKey('type', $event);
113
            $this->assertArrayHasKey('actor', $event);
114
            $this->assertArrayHasKey('repo', $event);
115
            $this->assertArrayHasKey('payload', $event);
116
            $this->assertArrayHasKey('public', $event);
117
            $this->assertArrayHasKey('created_at', $event);
118
        }
119
    }
120
121
    /**
122
     * Test listing repository events
123
     */
124 View Code Duplication
    public function testListRepositoryEvents()
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
        $events = $this->events->listRepositoryEvents();
127
        if (!empty($events)) {
128
            $event = array_pop($events);
129
130
            $this->assertArrayHasKey('id', $event);
131
            $this->assertArrayHasKey('type', $event);
132
            $this->assertArrayHasKey('actor', $event);
133
            $this->assertArrayHasKey('repo', $event);
134
            $this->assertArrayHasKey('payload', $event);
135
            $this->assertArrayHasKey('public', $event);
136
            $this->assertArrayHasKey('created_at', $event);
137
            $this->assertArrayHasKey('org', $event);
138
        }
139
    }
140
141
    /**
142
     * Test listing issues events
143
     */
144
    public function testListIssueEvents()
145
    {
146
        $events = $this->events->listIssueEvents();
147
        if (!empty($events)) {
148
            $event = array_pop($events);
149
150
            $this->assertArrayHasKey('id', $event);
151
            $this->assertArrayHasKey('url', $event);
152
            $this->assertArrayHasKey('actor', $event);
153
            $this->assertArrayHasKey('event', $event);
154
            $this->assertArrayHasKey('issue', $event);
155
            $this->assertArrayHasKey('created_at', $event);
156
        }
157
    }
158
159
    /**
160
     * Test listing public network events
161
     */
162 View Code Duplication
    public function testListPublicNetworkEvents()
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...
163
    {
164
        $events = $this->events->listPublicNetworkEvents();
165
        if (!empty($events)) {
166
            $event = array_pop($events);
167
168
            $this->assertArrayHasKey('id', $event);
169
            $this->assertArrayHasKey('type', $event);
170
            $this->assertArrayHasKey('actor', $event);
171
            $this->assertArrayHasKey('repo', $event);
172
            $this->assertArrayHasKey('payload', $event);
173
            $this->assertArrayHasKey('public', $event);
174
            $this->assertArrayHasKey('created_at', $event);
175
            $this->assertArrayHasKey('org', $event);
176
        }
177
    }
178
179
    /**
180
     * Test listing public organization events
181
     */
182
    public function testListPublicOrganizationEvents()
0 ignored issues
show
Coding Style introduced by
testListPublicOrganizationEvents uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
183
    {
184
        $events = $this->events->listPublicOrganizationEvents($GLOBALS['ORGANIZATION']);
185
        if (!empty($events)) {
186
            $event = array_pop($events);
187
188
            $this->assertArrayHasKey('id', $event);
189
            $this->assertArrayHasKey('type', $event);
190
            $this->assertArrayHasKey('actor', $event);
191
            $this->assertArrayHasKey('repo', $event);
192
            $this->assertArrayHasKey('payload', $event);
193
            $this->assertArrayHasKey('public', $event);
194
            $this->assertArrayHasKey('created_at', $event);
195
            $this->assertArrayHasKey('org', $event);
196
        }
197
    }
198
199
    /**
200
     * Test listing user receive events
201
     */
202
    public function testListUserReceiveEvents()
0 ignored issues
show
Coding Style introduced by
testListUserReceiveEvents uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
203
    {
204
        $events = $this->events->listUserReceiveEvents($GLOBALS['USERNAME']);
205
        if (!empty($events)) {
206
            $event = array_pop($events);
207
208
            $this->assertArrayHasKey('id', $event);
209
            $this->assertArrayHasKey('type', $event);
210
            $this->assertArrayHasKey('actor', $event);
211
            $this->assertArrayHasKey('repo', $event);
212
            $this->assertArrayHasKey('payload', $event);
213
            $this->assertArrayHasKey('public', $event);
214
            $this->assertArrayHasKey('created_at', $event);
215
        }
216
    }
217
218
    /**
219
     * Test listing public user receive events
220
     */
221
    public function testListPublicUserReceiveEvents()
0 ignored issues
show
Coding Style introduced by
testListPublicUserReceiveEvents uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
222
    {
223
        $events = $this->events->listPublicUserReceiveEvents($GLOBALS['USERNAME']);
224
        if (!empty($events)) {
225
            $event = array_pop($events);
226
227
            $this->assertArrayHasKey('id', $event);
228
            $this->assertArrayHasKey('type', $event);
229
            $this->assertArrayHasKey('actor', $event);
230
            $this->assertArrayHasKey('repo', $event);
231
            $this->assertArrayHasKey('payload', $event);
232
            $this->assertArrayHasKey('public', $event);
233
            $this->assertArrayHasKey('created_at', $event);
234
        }
235
    }
236
237
    /**
238
     * Test listing user preformed events
239
     */
240
    public function testListUserPerformedEvents()
0 ignored issues
show
Coding Style introduced by
testListUserPerformedEvents uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
241
    {
242
        $events = $this->events->listUserPerformedEvents($GLOBALS['USERNAME']);
243
        if (!empty($events)) {
244
            $event = array_pop($events);
245
246
            $this->assertArrayHasKey('id', $event);
247
            $this->assertArrayHasKey('type', $event);
248
            $this->assertArrayHasKey('actor', $event);
249
            $this->assertArrayHasKey('repo', $event);
250
            $this->assertArrayHasKey('payload', $event);
251
            $this->assertArrayHasKey('public', $event);
252
            $this->assertArrayHasKey('created_at', $event);
253
            $this->assertArrayHasKey('org', $event);
254
        }
255
    }
256
257
    /**
258
     * Test listing public user performed events
259
     */
260
    public function testListPublicUserPerformedEvents()
0 ignored issues
show
Coding Style introduced by
testListPublicUserPerformedEvents uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
261
    {
262
        $events = $this->events->listPublicUserPerformedEvents($GLOBALS['USERNAME']);
263
        if (!empty($events)) {
264
            $event = array_pop($events);
265
266
            $this->assertArrayHasKey('id', $event);
267
            $this->assertArrayHasKey('type', $event);
268
            $this->assertArrayHasKey('actor', $event);
269
            $this->assertArrayHasKey('repo', $event);
270
            $this->assertArrayHasKey('payload', $event);
271
            $this->assertArrayHasKey('public', $event);
272
            $this->assertArrayHasKey('created_at', $event);
273
            $this->assertArrayHasKey('org', $event);
274
        }
275
    }
276
277
    /**
278
     * Test listing organization events
279
     */
280
    public function testListOrganizationEvents()
0 ignored issues
show
Coding Style introduced by
testListOrganizationEvents uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
281
    {
282
        $events = $this->events->listOrganizationEvents($GLOBALS['USERNAME'], $GLOBALS['ORGANIZATION']);
283
        if (!empty($events)) {
284
            $event = array_pop($events);
285
286
            $this->assertArrayHasKey('id', $event);
287
            $this->assertArrayHasKey('type', $event);
288
            $this->assertArrayHasKey('actor', $event);
289
            $this->assertArrayHasKey('repo', $event);
290
            $this->assertArrayHasKey('payload', $event);
291
            $this->assertArrayHasKey('public', $event);
292
            $this->assertArrayHasKey('created_at', $event);
293
            $this->assertArrayHasKey('org', $event);
294
        }
295
    }
296
297
    /**
298
     * Test listing feeds
299
     */
300
    public function testListFeeds()
301
    {
302
        $feeds = $this->feeds->listFeeds();
303
        $this->assertArrayHasKey('timeline_url', $feeds);
304
        $this->assertArrayHasKey('user_url', $feeds);
305
        $this->assertArrayHasKey('current_user_public_url', $feeds);
306
        $this->assertArrayHasKey('current_user_url', $feeds);
307
        $this->assertArrayHasKey('current_user_actor_url', $feeds);
308
        $this->assertArrayHasKey('current_user_organization_url', $feeds);
309
        $this->assertArrayHasKey('current_user_organization_urls', $feeds);
310
    }
311
312
    /**
313
     * Test listing notifications
314
     */
315 View Code Duplication
    public function testListNotifications()
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...
316
    {
317
        $notifications = $this->notifications->listNotifications(true, true, '2016-02-14');
318
        if (!empty($notifications)) {
319
            $notification = array_pop($notifications);
320
321
            $this->assertArrayHasKey('id', $notification);
322
            $this->assertArrayHasKey('repository', $notification);
323
            $this->assertArrayHasKey('subject', $notification);
324
            $this->assertArrayHasKey('reason', $notification);
325
            $this->assertArrayHasKey('unread', $notification);
326
            $this->assertArrayHasKey('updated_at', $notification);
327
            $this->assertArrayHasKey('last_read_at', $notification);
328
            $this->assertArrayHasKey('url', $notification);
329
        }
330
    }
331
}