ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
IsNullConstraintTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Refinery\Factory as Refinery;
22use ILIAS\Data\Factory as DataFactory;
23use PHPUnit\Framework\TestCase;
24
25class IsNullConstraintTest extends TestCase
26{
27 private DataFactory $df;
29 private Refinery $f;
30 private \ILIAS\Refinery\Constraint $c;
31
32 protected function setUp(): void
33 {
34 $this->df = new DataFactory();
35 $this->lng = $this->createMock(ILIAS\Language\Language::class);
36 $this->f = new Refinery($this->df, $this->lng);
37
38 $this->c = $this->f->null();
39 }
40
41 public function testAccepts(): void
42 {
43 $this->assertTrue($this->c->accepts(null));
44 }
45
46 public function testNotAccepts(): void
47 {
48 $this->assertFalse($this->c->accepts(2));
49 }
50
51 public function testCheckSucceed(): void
52 {
53 $this->c->check(null);
54 $this->assertTrue(true); // does not throw
55 }
56
57 public function testCheckFails(): void
58 {
59 $this->expectException(UnexpectedValueException::class);
60 $this->c->check(2);
61 }
62
63 public function testNoProblemWith(): void
64 {
65 $this->assertNull($this->c->problemWith(null));
66 }
67
68 public function testProblemWith(): void
69 {
70 $this->lng
71 ->expects($this->once())
72 ->method("txt")
73 ->with("not_a_null")
74 ->willReturn("-%s-");
75
76 $this->assertEquals("-integer-", $this->c->problemWith(2));
77 }
78
79 public function testRestrictOk(): void
80 {
81 $ok = $this->df->ok(null);
82
83 $res = $this->c->applyTo($ok);
84 $this->assertTrue($res->isOk());
85 }
86
87 public function testRestrictNotOk(): void
88 {
89 $not_ok = $this->df->ok(2);
90
91 $res = $this->c->applyTo($not_ok);
92 $this->assertFalse($res->isOk());
93 }
94
95 public function testRestrictError(): void
96 {
97 $error = $this->df->error("error");
98
99 $res = $this->c->applyTo($error);
100 $this->assertSame($error, $res);
101 }
102
103 public function testWithProblemBuilder(): void
104 {
105 $new_c = $this->c->withProblemBuilder(static function (): string {
106 return "This was a fault";
107 });
108 $this->assertEquals("This was a fault", $new_c->problemWith(2));
109 }
110}
Builds data types.
Definition: Factory.php:36
ILIAS Refinery Constraint $c
ILIAS Language Language $lng
$res
Definition: ltiservices.php:69
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.