ILIAS  release_8 Revision v8.24
LogicalOrTest.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use ILIAS\Data\Factory as DataFactory;
22use ILIAS\Refinery\Factory as Refinery;
24use PHPUnit\Framework\TestCase;
25
26class 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 function constraintsProvider(): array
121 {
122 $mock = $this->getMockBuilder(ilLanguage::class)->disableOriginalConstructor()->getMock();
123 $data_factory = new DataFactory();
124
125 $refinery = new Refinery($data_factory, $mock);
126 return [
127 [
128 $refinery->logical()->logicalOr([
129 $refinery->int()->isLessThan(6),
130 $refinery->int()->isGreaterThan(100)
131 ]),
132 '5',
133 8
134 ],
135 [
136 $refinery->logical()->logicalOr([$refinery->int()->isGreaterThan(5), $refinery->int()->isLessThan(2)]),
137 7,
138 3
139 ]
140 ];
141 }
142}
Builds data types.
Definition: Factory.php:21
testRestrict(LogicalOr $constraint, $okValue, $errorValue)
@dataProvider constraintsProvider
testWithProblemBuilder(LogicalOr $constraint, $okValue, $errorValue)
@dataProvider constraintsProvider
testAccept(LogicalOr $constraint, $okValue, $errorValue)
@dataProvider constraintsProvider
testProblemWith(LogicalOr $constraint, $okValue, $errorValue)
@dataProvider constraintsProvider
testCheck(LogicalOr $constraint, $okValue, $errorValue)
@dataProvider 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.
Refinery Factory $refinery