1 <?php declare(strict_types=1);
5 require_once(
'./libs/composer/vendor/autoload.php');
21 $df =
new Data\Factory();
23 $this->refine = new \ILIAS\Refinery\Factory($df,
$lang);
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],
35 'negative int' => [-1, -1],
37 'array' => [[], self::ERROR],
38 'bool (false)' => [
false, self::ERROR],
39 'bool (true)' => [
true, self::ERROR]
48 $transformation = $this->refine->byTrying([
49 $this->refine->numeric()->isNumeric(),
50 $this->refine->kindlyTo()->null()
53 if ($expected === self::ERROR) {
54 $this->expectException(ConstraintViolationException::class);
56 $transformed = $transformation->transform($value);
57 $this->assertEquals($expected, $transformed);
64 'string' => [
'str',
'str'],
65 'null' => [null, null],
66 'empty string' => [
'', null],
68 'bool (true)' => [
true, self::ERROR],
69 'array' => [[], self::ERROR]
78 $transformation = $this->refine->byTrying([
79 $this->refine->kindlyTo()->null(),
80 $this->refine->numeric()->isNumeric(),
81 $this->refine->to()->string()
84 if ($expected === self::ERROR) {
85 $this->expectException(ConstraintViolationException::class);
87 $transformed = $transformation->transform($value);
88 $this->assertEquals($expected, $transformed);
94 'string' => [
'str',
'str'],
95 'null' => [null, null],
96 'empty string' => [
'',
''],
97 'int' => [1, self::ERROR],
98 'array' => [[], self::ERROR]
107 $transformation = $this->refine->byTrying([
108 $this->refine->to()->string(),
109 $this->refine->kindlyTo()->null()
112 if ($expected === self::ERROR) {
113 $this->expectException(ConstraintViolationException::class);
115 $transformed = $transformation->transform($value);
116 $this->assertEquals($expected, $transformed);