19declare(strict_types=1);
22use PHPUnit\Framework\TestCase;
31 protected function setUp(): void
33 $is_ok =
static function ($value):
bool {
36 $this->txt_id =
"TXT_ID";
37 $error =
function (callable
$txt, $value):
string {
38 return $txt($this->txt_id, $value);
40 $this->
lng = $this->createMock(
ILIAS\Language\Language::class);
41 $this->constraint =
new class ($is_ok, $error,
new DataFactory(),
$this->lng) extends CustomConstraint {
42 public function _getLngClosure(): Closure
51 $new_constraint = $this->constraint->withProblemBuilder(
static function ():
string {
52 return "This was a fault";
54 $this->assertEquals(
"This was a fault", $new_constraint->problemWith(
""));
60 $c = $this->constraint->withProblemBuilder(
function (
$txt) use (&$cls):
string {
65 $this->assertIsCallable($cls);
72 ->expects($this->once())
75 ->willReturn($txt_out);
78 $problem = $this->constraint->problemWith($value);
80 $this->assertEquals(sprintf($txt_out, $value), $problem);
85 $lng_closure = $this->constraint->_getLngClosure();
87 $this->expectException(ArgumentCountError::class);
94 $lng_closure = $this->constraint->_getLngClosure();
98 ->expects($this->once())
100 ->with($this->txt_id)
101 ->willReturn($txt_out);
103 $res = $lng_closure($this->txt_id);
105 $this->assertEquals($txt_out,
$res);
110 $lng_closure = $this->constraint->_getLngClosure();
113 ->expects($this->once())
116 ->willReturn(
"%s-%s-%s-%s-");
118 $res = $lng_closure(
"id", [],
new stdClass(),
"foo",
null);
120 $this->assertEquals(
"array-" . stdClass::class .
"-foo-null-",
$res);
testProblemBuilderRetrievesLngClosure()
ILIAS Language Language $lng
CustomConstraint $constraint
test_gracefully_handle_arrays_and_objects()
test_exception_on_no_parameter()
test_no_sprintf_on_one_parameter()
getLngClosure()
Get the closure to be passed to the error-function that does i18n and sprintf.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.