Completed
Push — develop ( b68cde...86f0dd )
by Adam
57s queued 52s
created

HelperTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 41
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testCamelCase() 0 5 1
A testCamelCaseIgnoresWhenAlreadyCorrect() 0 5 1
A testCamelCaseWithUppercaseValue() 0 5 1
A testInitializeIgnoresNullValues() 0 5 1
A testInitializeIgnoresString() 0 5 1
A testInitializeCallsSetters() 0 8 1
1
<?php
2
3
namespace IBM\Watson\Common\Tests;
4
5
use Mockery as m;
6
use IBM\Watson\Common\Helper;
7
8
class HelperTest extends \PHPUnit_Framework_TestCase
9
{
10
    public function testCamelCase()
11
    {
12
        $result = Helper::camelCase('test_case');
13
        $this->assertEquals('testCase', $result);
14
    }
15
16
    public function testCamelCaseIgnoresWhenAlreadyCorrect()
17
    {
18
        $result = Helper::camelCase('testCase');
19
        $this->assertEquals('testCase', $result);
20
    }
21
22
    public function testCamelCaseWithUppercaseValue()
23
    {
24
        $result = Helper::camelCase('TEST_CASE');
25
        $this->assertEquals('testCase', $result);
26
    }
27
28
    public function testInitializeIgnoresNullValues()
29
    {
30
        $target = m::mock();
31
        Helper::initialize($target, null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a array.

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...
32
    }
33
34
    public function testInitializeIgnoresString()
35
    {
36
        $target = m::mock();
37
        Helper::initialize($target, 'invalid');
0 ignored issues
show
Documentation introduced by
'invalid' is of type string, but the function expects a array.

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...
38
    }
39
40
    public function testInitializeCallsSetters()
41
    {
42
        $target = m::mock('\IBM\Watson\Common\AbstractService');
43
        $target->shouldReceive('setUsername')->once()->with('adam');
44
        $target->shouldReceive('setPassword')->once()->with('01234');
45
46
        Helper::initialize($target, ['username' => 'adam', 'password' => '01234']);
47
    }
48
}
49