ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
LogicalOrTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
25 
26 class LogicalOrTest extends TestCase
27 {
34  public function testAccept(LogicalOr $constraint, $okValue, $errorValue): void
35  {
36  $this->assertTrue($constraint->accepts($okValue));
37  $this->assertFalse($constraint->accepts($errorValue));
38  }
39 
46  public function testCheck(LogicalOr $constraint, $okValue, $errorValue): void
47  {
48  $raised = false;
49 
50  try {
51  $constraint->check($errorValue);
52  } catch (UnexpectedValueException $e) {
53  $raised = true;
54  }
55 
56  $this->assertTrue($raised);
57 
58  try {
59  $constraint->check($okValue);
60  $raised = false;
61  } catch (UnexpectedValueException $e) {
62  $raised = true;
63  }
64 
65  $this->assertFalse($raised);
66  }
67 
74  public function testProblemWith(LogicalOr $constraint, $okValue, $errorValue): void
75  {
76  $this->assertNull($constraint->problemWith($okValue));
77  $this->assertIsString($constraint->problemWith($errorValue));
78  }
79 
86  public function testRestrict(LogicalOr $constraint, $okValue, $errorValue): void
87  {
88  $rf = new DataFactory();
89  $ok = $rf->ok($okValue);
90  $ok2 = $rf->ok($errorValue);
91  $error = $rf->error('text');
92 
93  $result = $constraint->applyTo($ok);
94  $this->assertTrue($result->isOk());
95 
96  $result = $constraint->applyTo($ok2);
97  $this->assertTrue($result->isError());
98 
99  $result = $constraint->applyTo($error);
100  $this->assertSame($error, $result);
101  }
102 
109  public function testWithProblemBuilder(LogicalOr $constraint, $okValue, $errorValue): void
110  {
111  $new_constraint = $constraint->withProblemBuilder(static function (): string {
112  return "This was a vault";
113  });
114  $this->assertEquals("This was a vault", $new_constraint->problemWith($errorValue));
115  }
116 
120  public static function constraintsProvider(): array
121  {
122  $language = new class () implements \ILIAS\Language\Language {
123  public function txt(string $a_topic, string $a_default_lang_fallback_mod = ""): string
124  {
125  return $a_topic;
126  }
127  public function loadLanguageModule(string $a_module): void
128  {
129  }
130  };
131  $data_factory = new DataFactory();
132 
133  $refinery = new Refinery($data_factory, $language);
134  return [
135  [
136  $refinery->logical()->logicalOr([
137  $refinery->int()->isLessThan(6),
138  $refinery->int()->isGreaterThan(100)
139  ]),
140  '5',
141  8
142  ],
143  [
144  $refinery->logical()->logicalOr([$refinery->int()->isGreaterThan(5), $refinery->int()->isLessThan(2)]),
145  7,
146  3
147  ]
148  ];
149  }
150 }
problemWith($value)
Tells what the problem with the provided value is.
testRestrict(LogicalOr $constraint, $okValue, $errorValue)
constraintsProvider
Interface Observer Contains several chained tasks and infos about them.
testAccept(LogicalOr $constraint, $okValue, $errorValue)
constraintsProvider
withProblemBuilder(callable $builder)
Get a constraint like this one with a builder for a custom error message.
testProblemWith(LogicalOr $constraint, $okValue, $errorValue)
constraintsProvider
applyTo(Result $result)
Restricts a Result.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static constraintsProvider()
accepts($value)
Tells if the provided value complies.
testCheck(LogicalOr $constraint, $okValue, $errorValue)
constraintsProvider
check($value)
Checks the provided value.
testWithProblemBuilder(LogicalOr $constraint, $okValue, $errorValue)
constraintsProvider