ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
All Data Structures Namespaces Files Functions Variables Modules Pages
IsNullConstraintTest.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 2018 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */
4 require_once("libs/composer/vendor/autoload.php");
5 
7 use ILIAS\Data;
9 
11 {
12  public function setUp() : void
13  {
14  $this->df = new Data\Factory();
15  $this->lng = $this->createMock(\ilLanguage::class);
16  $this->f = new Factory($this->df, $this->lng);
17 
18  $this->c = $this->f->null();
19  }
20 
21  public function testAccepts()
22  {
23  $this->assertTrue($this->c->accepts(null));
24  }
25 
26  public function testNotAccepts()
27  {
28  $this->assertFalse($this->c->accepts(2));
29  }
30 
31  public function testCheckSucceed()
32  {
33  $this->c->check(null);
34  $this->assertTrue(true); // does not throw
35  }
36 
37  public function testCheckFails()
38  {
39  $this->expectException(\UnexpectedValueException::class);
40  $this->c->check(2);
41  }
42 
43  public function testNoProblemWith()
44  {
45  $this->assertNull($this->c->problemWith(null));
46  }
47 
48  public function testProblemWith()
49  {
50  $this->lng
51  ->expects($this->once())
52  ->method("txt")
53  ->with("not_a_null")
54  ->willReturn("-%s-");
55 
56  $this->assertEquals("-integer-", $this->c->problemWith(2));
57  }
58 
59  public function testRestrictOk()
60  {
61  $ok = $this->df->ok(null);
62 
63  $res = $this->c->applyTo($ok);
64  $this->assertTrue($res->isOk());
65  }
66 
67  public function testRestrictNotOk()
68  {
69  $not_ok = $this->df->ok(2);
70 
71  $res = $this->c->applyTo($not_ok);
72  $this->assertFalse($res->isOk());
73  }
74 
75  public function testRestrictError()
76  {
77  $error = $this->df->error("error");
78 
79  $res = $this->c->applyTo($error);
80  $this->assertSame($error, $res);
81  }
82 
83  public function testWithProblemBuilder()
84  {
85  $new_c = $this->c->withProblemBuilder(function () {
86  return "This was a fault";
87  });
88  $this->assertEquals("This was a fault", $new_c->problemWith(2));
89  }
90 }
foreach($_POST as $key=> $value) $res
Builds data types.
Definition: Factory.php:19