ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
LessThanConstraintTest.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data\Factory as DataFactory;
27use PHPUnit\Framework\TestCase;
28use UnexpectedValueException;
29
30class LessThanConstraintTest extends TestCase
31{
32 private Constraint $c;
33 private Language $lng;
34 private DataFactory $df;
35 private int $less_than;
36
37 protected function setUp(): void
38 {
39 $this->df = new DataFactory();
40 $this->lng = $this->getMockBuilder(Language::class)
41 ->disableOriginalConstructor()
42 ->getMock();
43
44 $this->less_than = 10;
45
46 $this->c = new LessThan(
47 $this->less_than,
48 $this->df,
49 $this->lng
50 );
51 }
52
53 public function testAccepts(): void
54 {
55 $this->assertTrue($this->c->accepts(2));
56 }
57
58 public function testNotAccepts(): void
59 {
60 $this->assertFalse($this->c->accepts(10));
61 }
62
63 public function testCheckSucceed(): void
64 {
65 $this->c->check(2);
66 $this->assertTrue(true); // does not throw
67 }
68
69 public function testCheckFails(): void
70 {
71 $this->expectException(UnexpectedValueException::class);
72 $this->c->check(11);
73 }
74
75 public function testNoProblemWith(): void
76 {
77 $this->assertNull($this->c->problemWith(1));
78 }
79
80 public function testProblemWith(): void
81 {
82 $this->lng
83 ->expects($this->once())
84 ->method("txt")
85 ->with("not_less_than")
86 ->willReturn("-%s-%s-");
87
88 $this->assertEquals("-12-{$this->less_than}-", $this->c->problemWith("12"));
89 }
90
91 public function testRestrictOk(): void
92 {
93 $ok = $this->df->ok(1);
94
95 $res = $this->c->applyTo($ok);
96 $this->assertTrue($res->isOk());
97 }
98
99 public function testRestrictNotOk(): void
100 {
101 $not_ok = $this->df->ok(1234);
102
103 $res = $this->c->applyTo($not_ok);
104 $this->assertFalse($res->isOk());
105 }
106
107 public function testRestrictError(): void
108 {
109 $error = $this->df->error("error");
110
111 $res = $this->c->applyTo($error);
112 $this->assertSame($error, $res);
113 }
114
115 public function testWithProblemBuilder(): void
116 {
117 $new_c = $this->c->withProblemBuilder(static function (): string {
118 return "This was a fault";
119 });
120 $this->assertEquals("This was a fault", $new_c->problemWith(13));
121 }
122}
Builds data types.
Definition: Factory.php:36
ilErrorHandling $error
Definition: class.ilias.php:69
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
$res
Definition: ltiservices.php:69