Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit58e7c10

Browse files
committed
[Form] Improved test coverage of ChoiceList classes
1 parent9542d72 commit58e7c10

File tree

5 files changed

+486
-316
lines changed

5 files changed

+486
-316
lines changed
Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Component\Form\Tests\Extension\Core\ChoiceList;
13+
14+
/**
15+
* @author Bernhard Schussek <bschussek@gmail.com>
16+
*/
17+
abstractclass AbstractChoiceListTestextends \PHPUnit_Framework_TestCase
18+
{
19+
/**
20+
* @var \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
21+
*/
22+
protected$list;
23+
24+
/**
25+
* @var array
26+
*/
27+
protected$choices;
28+
29+
/**
30+
* @var array
31+
*/
32+
protected$values;
33+
34+
/**
35+
* @var array
36+
*/
37+
protected$indices;
38+
39+
/**
40+
* @var array
41+
*/
42+
protected$labels;
43+
44+
/**
45+
* @var mixed
46+
*/
47+
protected$choice1;
48+
49+
/**
50+
* @var mixed
51+
*/
52+
protected$choice2;
53+
54+
/**
55+
* @var mixed
56+
*/
57+
protected$choice3;
58+
59+
/**
60+
* @var mixed
61+
*/
62+
protected$choice4;
63+
64+
/**
65+
* @var string
66+
*/
67+
protected$value1;
68+
69+
/**
70+
* @var string
71+
*/
72+
protected$value2;
73+
74+
/**
75+
* @var string
76+
*/
77+
protected$value3;
78+
79+
/**
80+
* @var string
81+
*/
82+
protected$value4;
83+
84+
/**
85+
* @var int|string
86+
*/
87+
protected$index1;
88+
89+
/**
90+
* @var int|string
91+
*/
92+
protected$index2;
93+
94+
/**
95+
* @var int|string
96+
*/
97+
protected$index3;
98+
99+
/**
100+
* @var int|string
101+
*/
102+
protected$index4;
103+
104+
/**
105+
* @var string
106+
*/
107+
protected$label1;
108+
109+
/**
110+
* @var string
111+
*/
112+
protected$label2;
113+
114+
/**
115+
* @var string
116+
*/
117+
protected$label3;
118+
119+
/**
120+
* @var string
121+
*/
122+
protected$label4;
123+
124+
protectedfunctionsetUp()
125+
{
126+
parent::setUp();
127+
128+
$this->list =$this->createChoiceList();
129+
130+
$this->choices =$this->getChoices();
131+
$this->indices =$this->getIndices();
132+
$this->values =$this->getValues();
133+
$this->labels =$this->getLabels();
134+
135+
// allow access to the individual entries without relying on their indices
136+
reset($this->choices);
137+
reset($this->indices);
138+
reset($this->values);
139+
reset($this->labels);
140+
141+
for ($i =1;$i <=4; ++$i) {
142+
$this->{'choice'.$i} =current($this->choices);
143+
$this->{'index'.$i} =current($this->indices);
144+
$this->{'value'.$i} =current($this->values);
145+
$this->{'label'.$i} =current($this->labels);
146+
147+
next($this->choices);
148+
next($this->indices);
149+
next($this->values);
150+
next($this->labels);
151+
}
152+
}
153+
154+
publicfunctiontestGetChoices()
155+
{
156+
$this->assertSame($this->choices,$this->list->getChoices());
157+
}
158+
159+
publicfunctiontestGetValues()
160+
{
161+
$this->assertSame($this->values,$this->list->getValues());
162+
}
163+
164+
publicfunctiontestGetIndicesForChoices()
165+
{
166+
$choices =array($this->choice1,$this->choice2);
167+
$this->assertSame(array($this->index1,$this->index2),$this->list->getIndicesForChoices($choices));
168+
}
169+
170+
publicfunctiontestGetIndicesForChoicesPreservesKeys()
171+
{
172+
$choices =array(5 =>$this->choice1,8 =>$this->choice2);
173+
$this->assertSame(array(5 =>$this->index1,8 =>$this->index2),$this->list->getIndicesForChoices($choices));
174+
}
175+
176+
publicfunctiontestGetIndicesForChoicesPreservesOrder()
177+
{
178+
$choices =array($this->choice2,$this->choice1);
179+
$this->assertSame(array($this->index2,$this->index1),$this->list->getIndicesForChoices($choices));
180+
}
181+
182+
publicfunctiontestGetIndicesForChoicesIgnoresNonExistingChoices()
183+
{
184+
$choices =array($this->choice1,$this->choice2,'foobar');
185+
$this->assertSame(array($this->index1,$this->index2),$this->list->getIndicesForChoices($choices));
186+
}
187+
188+
publicfunctiontestGetIndicesForChoicesEmpty()
189+
{
190+
$this->assertSame(array(),$this->list->getIndicesForChoices(array()));
191+
}
192+
193+
publicfunctiontestGetIndicesForValues()
194+
{
195+
// values and indices are always the same
196+
$values =array($this->value1,$this->value2);
197+
$this->assertSame(array($this->index1,$this->index2),$this->list->getIndicesForValues($values));
198+
}
199+
200+
publicfunctiontestGetIndicesForValuesPreservesKeys()
201+
{
202+
// values and indices are always the same
203+
$values =array(5 =>$this->value1,8 =>$this->value2);
204+
$this->assertSame(array(5 =>$this->index1,8 =>$this->index2),$this->list->getIndicesForValues($values));
205+
}
206+
207+
publicfunctiontestGetIndicesForValuesPreservesOrder()
208+
{
209+
$values =array($this->value2,$this->value1);
210+
$this->assertSame(array($this->index2,$this->index1),$this->list->getIndicesForValues($values));
211+
}
212+
213+
publicfunctiontestGetIndicesForValuesIgnoresNonExistingValues()
214+
{
215+
$values =array($this->value1,$this->value2,'foobar');
216+
$this->assertSame(array($this->index1,$this->index2),$this->list->getIndicesForValues($values));
217+
}
218+
219+
publicfunctiontestGetIndicesForValuesEmpty()
220+
{
221+
$this->assertSame(array(),$this->list->getIndicesForValues(array()));
222+
}
223+
224+
publicfunctiontestGetChoicesForValues()
225+
{
226+
$values =array($this->value1,$this->value2);
227+
$this->assertSame(array($this->choice1,$this->choice2),$this->list->getChoicesForValues($values));
228+
}
229+
230+
publicfunctiontestGetChoicesForValuesPreservesKeys()
231+
{
232+
$values =array(5 =>$this->value1,8 =>$this->value2);
233+
$this->assertSame(array(5 =>$this->choice1,8 =>$this->choice2),$this->list->getChoicesForValues($values));
234+
}
235+
236+
publicfunctiontestGetChoicesForValuesPreservesOrder()
237+
{
238+
$values =array($this->value2,$this->value1);
239+
$this->assertSame(array($this->choice2,$this->choice1),$this->list->getChoicesForValues($values));
240+
}
241+
242+
publicfunctiontestGetChoicesForValuesIgnoresNonExistingValues()
243+
{
244+
$values =array($this->value1,$this->value2,'foobar');
245+
$this->assertSame(array($this->choice1,$this->choice2),$this->list->getChoicesForValues($values));
246+
}
247+
248+
// https://github.com/symfony/symfony/issues/3446
249+
publicfunctiontestGetChoicesForValuesEmpty()
250+
{
251+
$this->assertSame(array(),$this->list->getChoicesForValues(array()));
252+
}
253+
254+
publicfunctiontestGetValuesForChoices()
255+
{
256+
$choices =array($this->choice1,$this->choice2);
257+
$this->assertSame(array($this->value1,$this->value2),$this->list->getValuesForChoices($choices));
258+
}
259+
260+
261+
publicfunctiontestGetValuesForChoicesPreservesKeys()
262+
{
263+
$choices =array(5 =>$this->choice1,8 =>$this->choice2);
264+
$this->assertSame(array(5 =>$this->value1,8 =>$this->value2),$this->list->getValuesForChoices($choices));
265+
}
266+
267+
268+
publicfunctiontestGetValuesForChoicesPreservesOrder()
269+
{
270+
$choices =array($this->choice2,$this->choice1);
271+
$this->assertSame(array($this->value2,$this->value1),$this->list->getValuesForChoices($choices));
272+
}
273+
274+
publicfunctiontestGetValuesForChoicesIgnoresNonExistingChoices()
275+
{
276+
$choices =array($this->choice1,$this->choice2,'foobar');
277+
$this->assertSame(array($this->value1,$this->value2),$this->list->getValuesForChoices($choices));
278+
}
279+
280+
publicfunctiontestGetValuesForChoicesEmpty()
281+
{
282+
$this->assertSame(array(),$this->list->getValuesForChoices(array()));
283+
}
284+
285+
/**
286+
* @return \Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface
287+
*/
288+
abstractprotectedfunctioncreateChoiceList();
289+
290+
abstractprotectedfunctiongetChoices();
291+
292+
abstractprotectedfunctiongetLabels();
293+
294+
abstractprotectedfunctiongetValues();
295+
296+
abstractprotectedfunctiongetIndices();
297+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp