ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
ByTryingTransformationTest Class Reference
+ Inheritance diagram for ByTryingTransformationTest:
+ Collaboration diagram for ByTryingTransformationTest:

Public Member Functions

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

Protected Member Functions

 setUp ()
 

Private Attributes

const ERROR = 'error_expected'
 
Refinery $refinery
 

Detailed Description

Definition at line 26 of file ByTryingTransformTest.php.

Member Function Documentation

◆ NullOrNumericDataProvider()

ByTryingTransformationTest::NullOrNumericDataProvider ( )

Definition at line 39 of file ByTryingTransformTest.php.

39 : array
40 {
41 return [
42 'empty string' => ['', null],
43 'empty string - one space' => [' ', null],
44 'empty string - more spaces' => [' ', null],
45 'null' => [null, null],
46 'string' => ['str', self::ERROR],
47 'int' => [1, 1],
48 'negative int' => [-1, -1],
49 'zero' => [0, 0],
50 'array' => [[], self::ERROR],
51 'bool (false)' => [false, self::ERROR],
52 'bool (true)' => [true, self::ERROR]
53 ];
54 }

References ERROR.

◆ NullOrNumericOrStringDataProvider()

ByTryingTransformationTest::NullOrNumericOrStringDataProvider ( )

Definition at line 76 of file ByTryingTransformTest.php.

76 : array
77 {
78 return [
79 'string' => ['str', 'str'],
80 'null' => [null, null],
81 'empty string' => ['', null],
82 'int' => [1, 1],
83 'bool (true)' => [true, self::ERROR],
84 'array' => [[], self::ERROR]
85 ];
86 }

References ERROR.

◆ setUp()

ByTryingTransformationTest::setUp ( )
protected

Definition at line 32 of file ByTryingTransformTest.php.

32 : void
33 {
34 $df = new DataFactory();
35 $lang = $this->getLanguage();
36 $this->refinery = new Refinery($df, $lang);
37 }
$lang
Definition: xapiexit.php:26

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

+ Here is the call graph for this function:

◆ StringOrNullDataProvider()

ByTryingTransformationTest::StringOrNullDataProvider ( )

Definition at line 108 of file ByTryingTransformTest.php.

108 : array
109 {
110 return [
111 'string' => ['str', 'str'],
112 'null' => [null, null],
113 'empty string' => ['', ''],
114 'int' => [1, self::ERROR],
115 'array' => [[], self::ERROR]
116 ];
117 }

References ERROR.

◆ testNullOrNumeric()

ByTryingTransformationTest::testNullOrNumeric (   $value,
  $expected 
)

@dataProvider NullOrNumericDataProvider

Parameters
mixed$value
mixed$expected

Definition at line 61 of file ByTryingTransformTest.php.

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

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testNullOrNumericOrString()

ByTryingTransformationTest::testNullOrNumericOrString (   $value,
  $expected 
)

@dataProvider NullOrNumericOrStringDataProvider

Parameters
mixed$value
mixed$expected

Definition at line 93 of file ByTryingTransformTest.php.

93 : void
94 {
95 $transformation = $this->refinery->byTrying([
96 $this->refinery->kindlyTo()->null(),
97 $this->refinery->numeric()->isNumeric(),
98 $this->refinery->to()->string()
99 ]);
100
101 if ($expected === self::ERROR) {
102 $this->expectException(ConstraintViolationException::class);
103 }
104 $transformed = $transformation->transform($value);
105 $this->assertEquals($expected, $transformed);
106 }

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

◆ testStringOrNull()

ByTryingTransformationTest::testStringOrNull (   $value,
  $expected 
)

@dataProvider StringOrNullDataProvider

Parameters
mixed$value
mixed$expected

Definition at line 124 of file ByTryingTransformTest.php.

124 : void
125 {
126 $transformation = $this->refinery->byTrying([
127 $this->refinery->to()->string(),
128 $this->refinery->kindlyTo()->null()
129 ]);
130
131 if ($expected === self::ERROR) {
132 $this->expectException(ConstraintViolationException::class);
133 }
134 $transformed = $transformation->transform($value);
135 $this->assertEquals($expected, $transformed);
136 }

References ILIAS\Repository\refinery().

+ Here is the call graph for this function:

Field Documentation

◆ $refinery

Refinery ByTryingTransformationTest::$refinery
private

Definition at line 30 of file ByTryingTransformTest.php.

◆ ERROR

const ByTryingTransformationTest::ERROR = 'error_expected'
private

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