Completed
Push — develop ( 86f0dd...f71342 )
by Adam
12s
created

ServiceTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 27
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testConstruct() 0 5 1
A testVersion() 0 5 1
A testName() 0 4 1
1
<?php
2
3
namespace IBM\Watson\ToneAnalyzer\Tests;
4
5
use GuzzleHttp\Client;
6
use IBM\Watson\ToneAnalyzer\Message\ToneRequest;
7
use IBM\Watson\ToneAnalyzer\Service;
8
use Mockery as m;
9
use Symfony\Component\HttpFoundation\Request;
10
11
class ServiceTest extends \PHPUnit_Framework_TestCase
12
{
13
    protected $service;
14
15
    public function setUp()
16
    {
17
        $this->service = m::mock('\IBM\Watson\ToneAnalyzer\Service')->makePartial();
18
        $this->service->initialize();
19
    }
20
21
    public function testConstruct()
22
    {
23
        $this->service = new ToneAnalyzerServiceTest_MockService;
24
        $this->assertInstanceOf('\IBM\Watson\Common\AbstractService', $this->service);
25
    }
26
27
    public function testVersion()
28
    {
29
        $this->assertSame($this->service, $this->service->setVersion('2016-03-02'));
0 ignored issues
show
Bug introduced by
The method setVersion does only exist in IBM\Watson\ToneAnalyzer\...ServiceTest_MockService, but not in Mockery\Mock.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
30
        $this->assertSame('2016-03-02', $this->service->getVersion());
0 ignored issues
show
Bug introduced by
The method getVersion does only exist in IBM\Watson\ToneAnalyzer\...ServiceTest_MockService, but not in Mockery\Mock.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
31
    }
32
33
    public function testName()
34
    {
35
        $this->assertSame('Tone Analyzer', $this->service->getName());
0 ignored issues
show
Bug introduced by
The method getName does only exist in IBM\Watson\ToneAnalyzer\...ServiceTest_MockService, but not in Mockery\Mock.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
36
    }
37
}
38
39
class ToneAnalyzerServiceTest_MockService extends Service
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
40
{
41
}
42