ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ByTryingTransformationTest Class Reference

Test ByTrying transformation. More...

+ Inheritance diagram for ByTryingTransformationTest:
+ Collaboration diagram for ByTryingTransformationTest:

Public Member Functions

 setUp ()
 
 NullOrNumericDataProvider ()
 
 testNullOrNumeric ($value, $expected)
 NullOrNumericDataProvider More...
 
 NullOrNumericOrStringDataProvider ()
 
 testNullOrNumericOrString ($value, $expected)
 NullOrNumericOrStringDataProvider More...
 
 StringOrNullDataProvider ()
 
 testStringOrNull ($value, $expected)
 StringOrNullDataProvider More...
 
- Public Member Functions inherited from ILIAS\Tests\Refinery\TestCase
 getLanguage ()
 

Data Fields

const ERROR = 'error_expected'
 

Detailed Description

Test ByTrying transformation.

Definition at line 15 of file ByTryingTransformTest.php.

Member Function Documentation

◆ NullOrNumericDataProvider()

ByTryingTransformationTest::NullOrNumericDataProvider ( )

Definition at line 26 of file ByTryingTransformTest.php.

27  {
28  return [
29  'empty string' => ['', null],
30  'empty string - one space' => [' ', null],
31  'empty string - more spaces' => [' ', null],
32  'null' => [null, null],
33  'string' => ['str', self::ERROR],
34  'int' => [1, 1],
35  'negative int' => [-1, -1],
36  'zero' => [0, 0],
37  'array' => [[], self::ERROR],
38  'bool (false)' => [false, self::ERROR],
39  'bool (true)' => [true, self::ERROR]
40  ];
41  }

◆ NullOrNumericOrStringDataProvider()

ByTryingTransformationTest::NullOrNumericOrStringDataProvider ( )

Definition at line 61 of file ByTryingTransformTest.php.

62  {
63  return [
64  'string' => ['str', 'str'],
65  'null' => [null, null],
66  'empty string' => ['', null],
67  'int' => [1, 1],
68  'bool (true)' => [true, self::ERROR],
69  'array' => [[], self::ERROR]
70  ];
71  }

◆ setUp()

ByTryingTransformationTest::setUp ( )

Definition at line 19 of file ByTryingTransformTest.php.

References $lang, and ILIAS\Tests\Refinery\TestCase\getLanguage().

19  : void
20  {
21  $df = new Data\Factory();
22  $lang = $this->getLanguage();
23  $this->refine = new \ILIAS\Refinery\Factory($df, $lang);
24  }
$lang
Definition: xapiexit.php:8
+ Here is the call graph for this function:

◆ StringOrNullDataProvider()

ByTryingTransformationTest::StringOrNullDataProvider ( )

Definition at line 91 of file ByTryingTransformTest.php.

92  {
93  return [
94  'string' => ['str', 'str'],
95  'null' => [null, null],
96  'empty string' => ['', ''],
97  'int' => [1, self::ERROR],
98  'array' => [[], self::ERROR]
99  ];
100  }

◆ testNullOrNumeric()

ByTryingTransformationTest::testNullOrNumeric (   $value,
  $expected 
)

NullOrNumericDataProvider

Definition at line 46 of file ByTryingTransformTest.php.

47  {
48  $transformation = $this->refine->byTrying([
49  $this->refine->numeric()->isNumeric(),
50  $this->refine->kindlyTo()->null()
51  ]);
52 
53  if ($expected === self::ERROR) {
54  $this->expectException(ConstraintViolationException::class);
55  }
56  $transformed = $transformation->transform($value);
57  $this->assertEquals($expected, $transformed);
58  }

◆ testNullOrNumericOrString()

ByTryingTransformationTest::testNullOrNumericOrString (   $value,
  $expected 
)

NullOrNumericOrStringDataProvider

Definition at line 76 of file ByTryingTransformTest.php.

77  {
78  $transformation = $this->refine->byTrying([
79  $this->refine->kindlyTo()->null(),
80  $this->refine->numeric()->isNumeric(),
81  $this->refine->to()->string()
82  ]);
83 
84  if ($expected === self::ERROR) {
85  $this->expectException(ConstraintViolationException::class);
86  }
87  $transformed = $transformation->transform($value);
88  $this->assertEquals($expected, $transformed);
89  }

◆ testStringOrNull()

ByTryingTransformationTest::testStringOrNull (   $value,
  $expected 
)

StringOrNullDataProvider

Definition at line 105 of file ByTryingTransformTest.php.

106  {
107  $transformation = $this->refine->byTrying([
108  $this->refine->to()->string(),
109  $this->refine->kindlyTo()->null()
110  ]);
111 
112  if ($expected === self::ERROR) {
113  $this->expectException(ConstraintViolationException::class);
114  }
115  $transformed = $transformation->transform($value);
116  $this->assertEquals($expected, $transformed);
117  }

Field Documentation

◆ ERROR

const ByTryingTransformationTest::ERROR = 'error_expected'

Definition at line 17 of file ByTryingTransformTest.php.


The documentation for this class was generated from the following file: