HelperTest   A
last analyzed

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 testCamelCaseAlreadyCorrect() 0 5 1
A testCamelCaseWithUppercaseValue() 0 5 1
A testInitializeIgnoresNull() 0 5 1
A testInitializeIgnoresString() 0 5 1
A testInitializeCallsSetters() 0 8 1
1
<?php
2
3
4
namespace IBM\Watson\Common;
5
6
use IBM\Watson\Tests\TestCase;
7
use Mockery as m;
8
use IBM\Watson\Common\Helper;
9
10
class HelperTest extends TestCase
11
{
12
    public function testCamelCase()
13
    {
14
        $result = Helper::camelCase('test_case');
15
        $this->assertEquals('testCase', $result);
16
    }
17
18
    public function testCamelCaseAlreadyCorrect()
19
    {
20
        $result = Helper::camelCase('testCase');
21
        $this->assertEquals('testCase', $result);
22
    }
23
24
    public function testCamelCaseWithUppercaseValue()
25
    {
26
        $result = Helper::camelCase('TEST_CASE');
27
        $this->assertEquals('testCase', $result);
28
    }
29
30
    public function testInitializeIgnoresNull()
31
    {
32
        $target = m::mock();
33
        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...
34
    }
35
36
    public function testInitializeIgnoresString()
37
    {
38
        $target = m::mock();
39
        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...
40
    }
41
42
    public function testInitializeCallsSetters()
43
    {
44
        $target = m::mock('\IBM\Watson\Common\AbstractService');
45
        $target->shouldReceive('setUsername')->once()->with('adam');
46
        $target->shouldReceive('setPassword')->once()->with('01234');
47
48
        Helper::initialize($target, ['username' => 'adam', 'password' => '01234']);
49
    }
50
}
51