Completed
Pull Request — master (#12)
by Maxime
02:44 queued 01:41
created

VideosTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 79
rs 10
wmc 3
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldThrowExceptionIfNoItemFound() 0 18 1
B getYoutubeList() 0 42 1
A shouldReturnYoutubeArrayAsJson() 0 10 1
1
<?php
2
3
/**
4
 * This file is a part of nekland youtube api package
5
 *
6
 * (c) Nekland <[email protected]>
7
 *
8
 * For the full license, take a look to the LICENSE file
9
 * on the root directory of this project
10
 */
11
12
namespace Nekland\Tests\Api;
13
14
15
16
use Nekland\YoutubeApi\Exception\NotFoundItemException;
17
18
class VideosTest extends TestCase
19
{
20
    /**
21
     * @test
22
     */
23
    public function shouldReturnYoutubeArrayAsJson()
24
    {
25
        $youtube = $this->getYoutubeMock(['get' => $this->getYoutubeList()]);
26
        /** @var \Nekland\YoutubeApi\Api\Videos $videos */
27
        $videos  = $youtube->api('videos');
28
29
        $this->assertEquals($videos->listById('PLXONb89nemXsCa5-v7kO8qbLnCjG9O80f')['etag'], '"X98aQHqGvPBJLZLOiSGUHCM9jnE/DqrNg5r4X93fnTIO0si3XjQXUwY"');
30
        $this->assertEquals($videos->getById('PLXONb89nemXsCa5-v7kO8qbLnCjG9O80f')['id'], 'DR7e0DoHZ2Y');
31
        $this->assertEquals($videos->listBy(['id' => 'PLXONb89nemXsCa5-v7kO8qbLnCjG9O80f'])['etag'], '"X98aQHqGvPBJLZLOiSGUHCM9jnE/DqrNg5r4X93fnTIO0si3XjQXUwY"');
32
    }
33
34
35
    public function shouldThrowExceptionIfNoItemFound()
36
    {
37
        $youtube = $this->getYoutubeMock(['get' => '{
38
 "kind": "youtube#videoListResponse",
39
 "etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/q9wh51deRpP1b7X8Nc3D-bdBxqs\"",
40
 "pageInfo": {
41
  "totalResults": 0,
42
  "resultsPerPage": 0
43
 },
44
 "items": []
45
}
46
'
47
        ]);
48
49
        $this->expectException(NotFoundItemException::class);
50
51
        $youtube->api('videos')->listById('id_that_doesnt_exists');
52
    }
53
54
    private function getYoutubeList()
55
    {
56
        return '
57
{
58
 "kind": "youtube#videoListResponse",
59
 "etag": "\\"X98aQHqGvPBJLZLOiSGUHCM9jnE/DqrNg5r4X93fnTIO0si3XjQXUwY\\"",
60
 "pageInfo": {
61
  "totalResults": 1,
62
  "resultsPerPage": 1
63
 },
64
 "items": [
65
  {
66
   "kind": "youtube#video",
67
   "etag": "\\"X98aQHqGvPBJLZLOiSGUHCM9jnE/PYBJAtNy79ShJyHHToh-N89kDH4\\"",
68
   "id": "DR7e0DoHZ2Y",
69
   "snippet": {
70
    "publishedAt": "2014-02-19T18:00:04.000Z",
71
    "channelId": "UCvOGElQWhX8tyTxwzv1rKzg",
72
    "title": "Mystery Skulls - Ghost (Solidisco Remix)\u200f",
73
    "description": "ENM ● New Songs every Monday, Wednesday & Friday!\nDownload it from iTunes: http://bit.ly/1e5u2pM\n\nBecome a fan of Solidisco\nFB: https://facebook.com/solidisco\nSoundcloud: http://soundcloud.com/solidisco\n\nBecome a fan of Mystery Skulls\nFB: https://facebook.com/mysteryskulls\nSoundcloud: http://soundcloud.com/mysteryskulls\n\nFollow Warner bros. Records\nFB: http://facebook.com/WarnerBrosRecords\nYouTube: http://youtube.com/warnerbrosrecords\nhttp://warnerbrosrecords.com\n\nOriginal artwork: http://bit.ly/1bK1bge\n------------------------------------------------------------\nStay connected with us\nFB: http://on.fb.me/tWNN6B\n@epicnetwork\nGoogle+ http://google.com/+EpicNetworkMusic\nSoundcloud: http://snd.sc/1hQlDce\n------------------------------------------------------------\nTrack\'s title: Mystery Skulls - Ghost (Solidisco Remix)\u200f",
74
    "thumbnails": {
75
     "default": {
76
      "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/default.jpg"
77
     },
78
     "medium": {
79
      "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/mqdefault.jpg"
80
     },
81
     "high": {
82
      "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/hqdefault.jpg"
83
     },
84
     "standard": {
85
      "url": "https://i1.ytimg.com/vi/DR7e0DoHZ2Y/sddefault.jpg"
86
     }
87
    },
88
    "channelTitle": "ENM",
89
    "categoryId": "10",
90
    "liveBroadcastContent": "none"
91
   }
92
  }
93
 ]
94
}';
95
    }
96
}
97