ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
NotConstraintTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\Refinery\Factory as Refinery;
23use ILIAS\Data\Factory as DataFactory;
24use PHPUnit\Framework\TestCase;
25
26class NotConstraintTest extends TestCase
27{
28 private DataFactory $df;
31
32 protected function setUp(): void
33 {
34 $this->df = new DataFactory();
36 $this->createStub(ILIAS\Language\Language::class)
37 );
38 }
39
40 public function testAccepts(): void
41 {
42 $this->assertTrue($this->not_false->accepts(null));
43 }
44
45 public function testNotAccepts(): void
46 {
47 $this->assertFalse($this->not_true->accepts(null));
48 }
49
50 public function testCheckSucceed(): void
51 {
52 $this->not_false->check(null);
53 $this->assertTrue(true); // does not throw
54 }
55
56 public function testCheckFails(): void
57 {
58 $this->expectException(UnexpectedValueException::class);
59 $this->not_true->check(null);
60 }
61
62 public function testNoProblemWith(): void
63 {
64 $this->assertNull($this->not_false->problemWith(null));
65 }
66
67 public function testProblemWith(): void
68 {
69 $lng = $this->createMock(ILIAS\Language\Language::class);
70 $lng
71 ->expects($this->once())
72 ->method('txt')
73 ->with('not_generic')
74 ->willReturn('-%s-');
75
76 [$not_true] = $this->notConstraints($lng);
77
78 $this->assertEquals('-not_true-', $not_true->problemWith(null));
79 }
80
81 public function testRestrictOk(): void
82 {
83 $ok = $this->df->ok(null);
84
85 $res = $this->not_false->applyTo($ok);
86 $this->assertTrue($res->isOk());
87 }
88
89 public function testRestrictNotOk(): void
90 {
91 $not_ok = $this->df->ok(null);
92
93 $res = $this->not_true->applyTo($not_ok);
94 $this->assertFalse($res->isOk());
95 }
96
97 public function testRestrictError(): void
98 {
99 $error = $this->df->error('error');
100
101 $res = $this->not_false->applyTo($error);
102 $this->assertSame($error, $res);
103 }
104
105 public function testWithProblemBuilder(): void
106 {
107 $new_c = $this->not_true->withProblemBuilder(static fn(): string => 'This was a fault');
108 $this->assertEquals('This was a fault', $new_c->problemWith(null));
109 }
110
114 private function notConstraints(ILIAS\Language\Language $lng): array
115 {
116 $refinery = new Refinery($this->df, $lng);
117 $group = $refinery->custom();
118
119 return [
120 $refinery->logical()->not($group->constraint(
121 static fn($v): bool => true,
122 'not_true'
123 )),
124 $refinery->logical()->not($group->constraint(
125 static fn($v): bool => false,
126 'not_false'
127 )),
128 ];
129 }
130}
Builds data types.
Definition: Factory.php:36
notConstraints(ILIAS\Language\Language $lng)
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
problemWith($value)
Tells what the problem with the provided value is.
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $lng
Definition: privfeed.php:26
foreach($_POST as $key=> $value) $res