3 namespace Wikimedia\ParamValidator\TypeDef
;
5 use Wikimedia\ParamValidator\ParamValidator
;
6 use Wikimedia\ParamValidator\ValidationException
;
9 * @covers Wikimedia\ParamValidator\TypeDef\EnumDef
11 class EnumDefTest
extends TypeDefTestCase
{
13 protected static $testClass = EnumDef
::class;
15 public function provideValidate() {
17 ParamValidator
::PARAM_TYPE
=> [ 'a', 'b', 'c', 'd' ],
18 EnumDef
::PARAM_DEPRECATED_VALUES
=> [
19 'b' => [ 'not-to-be' ],
25 'Basic' => [ 'a', 'a', $settings ],
26 'Deprecated' => [ 'c', 'c', $settings, [], [ [ 'deprecated-value', 'flag' => true ] ] ],
27 'Deprecated with message' => [
28 'b', 'b', $settings, [],
29 [ [ 'deprecated-value', 'flag' => [ 'not-to-be' ] ] ],
31 'Bad value, non-multi' => [
32 'x', new ValidationException( 'test', 'x', $settings, 'badvalue', [] ),
35 'Bad value, non-multi but looks like it' => [
36 'x|y', new ValidationException( 'test', 'x|y', $settings, 'notmulti', [] ),
39 'Bad value, multi' => [
40 'x|y', new ValidationException( 'test', 'x|y', $settings, 'badvalue', [] ),
41 $settings +
[ ParamValidator
::PARAM_ISMULTI
=> true ],
42 [ 'values-list' => [ 'x|y' ] ],
47 public function provideGetEnumValues() {
50 [ ParamValidator
::PARAM_TYPE
=> [ 'a', 'b', 'c', 'd' ] ],
51 [ 'a', 'b', 'c', 'd' ],
56 public function provideStringifyValue() {
58 'Basic test' => [ 123, '123' ],
59 'Array' => [ [ 1, 2, 3 ], '1|2|3' ],
60 'Array with pipes' => [ [ 1, 2, '3|4', 5 ], "\x1f1\x1f2\x1f3|4\x1f5" ],