3 declare(strict_types=1);
30 private \ILIAS\Refinery\Constraint
$c;
32 protected function setUp(): void
35 $this->
lng = $this->createMock(ilLanguage::class);
39 $this->c = $this->f->numeric()->isNumeric();
44 $this->assertTrue($this->c->accepts(0));
49 $this->assertTrue($this->c->accepts(
"1"));
54 $this->assertTrue($this->c->accepts(1));
59 $this->assertTrue($this->c->accepts(0x102));
64 $this->assertTrue($this->c->accepts(0102));
69 $this->assertTrue($this->c->accepts(0b101));
74 $this->assertTrue($this->c->accepts(192e0));
79 $this->assertTrue($this->c->accepts(9.1));
84 $this->assertFalse($this->c->accepts(null));
89 $this->assertFalse($this->c->accepts(
"foo"));
95 $this->assertTrue(
true);
102 ->willReturnCallback(
static function (
string $value):
string {
106 $this->expectException(\UnexpectedValueException::class);
112 $this->assertNull($this->c->problemWith(2));
118 ->expects($this->once())
120 ->with(
"not_numeric")
121 ->willReturn(
"-%s-");
123 $this->assertEquals(
"-aa-", $this->c->problemWith(
"aa"));
128 $ok = $this->df->ok(2);
130 $res = $this->c->applyTo($ok);
131 $this->assertTrue(
$res->isOk());
136 $not_ok = $this->df->ok(
"");
139 ->expects($this->once())
141 ->with(
"not_numeric_empty_string")
142 ->willReturn(
"-%s-");
144 $res = $this->c->applyTo($not_ok);
145 $this->assertFalse(
$res->isOk());
150 $error = $this->df->error(
"error");
152 $res = $this->c->applyTo($error);
153 $this->assertSame($error,
$res);
158 $new_c = $this->c->withProblemBuilder(
static function ():
string {
159 return "This was a fault";
161 $this->assertEquals(
"This was a fault", $new_c->problemWith(
""));
ILIAS Refinery Constraint $c