3 declare(strict_types=1);
35 private string $str_repr =
'';
39 return $this->str_repr;
45 private string $txt_id =
'';
49 protected function setUp(): void
51 $is_ok =
static function ($value):
bool {
54 $this->txt_id =
"TXT_ID";
55 $error =
function (callable
$txt, $value):
string {
56 return $txt($this->txt_id, $value);
58 $this->
lng = $this->createMock(ilLanguage::class);
64 $new_constraint = $this->constraint->withProblemBuilder(
static function ():
string {
65 return "This was a fault";
67 $this->assertEquals(
"This was a fault", $new_constraint->problemWith(
""));
73 $c = $this->constraint->withProblemBuilder(
function (
$txt) use (&$cls):
string {
78 $this->assertIsCallable($cls);
85 ->expects($this->once())
88 ->willReturn($txt_out);
91 $problem = $this->constraint->problemWith($value);
93 $this->assertEquals(sprintf($txt_out, $value), $problem);
98 $lng_closure = $this->constraint->_getLngClosure();
100 $this->expectException(InvalidArgumentException::class);
107 $lng_closure = $this->constraint->_getLngClosure();
111 ->expects($this->once())
113 ->with($this->txt_id)
114 ->willReturn($txt_out);
116 $res = $lng_closure($this->txt_id);
118 $this->assertEquals($txt_out,
$res);
123 $lng_closure = $this->constraint->_getLngClosure();
126 ->expects($this->once())
129 ->willReturn(
"%s-%s-%s-%s-");
133 $res = $lng_closure(
"id", [],
new stdClass(),
"foo", null);
135 $this->assertEquals(
"array-" . stdClass::class .
"-foo-null-",
$res);
MyValidationConstraintsConstraint $constraint
test_gracefully_handle_arrays_and_objects()
test_exception_on_no_parameter()
getLngClosure()
Get the closure to be passed to the error-function that does i18n and sprintf.
test_no_sprintf_on_one_parameter()
testProblemBuilderRetrievesLngClosure()