19declare(strict_types=1);
25use PHPUnit\Framework\Attributes\DataProvider;
27require_once(
"./components/ILIAS/Refinery/tests/TestCase.php");
31 private const ERROR =
'error_expected';
35 protected function setUp(): void
37 $df =
new DataFactory();
45 'empty string' => [
'',
null],
46 'empty string - one space' => [
' ',
null],
47 'empty string - more spaces' => [
' ',
null],
48 'null' => [
null,
null],
51 'negative int' => [-1, -1],
59 #[DataProvider('NullOrNumericDataProvider')]
62 $transformation = $this->
refinery->byTrying([
63 $this->
refinery->numeric()->isNumeric(),
64 $this->refinery->kindlyTo()->null()
67 if ($expected === self::ERROR) {
68 $this->expectException(ConstraintViolationException::class);
70 $transformed = $transformation->transform($value);
71 $this->assertEquals($expected, $transformed);
78 'string' => [
'str',
'str'],
79 'null' => [
null,
null],
80 'empty string' => [
'',
null],
87 #[DataProvider('NullOrNumericOrStringDataProvider')]
90 $transformation = $this->
refinery->byTrying([
92 $this->refinery->numeric()->isNumeric(),
93 $this->refinery->to()->string()
96 if ($expected === self::ERROR) {
97 $this->expectException(ConstraintViolationException::class);
99 $transformed = $transformation->transform($value);
100 $this->assertEquals($expected, $transformed);
106 'string' => [
'str',
'str'],
107 'null' => [
null,
null],
108 'empty string' => [
'',
''],
114 #[DataProvider('StringOrNullDataProvider')]
117 $transformation = $this->
refinery->byTrying([
119 $this->refinery->kindlyTo()->null()
122 if ($expected === self::ERROR) {
123 $this->expectException(ConstraintViolationException::class);
125 $transformed = $transformation->transform($value);
126 $this->assertEquals($expected, $transformed);