TracksTest::testLoad()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 18
rs 9.4285
1
<?php
2
include '../vendor/autoload.php';
3
4
use Guzzle\Http;
5
6
class TracksTest extends PHPUnit_Framework_TestCase
7
{
8
    protected $bundle = null;
9
    protected $media  = 'http://media.clarify.io/audio/samples/harvard-sentences-1.wav';
10
11
    public function setUp()
12
    {
13
        global $apikey;
14
15
        $this->bundle = new \Clarify\Bundle($apikey);
16
17
        parent::setUp();
18
    }
19
20
    /**
21
     * @expectedException \Clarify\Exceptions\InvalidEnumTypeException
22
     */
23
    public function testCreateWithChannelException()
24
    {
25
        $params = array();
26
        $params['media_url'] = '';
27
        $params['label'] = '';
28
        $params['source'] = '';
29
        $params['audio_channel'] = 'neither channel';
30
        $this->bundle->tracks->create($params);
31
    }
32
33
    public function testCreate()
34
    {
35
        $name = 'name - testCreate' . rand(0, 500);
36
        $this->bundle->create($name, $this->media);
37
38
        $this->assertEquals(201, $this->bundle->getStatusCode());
39
        $location = $this->bundle->location;
40
41
        $params = array('media_url' => 'http://google.com', 'id' => $location);
42
        $this->bundle->tracks->create($params);
43
44
        $this->assertTrue($this->bundle->delete($location));
45
        $this->assertEquals(204, $this->bundle->getStatusCode());
46
    }
47
48
    public function testLoad()
49
    {
50
        $name = 'name - testCreate' . rand(0, 500);
51
        $this->bundle->create($name, $this->media);
52
53
        $this->assertEquals(201, $this->bundle->getStatusCode());
54
        $location = $this->bundle->location;
55
56
        $params = array('media_url' => 'http://google.com', 'id' => $location);
57
        $this->bundle->tracks->create($params);
58
59
        $resource = $this->bundle->tracks->load($location);
60
        $this->assertEquals(2, count($resource['tracks']));
61
        $this->assertEquals('http://google.com', $resource['tracks'][1]['media_url']);
62
63
        $this->assertTrue($this->bundle->delete($location));
64
        $this->assertEquals(204, $this->bundle->getStatusCode());
65
    }
66
67
    public function testDelete()
68
    {
69
        $name = 'name - testCreate' . rand(0, 500);
70
        $this->bundle->create($name, $this->media);
71
72
        $this->assertEquals(201, $this->bundle->getStatusCode());
73
        $location = $this->bundle->location;
74
75
        $params = array('media_url' => 'http://google.com', 'id' => $location);
76
        $this->bundle->tracks->create($params);
77
78
        $resource = $this->bundle->tracks->load($location);
79
        $this->assertEquals(2, count($resource['tracks']));
80
        $this->bundle->tracks->delete($location);
81
82
        $resource = $this->bundle->tracks->load($location);
83
        $this->assertEquals(0, count($resource['tracks']));
84
85
        $this->assertTrue($this->bundle->delete($location));
86
        $this->assertEquals(204, $this->bundle->getStatusCode());
87
    }
88
}