ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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
93 public static function constraintsProvider(): array
94 {
95 $language = new class () implements \ILIAS\Language\Language {
96 public function txt(string|\ILIAS\Language\LanguageIdentifier $a_topic, ?int $n = null): string
97 {
98 return is_string($a_topic) ? $a_topic : (string) $a_topic->value;
99 }
100 public function loadLanguageModule(string $a_module): void
101 {
102 }
103 public function getLangKey(): string
104 {
105 return '';
106 }
107 public function toJS($key): void
108 {
109 }
110 };
111 $data_factory = new DataFactory();
112
113 $refinery = new Refinery($data_factory, $language);
114 return [
115 [
116 $refinery->logical()->logicalOr([
117 $refinery->int()->isLessThan(6),
118 $refinery->int()->isGreaterThan(100)
119 ]),
120 '5',
121 8
122 ],
123 [
124 $refinery->logical()->logicalOr([$refinery->int()->isGreaterThan(5), $refinery->int()->isLessThan(2)]),
125 7,
126 3
127 ]
128 ];
129 }
130}
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()
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.