ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
IsNullConstraintTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
24 
25 class IsNullConstraintTest extends TestCase
26 {
27  private DataFactory $df;
28  private ilLanguage $lng;
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(ilLanguage::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 }
$res
Definition: ltiservices.php:69
ILIAS Refinery Constraint $c