Passed
Push — master ( d277d1...50d4cf )
by Oss
05:45
created

StorageArrayTest::testConstructorError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
c 0
b 0
f 0
rs 9.6666
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Test\Brownie\Util;
4
5
use Brownie\Util\StorageArray;
6
7
class StorageArrayTest extends \PHPUnit_Framework_TestCase
8
{
9
10
    protected function setUp()
11
    {
12
    }
13
14
    protected function tearDown()
15
    {
16
    }
17
18 View Code Duplication
    public function testConstructorOk1()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
19
    {
20
        $fields = array(
21
            'question1' => 'answer1',
22
            'question2' => 'answer2',
23
        );
24
        $arrayList = new StorageArray($fields, true);
25
        $this->assertEquals($fields, $arrayList->toArray());
26
    }
27
28
    public function testConstructorOk2()
29
    {
30
        $fields = array();
31
        $arrayList = new StorageArray($fields, false);
32
        $this->assertEquals($fields, $arrayList->toArray());
33
    }
34
35
    /**
36
     * @expectedException \Brownie\Util\Exception\UndefinedMethodException
37
     */
38 View Code Duplication
    public function testConstructorError()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
    {
40
        $fields = array(
41
            'question1' => 'answer1',
42
            'question2' => 'answer2',
43
        );
44
        $arrayList = new StorageArray($fields);
45
        $this->assertEquals($fields, $arrayList->toArray());
46
    }
47
48
    public function testSetGetOk()
49
    {
50
        $fields = array(
51
            'question1' => 'answer1',
52
            'question2' => 'answer2',
53
        );
54
        $newvalue = 'answer3';
55
        $arrayList = new StorageArray($fields, true);
56
        $arrayList->setQuestion2('answer3');
0 ignored issues
show
Documentation Bug introduced by
The method setQuestion2 does not exist on object<Brownie\Util\StorageArray>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
57
        $fields['question2'] = $newvalue;
58
        $this->assertEquals($fields, $arrayList->toArray());
59
        $this->assertEquals($newvalue, $arrayList->getQuestion2());
0 ignored issues
show
Documentation Bug introduced by
The method getQuestion2 does not exist on object<Brownie\Util\StorageArray>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
60
    }
61
62
    /**
63
     * @expectedException \Brownie\Util\Exception\UndefinedMethodException
64
     */
65 View Code Duplication
    public function testSetError()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        $fields = array(
68
            'question1' => 'answer1',
69
            'question2' => 'answer2',
70
        );
71
        $arrayList = new StorageArray($fields, true);
72
        $arrayList->setQuestion3('answer3');
0 ignored issues
show
Documentation Bug introduced by
The method setQuestion3 does not exist on object<Brownie\Util\StorageArray>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
73
        $this->assertEquals($fields, $arrayList->toArray());
74
    }
75
76
    /**
77
     * @expectedException \Brownie\Util\Exception\UndefinedMethodException
78
     */
79 View Code Duplication
    public function testGetError()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
    {
81
        $fields = array(
82
            'question1' => 'answer1',
83
            'question2' => 'answer2',
84
        );
85
        $newvalue = 'answer3';
86
        $arrayList = new StorageArray($fields, true);
87
        $this->assertEquals($newvalue, $arrayList->getQuestion3('answer3'));
0 ignored issues
show
Documentation Bug introduced by
The method getQuestion3 does not exist on object<Brownie\Util\StorageArray>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
88
    }
89
}
90