ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LogicalOrTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Data\Factory as DataFactory;
22use ILIAS\Refinery\Factory as Refinery;
24use PHPUnit\Framework\TestCase;
25use PHPUnit\Framework\Attributes\DataProvider;
26
27class LogicalOrTest extends TestCase
28{
29 #[DataProvider('constraintsProvider')]
30 public function testAccept(LogicalOr $constraint, mixed $okValue, mixed $errorValue): void
31 {
32 $this->assertTrue($constraint->accepts($okValue));
33 $this->assertFalse($constraint->accepts($errorValue));
34 }
35
36 #[DataProvider('constraintsProvider')]
37 public function testCheck(LogicalOr $constraint, mixed $okValue, mixed $errorValue): void
38 {
39 $raised = false;
40
41 try {
42 $constraint->check($errorValue);
43 } catch (UnexpectedValueException $e) {
44 $raised = true;
45 }
46
47 $this->assertTrue($raised);
48
49 try {
50 $constraint->check($okValue);
51 $raised = false;
52 } catch (UnexpectedValueException $e) {
53 $raised = true;
54 }
55
56 $this->assertFalse($raised);
57 }
58
59 #[DataProvider('constraintsProvider')]
60 public function testProblemWith(LogicalOr $constraint, mixed $okValue, mixed $errorValue): void
61 {
62 $this->assertNull($constraint->problemWith($okValue));
63 $this->assertIsString($constraint->problemWith($errorValue));
64 }
65
66 #[DataProvider('constraintsProvider')]
67 public function testRestrict(LogicalOr $constraint, mixed $okValue, mixed $errorValue): void
68 {
69 $rf = new DataFactory();
70 $ok = $rf->ok($okValue);
71 $ok2 = $rf->ok($errorValue);
72 $error = $rf->error('text');
73
74 $result = $constraint->applyTo($ok);
75 $this->assertTrue($result->isOk());
76
77 $result = $constraint->applyTo($ok2);
78 $this->assertTrue($result->isError());
79
80 $result = $constraint->applyTo($error);
81 $this->assertSame($error, $result);
82 }
83
84 #[DataProvider('constraintsProvider')]
85 public function testWithProblemBuilder(LogicalOr $constraint, mixed $okValue, mixed $errorValue): void
86 {
87 $new_constraint = $constraint->withProblemBuilder(static function (): string {
88 return "This was a vault";
89 });
90 $this->assertEquals("This was a vault", $new_constraint->problemWith($errorValue));
91 }
92
96 public static function constraintsProvider(): array
97 {
98 $language = new class () implements \ILIAS\Language\Language {
99 public function txt(string $a_topic, string $a_default_lang_fallback_mod = ""): string
100 {
101 return $a_topic;
102 }
103 public function loadLanguageModule(string $a_module): void
104 {
105 }
106 public function getLangKey(): string
107 {
108 return '';
109 }
110 public function toJS($key): void
111 {
112 }
113 };
114 $data_factory = new DataFactory();
115
116 $refinery = new Refinery($data_factory, $language);
117 return [
118 [
119 $refinery->logical()->logicalOr([
120 $refinery->int()->isLessThan(6),
121 $refinery->int()->isGreaterThan(100)
122 ]),
123 '5',
124 8
125 ],
126 [
127 $refinery->logical()->logicalOr([$refinery->int()->isGreaterThan(5), $refinery->int()->isLessThan(2)]),
128 7,
129 3
130 ]
131 ];
132 }
133}
Builds data types.
Definition: Factory.php:36
testAccept(LogicalOr $constraint, mixed $okValue, mixed $errorValue)
testProblemWith(LogicalOr $constraint, mixed $okValue, mixed $errorValue)
testWithProblemBuilder(LogicalOr $constraint, mixed $okValue, mixed $errorValue)
testRestrict(LogicalOr $constraint, mixed $okValue, mixed $errorValue)
testCheck(LogicalOr $constraint, mixed $okValue, mixed $errorValue)
static constraintsProvider()
accepts($value)
Tells if the provided value complies.
applyTo(Result $result)
Restricts a Result.
check($value)
Checks the provided value.
problemWith($value)
Tells what the problem with the provided value is.
withProblemBuilder(callable $builder)
Get a constraint like this one with a builder for a custom error message.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.