1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Brownie\Util\StorageArray; |
4
|
|
|
|
5
|
|
|
class StorageArrayTest extends PHPUnit_Framework_TestCase |
|
|
|
|
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
protected function setUp() |
9
|
|
|
{ |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
protected function tearDown() |
13
|
|
|
{ |
14
|
|
|
} |
15
|
|
|
|
16
|
|
View Code Duplication |
public function testConstructorOk1() |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
$fields = array( |
19
|
|
|
'question1' => 'answer1', |
20
|
|
|
'question2' => 'answer2', |
21
|
|
|
); |
22
|
|
|
$arrayList = new StorageArray($fields, true); |
23
|
|
|
$this->assertEquals($fields, $arrayList->toArray()); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testConstructorOk2() |
27
|
|
|
{ |
28
|
|
|
$fields = array(); |
29
|
|
|
$arrayList = new StorageArray($fields, false); |
30
|
|
|
$this->assertEquals($fields, $arrayList->toArray()); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @expectedException \Brownie\Util\Exception\UndefinedMethodException |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
public function testConstructorError() |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
$fields = array( |
39
|
|
|
'question1' => 'answer1', |
40
|
|
|
'question2' => 'answer2', |
41
|
|
|
); |
42
|
|
|
$arrayList = new StorageArray($fields); |
43
|
|
|
$this->assertEquals($fields, $arrayList->toArray()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testSetGetOk() |
47
|
|
|
{ |
48
|
|
|
$fields = array( |
49
|
|
|
'question1' => 'answer1', |
50
|
|
|
'question2' => 'answer2', |
51
|
|
|
); |
52
|
|
|
$newvalue = 'answer3'; |
53
|
|
|
$arrayList = new StorageArray($fields, true); |
54
|
|
|
$arrayList->setQuestion2('answer3'); |
|
|
|
|
55
|
|
|
$fields['question2'] = $newvalue; |
56
|
|
|
$this->assertEquals($fields, $arrayList->toArray()); |
57
|
|
|
$this->assertEquals($newvalue, $arrayList->getQuestion2()); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @expectedException \Brownie\Util\Exception\UndefinedMethodException |
62
|
|
|
*/ |
63
|
|
View Code Duplication |
public function testSetError() |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$fields = array( |
66
|
|
|
'question1' => 'answer1', |
67
|
|
|
'question2' => 'answer2', |
68
|
|
|
); |
69
|
|
|
$arrayList = new StorageArray($fields, true); |
70
|
|
|
$arrayList->setQuestion3('answer3'); |
|
|
|
|
71
|
|
|
$this->assertEquals($fields, $arrayList->toArray()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @expectedException \Brownie\Util\Exception\UndefinedMethodException |
76
|
|
|
*/ |
77
|
|
View Code Duplication |
public function testGetError() |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
$fields = array( |
80
|
|
|
'question1' => 'answer1', |
81
|
|
|
'question2' => 'answer2', |
82
|
|
|
); |
83
|
|
|
$newvalue = 'answer3'; |
84
|
|
|
$arrayList = new StorageArray($fields, true); |
85
|
|
|
$this->assertEquals($newvalue, $arrayList->getQuestion3('answer3')); |
|
|
|
|
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.