ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ByTryingTransformTest Class Reference
+ Inheritance diagram for ByTryingTransformTest:
+ Collaboration diagram for ByTryingTransformTest:

Public Member Functions

 testNullOrNumeric (mixed $value, mixed $expected)
 
 testNullOrNumericOrString (mixed $value, mixed $expected)
 
 testStringOrNull (mixed $value, mixed $expected)
 
- Public Member Functions inherited from ILIAS\Tests\Refinery\TestCase
 getLanguage ()
 

Static Public Member Functions

static NullOrNumericDataProvider ()
 
static NullOrNumericOrStringDataProvider ()
 
static StringOrNullDataProvider ()
 

Protected Member Functions

 setUp ()
 

Private Attributes

const ERROR = 'error_expected'
 
Refinery $refinery
 

Detailed Description

Definition at line 29 of file ByTryingTransformTest.php.

Member Function Documentation

◆ NullOrNumericDataProvider()

static ByTryingTransformTest::NullOrNumericDataProvider ( )
static

Definition at line 42 of file ByTryingTransformTest.php.

References null.

42  : array
43  {
44  return [
45  'empty string' => ['', null],
46  'empty string - one space' => [' ', null],
47  'empty string - more spaces' => [' ', null],
48  'null' => [null, null],
49  'string' => ['str', self::ERROR],
50  'int' => [1, 1],
51  'negative int' => [-1, -1],
52  'zero' => [0, 0],
53  'array' => [[], self::ERROR],
54  'bool (false)' => [false, self::ERROR],
55  'bool (true)' => [true, self::ERROR]
56  ];
57  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ NullOrNumericOrStringDataProvider()

static ByTryingTransformTest::NullOrNumericOrStringDataProvider ( )
static

Definition at line 75 of file ByTryingTransformTest.php.

References null.

75  : array
76  {
77  return [
78  'string' => ['str', 'str'],
79  'null' => [null, null],
80  'empty string' => ['', null],
81  'int' => [1, 1],
82  'bool (true)' => [true, self::ERROR],
83  'array' => [[], self::ERROR]
84  ];
85  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ setUp()

ByTryingTransformTest::setUp ( )
protected

Definition at line 35 of file ByTryingTransformTest.php.

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

35  : void
36  {
37  $df = new DataFactory();
38  $lang = $this->getLanguage();
39  $this->refinery = new Refinery($df, $lang);
40  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$lang
Definition: xapiexit.php:25
+ Here is the call graph for this function:

◆ StringOrNullDataProvider()

static ByTryingTransformTest::StringOrNullDataProvider ( )
static

Definition at line 103 of file ByTryingTransformTest.php.

References null.

103  : array
104  {
105  return [
106  'string' => ['str', 'str'],
107  'null' => [null, null],
108  'empty string' => ['', ''],
109  'int' => [1, self::ERROR],
110  'array' => [[], self::ERROR]
111  ];
112  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null

◆ testNullOrNumeric()

ByTryingTransformTest::testNullOrNumeric ( mixed  $value,
mixed  $expected 
)

Definition at line 60 of file ByTryingTransformTest.php.

References ILIAS\Repository\refinery().

60  : void
61  {
62  $transformation = $this->refinery->byTrying([
63  $this->refinery->numeric()->isNumeric(),
64  $this->refinery->kindlyTo()->null()
65  ]);
66 
67  if ($expected === self::ERROR) {
68  $this->expectException(ConstraintViolationException::class);
69  }
70  $transformed = $transformation->transform($value);
71  $this->assertEquals($expected, $transformed);
72  }
+ Here is the call graph for this function:

◆ testNullOrNumericOrString()

ByTryingTransformTest::testNullOrNumericOrString ( mixed  $value,
mixed  $expected 
)

Definition at line 88 of file ByTryingTransformTest.php.

References ILIAS\Repository\refinery().

88  : void
89  {
90  $transformation = $this->refinery->byTrying([
91  $this->refinery->kindlyTo()->null(),
92  $this->refinery->numeric()->isNumeric(),
93  $this->refinery->to()->string()
94  ]);
95 
96  if ($expected === self::ERROR) {
97  $this->expectException(ConstraintViolationException::class);
98  }
99  $transformed = $transformation->transform($value);
100  $this->assertEquals($expected, $transformed);
101  }
+ Here is the call graph for this function:

◆ testStringOrNull()

ByTryingTransformTest::testStringOrNull ( mixed  $value,
mixed  $expected 
)

Definition at line 115 of file ByTryingTransformTest.php.

References ILIAS\Repository\refinery().

115  : void
116  {
117  $transformation = $this->refinery->byTrying([
118  $this->refinery->to()->string(),
119  $this->refinery->kindlyTo()->null()
120  ]);
121 
122  if ($expected === self::ERROR) {
123  $this->expectException(ConstraintViolationException::class);
124  }
125  $transformed = $transformation->transform($value);
126  $this->assertEquals($expected, $transformed);
127  }
+ Here is the call graph for this function:

Field Documentation

◆ $refinery

Refinery ByTryingTransformTest::$refinery
private

Definition at line 33 of file ByTryingTransformTest.php.

◆ ERROR

const ByTryingTransformTest::ERROR = 'error_expected'
private

Definition at line 31 of file ByTryingTransformTest.php.


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