BundleTest::testUpdate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
rs 9.4285
1
<?php
2
include '../vendor/autoload.php';
3
4
use Guzzle\Http;
5
6
class BundleTest extends PHPUnit_Framework_TestCase
7
{
8
    protected $bundle = null;
9
    protected $client = null;
10
    protected $media  = 'http://media.clarify.io/audio/samples/harvard-sentences-1.wav';
11
12
    public function setUp()
13
    {
14
        global $apikey;
15
16
        $this->client = new \Clarify\Client($apikey);
17
        $this->bundle = new \Clarify\Bundle($apikey, $this->client);
18
19
        parent::setUp();
20
    }
21
22
    public function testCreate()
23
    {
24
        $name = 'name - testCreate' . rand(0, 500);
25
        $this->bundle->create($name, $this->media);
26
27
        $this->assertEquals(201, $this->bundle->getStatusCode());
28
        $location = $this->bundle->location;
29
        $this->assertEquals(44, strlen($location));
30
31
        $this->assertTrue($this->bundle->delete($location));
32
        $this->assertEquals(204, $this->bundle->getStatusCode());
33
    }
34
35
    /**
36
     * @expectedException \Clarify\Exceptions\InvalidJSONException
37
     */
38
    public function testCreateWithJSONException()
39
    {
40
        $name = 'name - testCreate';
41
        $this->bundle->create($name, $this->media, 'not a json string');
42
    }
43
44
    /**
45
     * @expectedException \Clarify\Exceptions\InvalidEnumTypeException
46
     */
47
    public function testCreateWithChannelException()
48
    {
49
        $name = 'name - testCreate';
50
        $this->bundle->create($name, $this->media, '', '', 'neither channel!');
51
    }
52
53
    public function testUpdate()
54
    {
55
        $name = 'name - testUpdate';
56
        $this->bundle->create($name, $this->media);
57
58
        $this->assertEquals(201, $this->bundle->getStatusCode());
59
        $location = $this->bundle->location;
60
61
        $this->assertTrue($this->bundle->update($location, array()));
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
62
        $this->assertEquals(202, $this->bundle->getStatusCode());
63
    }
64
65
    /**
66
     * @expectedException \Clarify\Exceptions\InvalidIntegerArgumentException
67
     */
68
    public function testUpdateWithException()
69
    {
70
        $this->bundle->update('id', 'name', 'http://google.com', 'not a version string');
71
    }
72
73
    public function testDelete()
74
    {
75
        $name = 'name - testUpdate';
76
        $this->bundle->create($name, $this->media);
77
78
        $this->assertEquals(201, $this->bundle->getStatusCode());
79
        $location = $this->bundle->location;
80
81
        $this->assertTrue($this->bundle->delete($location));
82
        $this->assertEquals(204, $this->bundle->getStatusCode());
83
84
        $this->bundle->load($location);
85
        $this->assertEquals(404, $this->bundle->getStatusCode());
86
    }
87
88
    public function testIndex()
89
    {
90
        $data = $this->bundle->index();
91
        $items = $data['_links']['items'];
92
        $this->assertEquals(10, $data['limit']);
93
        $this->assertLessThanOrEqual(10, count($items));
94
95
        $data = $this->bundle->index(2);
96
        $items = $data['_links']['items'];
97
        $this->assertEquals(2, $data['limit']);
98
        $this->assertLessThanOrEqual(2, count($items));
99
    }
100
101
    public function test__get()
102
    {
103
        $object = $this->bundle->tracks;
104
        $this->assertInstanceOf('\Clarify\Tracks', $object);
105
106
        $object = $this->bundle->metadata;
107
        $this->assertInstanceOf('\Clarify\Metadata', $object);
108
    }
109
110
    /**
111
     * @expectedException \Clarify\Exceptions\InvalidResourceException
112
     */
113
    public function test__getWithException()
114
    {
115
        $object = $this->bundle->monkey;
0 ignored issues
show
Bug introduced by
The property monkey does not seem to exist in Clarify\Bundle.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Unused Code introduced by
$object is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
116
    }
117
}