testOtherSeparatorAndKvSplitter()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
1
<?php
2
namespace FwlibTest\Config;
3
4
use Fwlib\Config\StringOptions;
5
use Fwolf\Wrapper\PHPUnit\PHPUnitTestCase;
6
use PHPUnit_Framework_MockObject_MockObject as MockObject;
7
8
/**
9
 * @copyright   Copyright 2015 Fwolf
10
 * @license     http://www.gnu.org/licenses/lgpl.html LGPL-3.0+
11
 */
12
class StringOptionsTest extends PHPUnitTestCase
13
{
14
    /**
15
     * @param   string[]    $methods
16
     * @return  MockObject|StringOptions
17
     */
18
    protected function buildMock(array $methods = null)
19
    {
20
        $mock = $this->getMock(
21
            StringOptions::class,
22
            $methods
23
        );
24
25
        return $mock;
26
    }
27
28
29
    public function testExport()
30
    {
31
        $options = $this->buildMock();
32
33
        $options->set('foo1', 42)
0 ignored issues
show
Bug introduced by
The method set does only exist in Fwlib\Config\StringOptions, but not in PHPUnit_Framework_MockObject_MockObject.

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...
34
            ->set('foo2', true)
35
            ->set('foo3', false);
36
        $this->assertEquals(
37
            'foo1: 42, foo2: true, foo3: false',
38
            $options->export(', ', ': ')
0 ignored issues
show
Bug introduced by
The method export does only exist in Fwlib\Config\StringOptions, but not in PHPUnit_Framework_MockObject_MockObject.

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...
39
        );
40
    }
41
42
43
    public function testGet()
44
    {
45
        $options = $this->buildMock();
46
47
        $this->assertNotNull($options->get('notExist'));
0 ignored issues
show
Bug introduced by
The method get does only exist in Fwlib\Config\StringOptions, but not in PHPUnit_Framework_MockObject_MockObject.

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...
48
        $this->assertTrue(false === $options->get('notExist'));
49
    }
50
51
52
    public function testImport()
53
    {
54
        $options = $this->buildMock();
55
56
        $options->import(',,foo1 = 4 2 , foo2=true  , foo3 = false', ',', '=');
0 ignored issues
show
Bug introduced by
The method import does only exist in Fwlib\Config\StringOptions, but not in PHPUnit_Framework_MockObject_MockObject.

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...
57
58
        $this->assertEquals('4 2', $options->get('foo1'));
0 ignored issues
show
Bug introduced by
The method get does only exist in Fwlib\Config\StringOptions, but not in PHPUnit_Framework_MockObject_MockObject.

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...
59
        $this->assertTrue($options->get('foo2'));
60
        $this->assertFalse($options->get('foo3'));
61
    }
62
63
64
    /**
65
     * @expectedException   \Fwlib\Base\Exception\InvalidFormatException
66
     */
67
    public function testImportError()
68
    {
69
        $options = $this->buildMock();
70
71
        $options->import('foo == 42', ',', '=');
0 ignored issues
show
Bug introduced by
The method import does only exist in Fwlib\Config\StringOptions, but not in PHPUnit_Framework_MockObject_MockObject.

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...
72
    }
73
74
75
    public function testOtherSeparatorAndKvSplitter()
76
    {
77
        /** @var MockObject|StringOptions $options */
78
        $options = $this->getMock(
79
            StringOptions::class,
80
            null,
81
            ['foo:: 42; bar', ';', '::']
82
        );
83
84
        $this->assertEquals(42, $options->get('foo'));
0 ignored issues
show
Bug introduced by
The method get does only exist in Fwlib\Config\StringOptions, but not in PHPUnit_Framework_MockObject_MockObject.

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...
85
        $this->assertTrue($options->get('bar'));
86
    }
87
}
88