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() |
|
|
|
|
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() |
|
|
|
|
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'); |
|
|
|
|
57
|
|
|
$fields['question2'] = $newvalue; |
58
|
|
|
$this->assertEquals($fields, $arrayList->toArray()); |
59
|
|
|
$this->assertEquals($newvalue, $arrayList->getQuestion2()); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @expectedException \Brownie\Util\Exception\UndefinedMethodException |
64
|
|
|
*/ |
65
|
|
View Code Duplication |
public function testSetError() |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$fields = array( |
68
|
|
|
'question1' => 'answer1', |
69
|
|
|
'question2' => 'answer2', |
70
|
|
|
); |
71
|
|
|
$arrayList = new StorageArray($fields, true); |
72
|
|
|
$arrayList->setQuestion3('answer3'); |
|
|
|
|
73
|
|
|
$this->assertEquals($fields, $arrayList->toArray()); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @expectedException \Brownie\Util\Exception\UndefinedMethodException |
78
|
|
|
*/ |
79
|
|
View Code Duplication |
public function testGetError() |
|
|
|
|
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')); |
|
|
|
|
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
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.